Class: Keen::Client

Inherits:
Object
  • Object
show all
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 { |authorization, 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" => authorization,
      "Keen-Sdk" => "ruby-#{Keen::VERSION}" }
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/keen/client.rb', line 38

def initialize(*args)
  options = args[0]
  unless options.is_a?(Hash)
    # deprecated, pass a hash of options instead
    options = {
      :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 = options.values_at(
    :project_id, :write_key, :read_key, :master_key)

  self.api_url = options[:api_url] || CONFIG[:api_url]

  self.proxy_url, self.proxy_type = options.values_at(:proxy_url, :proxy_type)

  self.read_timeout = options[:read_timeout].to_f unless options[:read_timeout].nil?

  self.open_timeout = options[:open_timeout].to_f unless options[:open_timeout].nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_method, *args, &block) ⇒ Object (private)



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/keen/client.rb', line 168

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_urlObject

Returns the value of attribute api_url.



20
21
22
# File 'lib/keen/client.rb', line 20

def api_url
  @api_url
end

#master_keyObject

Returns the value of attribute master_key.



20
21
22
# File 'lib/keen/client.rb', line 20

def master_key
  @master_key
end

#open_timeoutObject

Returns the value of attribute open_timeout.



20
21
22
# File 'lib/keen/client.rb', line 20

def open_timeout
  @open_timeout
end

#project_idObject

Returns the value of attribute project_id.



20
21
22
# File 'lib/keen/client.rb', line 20

def project_id
  @project_id
end

#proxy_typeObject

Returns the value of attribute proxy_type.



20
21
22
# File 'lib/keen/client.rb', line 20

def proxy_type
  @proxy_type
end

#proxy_urlObject

Returns the value of attribute proxy_url.



20
21
22
# File 'lib/keen/client.rb', line 20

def proxy_url
  @proxy_url
end

#read_keyObject

Returns the value of attribute read_key.



20
21
22
# File 'lib/keen/client.rb', line 20

def read_key
  @read_key
end

#read_timeoutObject

Returns the value of attribute read_timeout.



20
21
22
# File 'lib/keen/client.rb', line 20

def read_timeout
  @read_timeout
end

#write_keyObject

Returns the value of attribute write_key.



20
21
22
# File 'lib/keen/client.rb', line 20

def write_key
  @write_key
end

Instance Method Details

#saved_queriesObject



61
62
63
# File 'lib/keen/client.rb', line 61

def saved_queries
  @saved_queries ||= SavedQueries.new(self)
end