Class: Algolia::Insights::Client

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/algolia/insights_client.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • insights_config (Insights::Config)

    an Insights::Config object which contains your APP_ID and API_KEY

  • adapter (Hash)

    a customizable set of options

  • logger (Hash)

    a customizable set of options

  • http_requester (Hash)

    a customizable set of options



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

Parameters:

  • app_id (String)

    Algolia application ID

  • api_key (String)

    Algolia API key

Returns:

  • self



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

Parameters:

Returns:

  • self



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.

Parameters:

  • event (Hash)

Returns:

  • (Hash)


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.

Parameters:

  • events (Array)

Returns:

  • (Hash)


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

Parameters:

  • user_token (String)

Returns:



49
50
51
# File 'lib/algolia/insights_client.rb', line 49

def user(user_token)
  UserClient.new(self, user_token)
end