class Algolia::Analytics
Constants
- API_URL
Attributes
headers[R]
ssl[R]
ssl_version[R]
Public Class Methods
new(client, params)
click to toggle source
# File lib/algolia/analytics.rb, line 7 def initialize(client, params) @client = client @headers = params[:headers] end
Public Instance Methods
add_ab_test(ab_test)
click to toggle source
# File lib/algolia/analytics.rb, line 27 def add_ab_test(ab_test) perform_request(:POST, Protocol.ab_tests_uri, {}, ab_test.to_json) end
delete_ab_test(ab_test_id)
click to toggle source
# File lib/algolia/analytics.rb, line 37 def delete_ab_test(ab_test_id) raise ArgumentError.new('ab_test_id cannot be empty') if ab_test_id.nil? || ab_test_id == '' perform_request(:DELETE, Protocol.ab_tests_uri(ab_test_id)) end
get_ab_test(ab_test_id)
click to toggle source
# File lib/algolia/analytics.rb, line 21 def get_ab_test(ab_test_id) raise ArgumentError.new('ab_test_id cannot be empty') if ab_test_id.nil? || ab_test_id == '' perform_request(:GET, Protocol.ab_tests_uri(ab_test_id)) end
get_ab_tests(params = {})
click to toggle source
# File lib/algolia/analytics.rb, line 12 def get_ab_tests(params = {}) params = { :offset => 0, :limit => 10, }.merge(params) perform_request(:GET, Protocol.ab_tests_uri, params) end
stop_ab_test(ab_test_id)
click to toggle source
# File lib/algolia/analytics.rb, line 31 def stop_ab_test(ab_test_id) raise ArgumentError.new('ab_test_id cannot be empty') if ab_test_id.nil? || ab_test_id == '' perform_request(:POST, Protocol.ab_tests_stop_uri(ab_test_id)) end
wait_task(index_name, taskID, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options = {})
click to toggle source
# File lib/algolia/analytics.rb, line 43 def wait_task(index_name, taskID, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options = {}) @client.wait_task(index_name, taskID, time_before_retry, request_options) end
Private Instance Methods
perform_request(method, url, params = {}, data = {})
click to toggle source
# File lib/algolia/analytics.rb, line 49 def perform_request(method, url, params = {}, data = {}) http = HTTPClient.new url = API_URL + url encoded_params = Hash[params.map { |k, v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }] url << "?" + Protocol.to_query(encoded_params) response = case method when :GET http.get(url, { :header => @headers }) when :POST http.post(url, { :body => data, :header => @headers }) when :DELETE http.delete(url, { :header => @headers }) end if response.code / 100 != 2 raise AlgoliaProtocolError.new(response.code, "Cannot #{method} to #{url}: #{response.content}") end JSON.parse(response.content) end