Class: Algolia::Analytics::Client
- Inherits:
-
Object
- Object
- Algolia::Analytics::Client
- Includes:
- Helpers
- Defined in:
- lib/algolia/analytics_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
-
#add_ab_test(ab_test, opts = {}) ⇒ Hash
Creates a new A/B test with provided configuration.
-
#delete_ab_test(ab_test_id, opts = {}) ⇒ Hash
Deletes the A/B Test and removes all associated metadata & metrics.
-
#get_ab_test(ab_test_id, opts = {}) ⇒ Hash
Returns metadata and metrics for A/B test id.
-
#get_ab_tests(opts = {}) ⇒ Hash
Fetch all existing A/B tests for App that are available for the current API Key.
-
#initialize(analytics_config, opts = {}) ⇒ Client
constructor
Initializes the Analytics client.
-
#stop_ab_test(ab_test_id, opts = {}) ⇒ Hash
Marks the A/B test as stopped.
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
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
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
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.
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.
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.
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.
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
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 |