Module: Algolia::Protocol
- Defined in:
- lib/algolia/protocol.rb
Overview
A module which encapsulates the specifics of Algolia’s REST API.
Constant Summary collapse
- VERSION =
The version of the REST API implemented by this module.
1
- HEADER_APP_ID =
The HTTP header used for passing your application ID to the Algolia API.
"X-Algolia-Application-Id"
- HEADER_API_KEY =
The HTTP header used for passing your API key to the Algolia API.
"X-Algolia-API-Key"
- HEADER_FORWARDED_IP =
"X-Forwarded-For"
- HEADER_FORWARDED_API_KEY =
"X-Forwarded-API-Key"
- ERROR_BAD_REQUEST =
HTTP ERROR CODES
400
- ERROR_FORBIDDEN =
403
- ERROR_NOT_FOUND =
404
Class Method Summary collapse
- .batch_uri(index = nil) ⇒ Object
- .browse_uri(index, params = {}) ⇒ Object
- .clear_uri(index) ⇒ Object
- .index_key_uri(index, key) ⇒ Object
- .index_keys_uri(index) ⇒ Object
- .index_operation_uri(index) ⇒ Object
-
.index_uri(index) ⇒ Object
Construct a uri referencing a given Algolia index.
-
.indexes_uri ⇒ Object
Construct a uri to list available indexes.
- .key_uri(key) ⇒ Object
- .keys_uri ⇒ Object
- .logs(offset, length, only_errors = false) ⇒ Object
- .multiple_queries_uri(strategy = "none") ⇒ Object
- .object_uri(index, object_id, params = {}) ⇒ Object
- .objects_uri ⇒ Object
- .partial_object_uri(index, object_id, create_if_not_exits = true) ⇒ Object
- .search_uri(index, query, params = {}) ⇒ Object
- .settings_uri(index) ⇒ Object
- .task_uri(index, task_id) ⇒ Object
- .to_query(params) ⇒ Object
Class Method Details
.batch_uri(index = nil) ⇒ Object
55 56 57 |
# File 'lib/algolia/protocol.rb', line 55 def Protocol.batch_uri(index = nil) "#{index.nil? ? "/#{VERSION}/indexes/*" : index_uri(index)}/batch" end |
.browse_uri(index, params = {}) ⇒ Object
77 78 79 80 |
# File 'lib/algolia/protocol.rb', line 77 def Protocol.browse_uri(index, params = {}) params = params.nil? || params.size == 0 ? "" : "?#{to_query(params)}" "#{index_uri(index)}/browse#{params}" end |
.clear_uri(index) ⇒ Object
91 92 93 |
# File 'lib/algolia/protocol.rb', line 91 def Protocol.clear_uri(index) "#{index_uri(index)}/clear" end |
.index_key_uri(index, key) ⇒ Object
107 108 109 |
# File 'lib/algolia/protocol.rb', line 107 def Protocol.index_key_uri(index, key) "#{index_uri(index)}/keys/#{key}" end |
.index_keys_uri(index) ⇒ Object
111 112 113 |
# File 'lib/algolia/protocol.rb', line 111 def Protocol.index_keys_uri(index) "#{index_uri(index)}/keys" end |
.index_operation_uri(index) ⇒ Object
59 60 61 |
# File 'lib/algolia/protocol.rb', line 59 def Protocol.index_operation_uri(index) "#{index_uri(index)}/operation" end |
.index_uri(index) ⇒ Object
Construct a uri referencing a given Algolia index
51 52 53 |
# File 'lib/algolia/protocol.rb', line 51 def Protocol.index_uri(index) "/#{VERSION}/indexes/#{CGI.escape(index)}" end |
.indexes_uri ⇒ Object
Construct a uri to list available indexes
38 39 40 |
# File 'lib/algolia/protocol.rb', line 38 def Protocol.indexes_uri "/#{VERSION}/indexes" end |
.key_uri(key) ⇒ Object
103 104 105 |
# File 'lib/algolia/protocol.rb', line 103 def Protocol.key_uri(key) "/#{VERSION}/keys/#{key}" end |
.keys_uri ⇒ Object
99 100 101 |
# File 'lib/algolia/protocol.rb', line 99 def Protocol.keys_uri "/#{VERSION}/keys" end |
.logs(offset, length, only_errors = false) ⇒ Object
95 96 97 |
# File 'lib/algolia/protocol.rb', line 95 def Protocol.logs(offset, length, only_errors = false) "/#{VERSION}/logs?offset=#{offset}&length=#{length}&onlyErrors=#{only_errors}" end |
.multiple_queries_uri(strategy = "none") ⇒ Object
42 43 44 |
# File 'lib/algolia/protocol.rb', line 42 def Protocol.multiple_queries_uri(strategy = "none") "/#{VERSION}/indexes/*/queries?strategy=#{strategy}" end |
.object_uri(index, object_id, params = {}) ⇒ Object
67 68 69 70 |
# File 'lib/algolia/protocol.rb', line 67 def Protocol.object_uri(index, object_id, params = {}) params = params.nil? || params.size == 0 ? "" : "?#{to_query(params)}" "#{index_uri(index)}/#{CGI.escape(object_id.to_s)}#{params}" end |
.objects_uri ⇒ Object
46 47 48 |
# File 'lib/algolia/protocol.rb', line 46 def Protocol.objects_uri "/#{VERSION}/indexes/*/objects" end |
.partial_object_uri(index, object_id, create_if_not_exits = true) ⇒ Object
82 83 84 85 |
# File 'lib/algolia/protocol.rb', line 82 def Protocol.partial_object_uri(index, object_id, create_if_not_exits = true) params = create_if_not_exits ? "" : "?createIfNotExists=false" "#{index_uri(index)}/#{CGI.escape(object_id)}/partial#{params}" end |
.search_uri(index, query, params = {}) ⇒ Object
72 73 74 75 |
# File 'lib/algolia/protocol.rb', line 72 def Protocol.search_uri(index, query, params = {}) params = params.nil? || params.size == 0 ? "" : "&#{to_query(params)}" "#{index_uri(index)}?query=#{CGI.escape(query)}&#{params}" end |
.settings_uri(index) ⇒ Object
87 88 89 |
# File 'lib/algolia/protocol.rb', line 87 def Protocol.settings_uri(index) "#{index_uri(index)}/settings" end |
.task_uri(index, task_id) ⇒ Object
63 64 65 |
# File 'lib/algolia/protocol.rb', line 63 def Protocol.task_uri(index, task_id) "#{index_uri(index)}/task/#{task_id}" end |
.to_query(params) ⇒ Object
115 116 117 118 119 |
# File 'lib/algolia/protocol.rb', line 115 def Protocol.to_query(params) params.map do |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" end.join('&') end |