Class: Keen::Client
- Inherits:
-
Object
- Object
- Keen::Client
- Includes:
- MaintenanceMethods, PublishingMethods, QueryingMethods
- Defined in:
- lib/keen/client.rb,
lib/keen/client/querying_methods.rb,
lib/keen/client/publishing_methods.rb,
lib/keen/client/maintenance_methods.rb
Defined Under Namespace
Modules: MaintenanceMethods, PublishingMethods, QueryingMethods
Constant Summary collapse
- CONFIG =
{ :api_url => "https://api.keen.io", :api_version => "3.0", :api_headers => lambda { |, sync_or_async| user_agent = "keen-gem, v#{Keen::VERSION}, #{sync_or_async}" user_agent += ", #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}" if defined?(RUBY_ENGINE) user_agent += ", #{RUBY_ENGINE}" end { "Content-Type" => "application/json", "User-Agent" => user_agent, "Authorization" => , "Keen-Sdk" => "ruby-#{Keen::VERSION}" } } }
Instance Attribute Summary collapse
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#log_queries ⇒ Object
Returns the value of attribute log_queries.
-
#master_key ⇒ Object
Returns the value of attribute master_key.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#proxy_type ⇒ Object
Returns the value of attribute proxy_type.
-
#proxy_url ⇒ Object
Returns the value of attribute proxy_url.
-
#read_key ⇒ Object
Returns the value of attribute read_key.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#write_key ⇒ Object
Returns the value of attribute write_key.
Instance Method Summary collapse
- #access_keys ⇒ Object
- #ensure_master_key! ⇒ Object
- #ensure_project_id! ⇒ Object
- #ensure_read_key! ⇒ Object
- #ensure_write_key! ⇒ Object
-
#initialize(*args) ⇒ Client
constructor
A new instance of Client.
- #process_response(status_code, response_body) ⇒ Object
- #saved_queries ⇒ Object
Methods included from MaintenanceMethods
#delete, #event_collection, #event_collections, #project_info
Methods included from QueryingMethods
#average, #count, #count_unique, #extraction, #funnel, #maximum, #median, #minimum, #multi_analysis, #percentile, #query, #query_url, #select_unique, #sum
Methods included from PublishingMethods
#add_event, #beacon_url, #publish, #publish_async, #publish_batch, #publish_batch_async, #redirect_url
Constructor Details
#initialize(*args) ⇒ Client
Returns a new instance of Client.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/keen/client.rb', line 37 def initialize(*args) = args[0] unless .is_a?(Hash) # deprecated, pass a hash of options instead = { :project_id => args[0], :write_key => args[1], :read_key => args[2], }.merge(args[3] || {}) end self.project_id, self.write_key, self.read_key, self.master_key = .values_at( :project_id, :write_key, :read_key, :master_key) self.api_url = [:api_url] || CONFIG[:api_url] self.proxy_url, self.proxy_type = .values_at(:proxy_url, :proxy_type) self.read_timeout = [:read_timeout].to_f unless [:read_timeout].nil? self.open_timeout = [:open_timeout].to_f unless [:open_timeout].nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(_method, *args, &block) ⇒ Object (private)
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/keen/client.rb', line 171 def method_missing(_method, *args, &block) if config = CONFIG[_method.to_sym] if config.is_a?(Proc) config.call(*args) else config end else super end end |
Instance Attribute Details
#api_url ⇒ Object
Returns the value of attribute api_url.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def api_url @api_url end |
#log_queries ⇒ Object
Returns the value of attribute log_queries.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def log_queries @log_queries end |
#master_key ⇒ Object
Returns the value of attribute master_key.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def master_key @master_key end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def open_timeout @open_timeout end |
#project_id ⇒ Object
Returns the value of attribute project_id.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def project_id @project_id end |
#proxy_type ⇒ Object
Returns the value of attribute proxy_type.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def proxy_type @proxy_type end |
#proxy_url ⇒ Object
Returns the value of attribute proxy_url.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def proxy_url @proxy_url end |
#read_key ⇒ Object
Returns the value of attribute read_key.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def read_key @read_key end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def read_timeout @read_timeout end |
#write_key ⇒ Object
Returns the value of attribute write_key.
19 20 21 |
# File 'lib/keen/client.rb', line 19 def write_key @write_key end |
Instance Method Details
#access_keys ⇒ Object
64 65 66 |
# File 'lib/keen/client.rb', line 64 def access_keys @access_keys ||= AccessKeys.new(self) end |
#ensure_master_key! ⇒ Object
98 99 100 |
# File 'lib/keen/client.rb', line 98 def ensure_master_key! raise ConfigurationError, "Master Key must be set for this operation" unless self.master_key end |
#ensure_project_id! ⇒ Object
90 91 92 |
# File 'lib/keen/client.rb', line 90 def ensure_project_id! raise ConfigurationError, "Project ID must be set" unless self.project_id end |
#ensure_read_key! ⇒ Object
102 103 104 |
# File 'lib/keen/client.rb', line 102 def ensure_read_key! raise ConfigurationError, "Read Key must be set for this operation" unless self.read_key end |
#ensure_write_key! ⇒ Object
94 95 96 |
# File 'lib/keen/client.rb', line 94 def ensure_write_key! raise ConfigurationError, "Write Key must be set for this operation" unless self.write_key end |
#process_response(status_code, response_body) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/keen/client.rb', line 68 def process_response(status_code, response_body) case status_code.to_i when 200..201 begin return MultiJson.decode(response_body) rescue Keen.logger.warn("Invalid JSON for response code #{status_code}: #{response_body}") return {} end when 204 return true when 400 raise BadRequestError.new(response_body) when 401 raise AuthenticationError.new(response_body) when 404 raise NotFoundError.new(response_body) else raise HttpError.new(response_body) end end |
#saved_queries ⇒ Object
60 61 62 |
# File 'lib/keen/client.rb', line 60 def saved_queries @saved_queries ||= SavedQueries.new(self) end |