Class: Masheri::RestClient::Query
- Inherits:
-
Object
- Object
- Masheri::RestClient::Query
- Defined in:
- lib/masheri/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
- #path ⇒ Object
- #query_params ⇒ Object
- #resource ⇒ Object
- #service_id ⇒ Object
- #start_date ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options) ⇒ Query
Returns a new instance of Query.
4 5 6 |
# File 'lib/masheri/rest_client/query.rb', line 4 def initialize() @options = end |
Instance Method Details
#check_dates! ⇒ Object
29 30 31 32 33 |
# File 'lib/masheri/rest_client/query.rb', line 29 def check_dates! if @options[:end_date] - @options[:start_date] > 7.days raise InvalidDateRange.new(@options[:start_date], @options[:end_date]) end end |
#check_params! ⇒ Object
24 25 26 27 |
# File 'lib/masheri/rest_client/query.rb', line 24 def check_params! raise QueryParamMissing.new("end_date") if @options[:end_date].blank? raise QueryParamMissing.new("start_date") if @options[:start_date].blank? end |
#config ⇒ Object
49 50 51 |
# File 'lib/masheri/rest_client/query.rb', line 49 def config Masheri.config end |
#end_date ⇒ Object
20 21 22 |
# File 'lib/masheri/rest_client/query.rb', line 20 def end_date @options[:end_date].strftime("%Y-%m-%dT00:00:00Z") end |
#format ⇒ Object
8 9 10 |
# File 'lib/masheri/rest_client/query.rb', line 8 def format @options[:format] || "csv" end |
#limit ⇒ Object
12 13 14 |
# File 'lib/masheri/rest_client/query.rb', line 12 def limit @options[:limit] || 1000 end |
#params ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/masheri/rest_client/query.rb', line 35 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 |
#path ⇒ Object
65 66 67 |
# File 'lib/masheri/rest_client/query.rb', line 65 def path "/v2/rest/#{config.site_id}/reports/calls/#{resource}/service/#{service_id}" end |
#query_params ⇒ Object
53 54 55 |
# File 'lib/masheri/rest_client/query.rb', line 53 def query_params URI.encode_www_form(params).gsub("%3A", ":") end |
#resource ⇒ Object
61 62 63 |
# File 'lib/masheri/rest_client/query.rb', line 61 def resource @options[:resource] end |
#service_id ⇒ Object
57 58 59 |
# File 'lib/masheri/rest_client/query.rb', line 57 def service_id @options[:service_id] end |
#start_date ⇒ Object
16 17 18 |
# File 'lib/masheri/rest_client/query.rb', line 16 def start_date @options[:start_date].strftime("%Y-%m-%dT00:00:00Z") end |
#url ⇒ Object
69 70 71 |
# File 'lib/masheri/rest_client/query.rb', line 69 def url URI::HTTP.build(host: config.host, path: path, query: query_params).to_s end |