lib/keen/client.rb in keen-0.6.1 vs lib/keen/client.rb in keen-0.7.0

- old
+ new

@@ -11,11 +11,11 @@ module Keen class Client include Keen::Client::PublishingMethods include Keen::Client::QueryingMethods - attr_accessor :project_id, :api_key + attr_accessor :project_id, :write_key, :read_key CONFIG = { :api_host => "api.keen.io", :api_port => 443, :api_version => "3.0", @@ -23,33 +23,35 @@ :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_PEER, :verify_depth => 5, :ca_file => File.expand_path("../../../config/cacert.pem", __FILE__) }, :api_async_http_options => {}, - :api_headers => lambda { |sync_or_async| + :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 } + "User-Agent" => user_agent, + "Authorization" => authorization } } } def initialize(*args) options = args[0] unless options.is_a?(Hash) # deprecated, pass a hash of options instead options = { :project_id => args[0], - :api_key => args[1], - }.merge(args[2] || {}) + :write_key => args[1], + :read_key => args[2], + }.merge(args[3] || {}) end - @project_id, @api_key = options.values_at( - :project_id, :api_key) + @project_id, @write_key, @read_key = options.values_at( + :project_id, :write_key, :read_key) end private def process_response(status_code, response_body) @@ -74,11 +76,15 @@ def ensure_project_id! raise ConfigurationError, "Project ID must be set" unless self.project_id end - def ensure_api_key! - raise ConfigurationError, "API Key must be set for queries" unless self.api_key + def ensure_write_key! + raise ConfigurationError, "Write Key must be set for sending events" unless self.write_key + end + + def ensure_read_key! + raise ConfigurationError, "Read Key must be set for queries" unless self.read_key end def method_missing(_method, *args, &block) if config = CONFIG[_method.to_sym] if config.is_a?(Proc)