Class: Mashery::RestClient::Query
- Inherits:
-
Object
- Object
- Mashery::RestClient::Query
- Defined in:
- lib/mashery/rest_client/query.rb
Instance Method Summary collapse
- #check_dates! ⇒ Object
- #check_params! ⇒ Object
- #config ⇒ Object
- #end_date ⇒ Object
- #format ⇒ Object
-
#initialize(options) ⇒ Query
constructor
A new instance of Query.
- #limit ⇒ Object
- #params ⇒ Object
- #query_params ⇒ Object
- #resource ⇒ Object
- #rest_path ⇒ Object
- #service_id ⇒ Object
- #start_date ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options) ⇒ Query
4 5 6 |
# File 'lib/mashery/rest_client/query.rb', line 4 def initialize() = end |
Instance Method Details
#check_dates! ⇒ Object
38 39 40 41 42 |
# File 'lib/mashery/rest_client/query.rb', line 38 def check_dates! if [:end_date] - [:start_date] > 7.days raise InvalidDateRange.new([:start_date], [:end_date]) end end |
#check_params! ⇒ Object
32 33 34 35 36 |
# File 'lib/mashery/rest_client/query.rb', line 32 def check_params! raise QueryParamMissing.new("resource") if [:resource].blank? raise QueryParamMissing.new("end_date") if [:end_date].blank? raise QueryParamMissing.new("start_date") if [:start_date].blank? end |
#config ⇒ Object
58 59 60 |
# File 'lib/mashery/rest_client/query.rb', line 58 def config Mashery.config end |
#end_date ⇒ Object
28 29 30 |
# File 'lib/mashery/rest_client/query.rb', line 28 def end_date [:end_date].strftime("%Y-%m-%dT00:00:00Z") end |
#format ⇒ Object
16 17 18 |
# File 'lib/mashery/rest_client/query.rb', line 16 def format [:format] || "csv" end |
#limit ⇒ Object
20 21 22 |
# File 'lib/mashery/rest_client/query.rb', line 20 def limit [:limit] || 1000 end |
#params ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mashery/rest_client/query.rb', line 44 def params check_params! check_dates! params = { start_date: start_date, end_date: end_date, format: format, limit: limit, apikey: config.key, sig: config.signature } end |
#query_params ⇒ Object
62 63 64 |
# File 'lib/mashery/rest_client/query.rb', line 62 def query_params URI.encode_www_form(params).gsub("%3A", ":") end |
#resource ⇒ Object
12 13 14 |
# File 'lib/mashery/rest_client/query.rb', line 12 def resource [:resource] end |
#rest_path ⇒ Object
66 67 68 |
# File 'lib/mashery/rest_client/query.rb', line 66 def rest_path "/v2/rest/#{config.site_id}/reports/calls/#{resource}/service/#{service_id}" end |
#service_id ⇒ Object
8 9 10 |
# File 'lib/mashery/rest_client/query.rb', line 8 def service_id [:service_id] end |
#start_date ⇒ Object
24 25 26 |
# File 'lib/mashery/rest_client/query.rb', line 24 def start_date [:start_date].strftime("%Y-%m-%dT00:00:00Z") end |
#url ⇒ Object
70 71 72 73 74 |
# File 'lib/mashery/rest_client/query.rb', line 70 def url uri = URI::HTTP.build(host: config.host, path: rest_path, query: query_params) uri.scheme = "https" uri.to_s end |