Created
March 25, 2015 23:55
-
-
Save kitwalker12/d5f4f896f56a9e2951a3 to your computer and use it in GitHub Desktop.
Algolia Rest API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AlgoliaApi | |
include HTTParty | |
def initialize(type = 'analytics') | |
self.class.base_uri self.class.send("#{type}_base") | |
@auth = { | |
'X-Algolia-API-KEY' => ENV['ALGOLIASEARCH_API_KEY'], | |
'X-Algolia-Application-Id' => ENV['ALGOLIASEARCH_APPLICATION_ID'] | |
} | |
end | |
def self.analytics_base | |
'https://analytics.algolia.com/1' | |
end | |
def self.indexes_base | |
"https://#{ENV['ALGOLIASEARCH_APPLICATION_ID']}.algolia.io/1/indexes" | |
end | |
def self.keys_base | |
"https://#{ENV['ALGOLIASEARCH_APPLICATION_ID']}.algolia.io/1/keys" | |
end | |
def self.logs_base | |
"https://#{ENV['ALGOLIASEARCH_APPLICATION_ID']}.algolia.io/1/logs" | |
end | |
def popular(index, options = { size: 5 }) | |
result = self.class.get("/searches/#{index}/popular", headers: @auth, query: options) | |
if result.success? | |
return result.fetch("topSearches", []).map{ |q| q['query'] } | |
else | |
return [] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment