Class: Algolia::Insights::Client
- Inherits:
-
Object
- Object
- Algolia::Insights::Client
- Includes:
- Helpers
- Defined in:
- lib/algolia/insights_client.rb
Class Method Summary collapse
-
.create(app_id, api_key) ⇒ Object
Create a new client providing only app ID and API key.
-
.create_with_config(config) ⇒ Object
Create a new client providing only an Analytics::Config object.
Instance Method Summary collapse
-
#initialize(insights_config, opts = {}) ⇒ Client
constructor
Initializes the Insights client.
-
#send_event(event, opts = {}) ⇒ Hash
Push an event to the Insights API.
-
#send_events(events, opts = {}) ⇒ Hash
Push an array of events to the Insights API.
-
#user(user_token) ⇒ UserClient
Create a new Insight User Client.
Methods included from Helpers
#check_array, #check_object, #chunk, #deserialize_settings, #get_object_id, #get_option, #handle_params, #hash_includes_subset?, included, #json_to_hash, #path_encode, #symbolize_hash, #to_json, #to_query_string
Constructor Details
#initialize(insights_config, opts = {}) ⇒ Client
Initializes the Insights client
13 14 15 16 17 18 19 |
# File 'lib/algolia/insights_client.rb', line 13 def initialize(insights_config, opts = {}) @config = insights_config adapter = opts[:adapter] || Defaults::ADAPTER logger = opts[:logger] || LoggerHelper.create requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger) @transporter = Transport::Transport.new(@config, requester) end |
Class Method Details
.create(app_id, api_key) ⇒ Object
Create a new client providing only app ID and API key
28 29 30 31 |
# File 'lib/algolia/insights_client.rb', line 28 def self.create(app_id, api_key) config = Insights::Config.new(application_id: app_id, api_key: api_key) create_with_config(config) end |
.create_with_config(config) ⇒ Object
Create a new client providing only an Analytics::Config object
39 40 41 |
# File 'lib/algolia/insights_client.rb', line 39 def self.create_with_config(config) new(config) end |
Instance Method Details
#send_event(event, opts = {}) ⇒ Hash
Push an event to the Insights API.
59 60 61 |
# File 'lib/algolia/insights_client.rb', line 59 def send_event(event, opts = {}) send_events([event], opts) end |
#send_events(events, opts = {}) ⇒ Hash
Push an array of events to the Insights API.
69 70 71 |
# File 'lib/algolia/insights_client.rb', line 69 def send_events(events, opts = {}) @transporter.write(:POST, '/1/events', { events: events }, opts) end |
#user(user_token) ⇒ UserClient
Create a new Insight User Client
49 50 51 |
# File 'lib/algolia/insights_client.rb', line 49 def user(user_token) UserClient.new(self, user_token) end |