Class: ActiveSearch::Algolia::Client
- Inherits:
-
Object
- Object
- ActiveSearch::Algolia::Client
- Includes:
- HTTParty
- Defined in:
- lib/activesearch/algolia/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete(id) ⇒ Object
- #delete_index ⇒ Object
- #get(id) ⇒ Object
- #query(text, extras = {}, options = {}) ⇒ Object
- #save(id, object) ⇒ Object
Class Method Details
.configure(api_key, app_id, index = "activesearch") ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/activesearch/algolia/client.rb', line 9 def self.configure(api_key, app_id, index = "activesearch") base_uri "https://#{app_id}.algolia.io/1/indexes/#{index}" headers({ "X-Algolia-API-Key" => api_key, "X-Algolia-Application-Id" => app_id, "Content-Type" => "application/json; charset=utf-8" }) end |
Instance Method Details
#delete(id) ⇒ Object
22 23 24 25 |
# File 'lib/activesearch/algolia/client.rb', line 22 def delete(id) return false if id.nil? self.class.delete("/#{id}") end |
#delete_index ⇒ Object
18 19 20 |
# File 'lib/activesearch/algolia/client.rb', line 18 def delete_index self.class.delete("") end |
#get(id) ⇒ Object
41 42 43 |
# File 'lib/activesearch/algolia/client.rb', line 41 def get(id) self.class.get("/#{id}") end |
#query(text, extras = {}, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/activesearch/algolia/client.rb', line 31 def query(text, extras = {}, = {}) page, per_page = [:page] || 0, [:per_page] || 20 self.class.get('', query: extras.merge!( query: text, page: page, hitsPerPage: per_page )) end |
#save(id, object) ⇒ Object
27 28 29 |
# File 'lib/activesearch/algolia/client.rb', line 27 def save(id, object) self.class.put("/#{id}", body: object.to_json) end |