Class: What3Words::API
- Inherits:
-
Object
show all
- Defined in:
- lib/what3words/api.rb
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}{4,}+\.\p{L}{4,}+\.\p{L}{4,}+$/u
- BASE_URL =
"https://api.what3words.com/v2/"
- ENDPOINTS =
{
:forward => "forward",
:reverse => "reverse",
:languages => "languages",
:autosuggest => "autosuggest"
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(params) ⇒ API
Returns a new instance of API.
24
25
26
|
# File 'lib/what3words/api.rb', line 24
def initialize(params)
@key = params.fetch(:key)
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
28
29
30
|
# File 'lib/what3words/api.rb', line 28
def key
@key
end
|
Instance Method Details
#autosuggest(addr, lang, focus = {}, clip = {}, params = {}) ⇒ Object
49
50
51
52
53
|
# File 'lib/what3words/api.rb', line 49
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
|
#deep_symbolize_keys(i) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/what3words/api.rb', line 125
def deep_symbolize_keys(i)
if i.kind_of? Hash
ni = {}
i.each {|k,v| ni[k.respond_to?(:to_sym) ? k.to_sym : k] = deep_symbolize_keys(v) }
elsif i.kind_of? Array
ni = i.map(&method(:deep_symbolize_keys))
else
ni = i
end
ni
end
|
#endpoint(name) ⇒ Object
143
144
145
|
# File 'lib/what3words/api.rb', line 143
def endpoint(name)
return base_url() + ENDPOINTS.fetch(name)
end
|
#forward(words, params = {}) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/what3words/api.rb', line 30
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
|
#languages ⇒ Object
43
44
45
46
47
|
# File 'lib/what3words/api.rb', line 43
def languages()
request_params = assemble_common_request_params({})
response = request! :languages, request_params
response
end
|
#reverse(position, params = {}) ⇒ Object
37
38
39
40
41
|
# File 'lib/what3words/api.rb', line 37
def reverse(position, params = {})
request_params = assemble_reverse_request_params(position, params)
response = request! :reverse, request_params
response
end
|