class Algolia::Indices::Client
Public Class Methods
new(api_key, application_id, index_name)
click to toggle source
# File lib/algolia/indices/client.rb, line 7 def initialize(api_key, application_id, index_name) @api_key = api_key @application_id = application_id @index_name = index_name http_client end
Public Instance Methods
batch_write_operations(parameters)
click to toggle source
# File lib/algolia/indices/client.rb, line 14 def batch_write_operations(parameters) http_post(batch_write_operations_path, parameters) end
clear_index()
click to toggle source
# File lib/algolia/indices/client.rb, line 18 def clear_index http_post(clear_index_path) end
Private Instance Methods
algolia_api_base_url()
click to toggle source
# File lib/algolia/indices/client.rb, line 48 def algolia_api_base_url "https://#{@application_id}.algolia.net" end
batch_write_operations_path()
click to toggle source
# File lib/algolia/indices/client.rb, line 52 def batch_write_operations_path "/1/indexes/#{@index_name}/batch" end
clear_index_path()
click to toggle source
# File lib/algolia/indices/client.rb, line 56 def clear_index_path "/1/indexes/#{@index_name}/clear" end
http_client()
click to toggle source
# File lib/algolia/indices/client.rb, line 24 def http_client @http_client ||= ::Faraday.new( url: algolia_api_base_url, headers: request_headers ) do |faraday| faraday.response(:raise_error) faraday.adapter(::Faraday.default_adapter) end end
http_post(path, parameters = {}.to_json)
click to toggle source
# File lib/algolia/indices/client.rb, line 41 def http_post(path, parameters = {}.to_json) http_client.post do |req| req.url path req.body = parameters end end
request_headers()
click to toggle source
# File lib/algolia/indices/client.rb, line 34 def request_headers { 'X-Algolia-API-Key' => @api_key, 'X-Algolia-Application-Id' => @application_id } end