Class: Algolia::Analytics::Client

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/algolia/analytics_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(analytics_config, opts = {}) ⇒ Client

Initializes the Analytics client

Parameters:

  • analytics_config (Analytics::Config)

    a Analytics::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/analytics_client.rb', line 13

def initialize(analytics_config, opts = {})
  @config      = analytics_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/analytics_client.rb', line 28

def self.create(app_id, api_key)
  config = Analytics::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/analytics_client.rb', line 39

def self.create_with_config(config)
  new(config)
end

Instance Method Details

#add_ab_test(ab_test, opts = {}) ⇒ Hash

Creates a new A/B test with provided configuration.

Parameters:

  • ab_test (Hash)
  • opts (Hash) (defaults to: {})

    contains extra parameters to send with your query

Returns:

  • (Hash)


50
51
52
# File 'lib/algolia/analytics_client.rb', line 50

def add_ab_test(ab_test, opts = {})
  @transporter.write(:POST, '/2/abtests', ab_test, opts)
end

#delete_ab_test(ab_test_id, opts = {}) ⇒ Hash

Deletes the A/B Test and removes all associated metadata & metrics.

Parameters:

  • ab_test_id (Integer)

    A/B test ID

  • opts (Hash) (defaults to: {})

    contains extra parameters to send with your query

Returns:

  • (Hash)

Raises:



98
99
100
101
102
# File 'lib/algolia/analytics_client.rb', line 98

def delete_ab_test(ab_test_id, opts = {})
  raise AlgoliaError, 'ab_test_id cannot be empty.' if ab_test_id.nil?

  @transporter.write(:DELETE, path_encode('/2/abtests/%s', ab_test_id), {}, opts)
end

#get_ab_test(ab_test_id, opts = {}) ⇒ Hash

Returns metadata and metrics for A/B test id.

Parameters:

  • ab_test_id (Integer)

    A/B test ID

  • opts (Hash) (defaults to: {})

    contains extra parameters to send with your query

Returns:

  • (Hash)

Raises:



61
62
63
64
65
# File 'lib/algolia/analytics_client.rb', line 61

def get_ab_test(ab_test_id, opts = {})
  raise AlgoliaError, 'ab_test_id cannot be empty.' if ab_test_id.nil?

  @transporter.read(:GET, path_encode('/2/abtests/%s', ab_test_id), {}, opts)
end

#get_ab_tests(opts = {}) ⇒ Hash

Fetch all existing A/B tests for App that are available for the current API Key. Returns an array of metadata and metrics.

Parameters:

  • opts (Hash) (defaults to: {})

    contains extra parameters to send with your query

Returns:

  • (Hash)


74
75
76
# File 'lib/algolia/analytics_client.rb', line 74

def get_ab_tests(opts = {})
  @transporter.read(:GET, '/2/abtests', {}, opts)
end

#stop_ab_test(ab_test_id, opts = {}) ⇒ Hash

Marks the A/B test as stopped. At this point, the test is over and cannot be restarted

Parameters:

  • ab_test_id (Integer)

    A/B test ID

  • opts (Hash) (defaults to: {})

    contains extra parameters to send with your query

Returns:

  • (Hash)

Raises:



85
86
87
88
89
# File 'lib/algolia/analytics_client.rb', line 85

def stop_ab_test(ab_test_id, opts = {})
  raise AlgoliaError, 'ab_test_id cannot be empty.' if ab_test_id.nil?

  @transporter.write(:POST, path_encode('/2/abtests/%s/stop', ab_test_id), {}, opts)
end