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"
ERROR_TIMEOUT =

HTTP ERROR CODES


124
ERROR_UNAVAILABLE =
503

Class Method Summary collapse

Class Method Details

.batch_uri(index) ⇒ Object



42
43
44
# File 'lib/algolia/protocol.rb', line 42

def Protocol.batch_uri(index)
  "/#{VERSION}/indexes/#{index}/batch"
end

.clear_uri(index) ⇒ Object



72
73
74
# File 'lib/algolia/protocol.rb', line 72

def Protocol.clear_uri(index)
  "#{index_uri(index)}/clear"
end

.index_key_uri(index, key) ⇒ Object



88
89
90
# File 'lib/algolia/protocol.rb', line 88

def Protocol.index_key_uri(index, key)
  "#{index_uri(index)}/keys/#{key}"
end

.index_keys_uri(index) ⇒ Object



92
93
94
# File 'lib/algolia/protocol.rb', line 92

def Protocol.index_keys_uri(index)
  "#{index_uri(index)}/keys"
end

.index_operation_uri(index) ⇒ Object



46
47
48
# File 'lib/algolia/protocol.rb', line 46

def Protocol.index_operation_uri(index)
  "/#{VERSION}/indexes/#{index}/operation"
end

.index_uri(index) ⇒ Object

Construct a uri referencing a given Algolia index



38
39
40
# File 'lib/algolia/protocol.rb', line 38

def Protocol.index_uri(index)
  "/#{VERSION}/indexes/#{index}"
end

.indexes_uriObject

Construct a uri to list available indexes



33
34
35
# File 'lib/algolia/protocol.rb', line 33

def Protocol.indexes_uri      
  "/#{VERSION}/indexes"
end

.key_uri(key) ⇒ Object



84
85
86
# File 'lib/algolia/protocol.rb', line 84

def Protocol.key_uri(key)
  "/#{VERSION}/keys/#{key}"
end

.keys_uriObject



80
81
82
# File 'lib/algolia/protocol.rb', line 80

def Protocol.keys_uri
  "/#{VERSION}/keys"
end

.logs(offset, length) ⇒ Object



76
77
78
# File 'lib/algolia/protocol.rb', line 76

def Protocol.logs(offset, length)
  "/#{VERSION}/logs?offset=#{offset}&length=#{length}"
end

.object_uri(index, object_id, params = {}) ⇒ Object



54
55
56
57
# File 'lib/algolia/protocol.rb', line 54

def Protocol.object_uri(index, object_id, params = {})
  params = params.nil? || params.size == 0 ? "" : "?#{to_query(params)}"
  "#{index_uri(index)}/#{object_id}#{params}"
end

.partial_object_uri(index, object_id) ⇒ Object



64
65
66
# File 'lib/algolia/protocol.rb', line 64

def Protocol.partial_object_uri(index, object_id)
  "#{index_uri(index)}/#{object_id}/partial"
end

.search_uri(index, query, params = {}) ⇒ Object



59
60
61
62
# File 'lib/algolia/protocol.rb', line 59

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



68
69
70
# File 'lib/algolia/protocol.rb', line 68

def Protocol.settings_uri(index)
  "#{index_uri(index)}/settings"
end

.task_uri(index, task_id) ⇒ Object



50
51
52
# File 'lib/algolia/protocol.rb', line 50

def Protocol.task_uri(index, task_id)
  "#{index_uri(index)}/task/#{task_id}"
end