Class: What3Words::API
- Inherits:
-
Object
show all
- Defined in:
- lib/what3words/api.rb
Overview
Document the responsibility of the class
Defined Under Namespace
Classes: Error, ResponseError, WordError
Constant Summary
collapse
- REGEX_3_WORD_ADDRESS =
/^\p{L}+\.\p{L}+\.\p{L}+$/u
- REGEX_STRICT =
/^\p{L}{3,}+\.\p{L}{3,}+\.\p{L}{3,}+$/u
- BASE_URL =
'https://api.what3words.com/v2/'.freeze
- ENDPOINTS =
{
forward: 'forward',
reverse: 'reverse',
languages: 'languages',
autosuggest: 'autosuggest',
standardblend: 'standardblend',
autosuggest_ml: 'autosuggest-ml',
standardblend_ml: 'standardblend-ml',
grid: 'grid'
}.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#autosuggest(addr, lang, focus = {}, clip = {}, params = {}) ⇒ Object
-
#autosuggest_ml(addr, lang, focus = {}, clip = {}, params = {}) ⇒ Object
-
#deep_symbolize_keys(i) ⇒ Object
-
#endpoint(name) ⇒ Object
-
#forward(words, params = {}) ⇒ Object
-
#grid(bbox, params = {}) ⇒ Object
-
#initialize(params) ⇒ API
constructor
-
#languages ⇒ Object
-
#reverse(position, params = {}) ⇒ Object
-
#standardblend(addr, lang, focus = {}, params = {}) ⇒ Object
-
#standardblend_ml(addr, lang, focus = {}, params = {}) ⇒ Object
Constructor Details
#initialize(params) ⇒ API
Returns a new instance of API.
29
30
31
|
# File 'lib/what3words/api.rb', line 29
def initialize(params)
@key = params.fetch(:key)
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
33
34
35
|
# File 'lib/what3words/api.rb', line 33
def key
@key
end
|
Instance Method Details
#autosuggest(addr, lang, focus = {}, clip = {}, params = {}) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/what3words/api.rb', line 60
def autosuggest(addr, lang, focus = {}, clip = {}, params = {})
request_params = assemble_autosuggest_request_params(addr, lang, focus,
clip, params)
response = request! :autosuggest, request_params
response
end
|
#autosuggest_ml(addr, lang, focus = {}, clip = {}, params = {}) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/what3words/api.rb', line 67
def autosuggest_ml(addr, lang, focus = {}, clip = {}, params = {})
request_params = assemble_autosuggest_request_params(addr, lang, focus,
clip, params)
response = request! :autosuggest_ml, request_params
response
end
|
#deep_symbolize_keys(i) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/what3words/api.rb', line 170
def deep_symbolize_keys(i)
if i.is_a? Hash
ni = {}
i.each { |k, v| ni[k.respond_to?(:to_sym) ? k.to_sym : k] = deep_symbolize_keys(v) }
elsif i.is_a? Array
ni = i.map(&method(:deep_symbolize_keys))
else
ni = i
end
ni
end
|
#endpoint(name) ⇒ Object
190
191
192
|
# File 'lib/what3words/api.rb', line 190
def endpoint(name)
base_url + ENDPOINTS.fetch(name)
end
|
#forward(words, params = {}) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/what3words/api.rb', line 35
def forward(words, params = {})
words_string = get_words_string words
request_params = assemble_forward_request_params(words_string, params)
response = request! :forward, request_params
response
end
|
#grid(bbox, params = {}) ⇒ Object
48
49
50
51
52
|
# File 'lib/what3words/api.rb', line 48
def grid(bbox, params = {})
request_params = assemble_grid_request_params(bbox, params)
response = request! :grid, request_params
response
end
|
#languages ⇒ Object
54
55
56
57
58
|
# File 'lib/what3words/api.rb', line 54
def languages
request_params = assemble_common_request_params({})
response = request! :languages, request_params
response
end
|
#reverse(position, params = {}) ⇒ Object
42
43
44
45
46
|
# File 'lib/what3words/api.rb', line 42
def reverse(position, params = {})
request_params = assemble_reverse_request_params(position, params)
response = request! :reverse, request_params
response
end
|
#standardblend(addr, lang, focus = {}, params = {}) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/what3words/api.rb', line 74
def standardblend(addr, lang, focus = {}, params = {})
request_params = assemble_standardblend_request_params(addr, lang, focus,
params)
response = request! :standardblend, request_params
response
end
|
#standardblend_ml(addr, lang, focus = {}, params = {}) ⇒ Object
81
82
83
84
85
86
|
# File 'lib/what3words/api.rb', line 81
def standardblend_ml(addr, lang, focus = {}, params = {})
request_params = assemble_standardblend_request_params(addr, lang, focus,
params)
response = request! :standardblend_ml, request_params
response
end
|