Class: CountOnce
- Inherits:
-
Object
- Object
- CountOnce
- Includes:
- Concurrent::Async
- Defined in:
- lib/version.rb,
lib/countonce.rb
Constant Summary collapse
- VERSION =
"0.1.0"
- DEFAULT_DOMAIN =
"countapi.com"
- DEFAULT_SCHEMA =
"https"
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #getCombined(key_name, query_options = {}, iterator = nil) ⇒ Object
- #getIncrements(key_name, query_options = {}, iterator = nil) ⇒ Object
- #getRevenue(key_name, query_options = {}, iterator = nil) ⇒ Object
- #getUniques(key_name, query_options = {}, iterator = nil) ⇒ Object
-
#initialize(credentials = {}) ⇒ CountOnce
constructor
A new instance of CountOnce.
- #ping(ping_options = {}) ⇒ Object
- #query(key_name, query_type, query_options = {}, iterator = nil) ⇒ Object
Constructor Details
#initialize(credentials = {}) ⇒ CountOnce
Returns a new instance of CountOnce.
17 18 19 20 21 22 23 24 25 |
# File 'lib/countonce.rb', line 17 def initialize(credentials = {}) @account_id = credentials[:account_id] @auth_token = credentials[:auth_token] api_protocol = ENV.key?("_API_PROTOCOL") ? ENV["_API_PROTOCOL"] : DEFAULT_SCHEMA api_domain = ENV.key?("_API_DOMAIN") ? ENV["_API_DOMAIN"] : DEFAULT_DOMAIN @url = "#{api_protocol}://#{credentials[:account_id]}.#{api_domain}" end |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
13 14 15 |
# File 'lib/countonce.rb', line 13 def account_id @account_id end |
#auth_token ⇒ Object
Returns the value of attribute auth_token.
14 15 16 |
# File 'lib/countonce.rb', line 14 def auth_token @auth_token end |
#url ⇒ Object
Returns the value of attribute url.
15 16 17 |
# File 'lib/countonce.rb', line 15 def url @url end |
Instance Method Details
#getCombined(key_name, query_options = {}, iterator = nil) ⇒ Object
101 102 103 |
# File 'lib/countonce.rb', line 101 def getCombined(key_name, = {}, iterator = nil) self.query(key_name, 'combined', , iterator) end |
#getIncrements(key_name, query_options = {}, iterator = nil) ⇒ Object
93 94 95 |
# File 'lib/countonce.rb', line 93 def getIncrements(key_name, = {}, iterator = nil) self.query(key_name, 'increments', , iterator) end |
#getRevenue(key_name, query_options = {}, iterator = nil) ⇒ Object
97 98 99 |
# File 'lib/countonce.rb', line 97 def getRevenue(key_name, = {}, iterator = nil) self.query(key_name, 'revenue', , iterator) end |
#getUniques(key_name, query_options = {}, iterator = nil) ⇒ Object
89 90 91 |
# File 'lib/countonce.rb', line 89 def getUniques(key_name, = {}, iterator = nil) self.query(key_name, 'uniques', , iterator) end |
#ping(ping_options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/countonce.rb', line 27 def ping( = {}) url_params = {} url_params["key"] = [:key] || "" url_params["unique_value"] = [:unique_value] || "" headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" headers["Authorization"] = "Bearer #{@auth_token}" if @auth_token if [:attributes] [:attributes].each {|key, value| url_params["attributes[#{key}]"] = value} end url_params["revenue"] = [:revenue] if [:revenue] url_params["timezone"] = [:timezone] if [:timezone] response = HTTParty.post( @url + "/ping", :body => url_params, :headers => headers, :verify => false ) PingResult.new(response.parsed_response) end |
#query(key_name, query_type, query_options = {}, iterator = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/countonce.rb', line 53 def query(key_name, query_type, = {}, iterator = nil) url_params = {} url_params["iterator"] = iterator if iterator headers = {} headers["Authorization"] = "Bearer #{@auth_token}" if @auth_token if [:filter] [:filter].each {|key, value| url_params["filter[#{key}]"] = value} end if [:include] if [:include].is_a? Array [:include] = [:include].join(",") end url_params["include"] = [:include] end url_params["start_date"] = [:start_date] if [:start_date] url_params["end_date"] = [:start_date] if [:end_date] url_params["range"] = [:start_date] if [:range] url_params["prev_start_date"] = [:start_date] if [:prev_start_date] url_params["prev_end_date"] = [:start_date] if [:prev_end_date] url_params["prev_range"] = [:start_date] if [:prev_date] response = HTTParty.get( "#{@url}/#{query_type}/#{key_name}/#{[:metric] || 'daily'}", :query => url_params, :headers => headers, :verify => false ) return QueryResult.new(response.parsed_response) end |