what3words 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +16 -0
- data/LICENSE.txt +1 -1
- data/README.md +61 -42
- data/lib/what3words/api.rb +61 -56
- data/lib/what3words/version.rb +1 -1
- data/spec/config.sample.yaml +0 -2
- data/spec/lib/what3words/what3words_api_spec.rb +106 -0
- data/spec/mock/api_spec.rb +120 -0
- data/spec/spec_helper.rb +7 -7
- data/what3words.gemspec +8 -8
- metadata +29 -31
- data/spec/fixtures/LibertyTech.yaml +0 -30
- data/spec/integration/what3words_api_integration_spec.rb +0 -106
- data/spec/lib/what3words/api_spec.rb +0 -155
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 071822e06272c4806cc6493be469b6bf4e03224f
|
4
|
+
data.tar.gz: 73bd8cb619a5afc0828b1dd2eec47cf29c031f71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fb0661e08c8e627deb26db2653b881dd5214eb5102b613ba7545ca2c45a45d150516c5e2f772182c5c5c85cf06362b7633713ca7402bcf586359d1abef9ae17
|
7
|
+
data.tar.gz: d5b964fdc28f5080ea62e421d4eaec85d4fd5c367cacb6ad1b30f2155ed379cea4a7ef5633fa83048fadf1d76da5169a8c3bad2b48f54e34940a60dad00ce334
|
data/.editorconfig
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
2
|
+
|
3
|
+
# top-most EditorConfig file
|
4
|
+
root = true
|
5
|
+
|
6
|
+
# Unix-style newlines with a newline ending every file
|
7
|
+
[*]
|
8
|
+
end_of_line = lf
|
9
|
+
insert_final_newline = true
|
10
|
+
|
11
|
+
# Set default charset
|
12
|
+
charset = utf-8
|
13
|
+
|
14
|
+
# Indentation
|
15
|
+
indent_style = space
|
16
|
+
indent_size = 2
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# ![what3words](https://map.what3words.com/images/map/marker-border.png)what3words Ruby wrapper
|
2
2
|
|
3
|
-
Use the
|
3
|
+
Use the what3words API in your Ruby app (see http://developer.what3words.com/api)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
+
gem 'what3words', '~> 2.0'
|
9
10
|
|
10
11
|
And then execute:
|
11
12
|
|
@@ -17,9 +18,9 @@ Or install it yourself as:
|
|
17
18
|
|
18
19
|
## Usage
|
19
20
|
|
20
|
-
Sign up for an API key at http://what3words.com
|
21
|
+
Sign up for an API key at http://developer.what3words.com
|
21
22
|
|
22
|
-
See
|
23
|
+
See https://docs.what3words.com/api/v2/ for all parameters that can be
|
23
24
|
passed to the API calls
|
24
25
|
|
25
26
|
If not using Bundler, require it:
|
@@ -28,64 +29,76 @@ If not using Bundler, require it:
|
|
28
29
|
|
29
30
|
Then:
|
30
31
|
|
31
|
-
what3words = What3Words::API.new(:key => "
|
32
|
+
what3words = What3Words::API.new(:key => "YOURAPIKEY")
|
32
33
|
|
33
|
-
|
34
|
+
Forward Geocode : convert a 3 word address into GPS coordinates (WGS-84)
|
34
35
|
|
35
|
-
what3words.
|
36
|
-
# =>
|
36
|
+
what3words.forward "prom.cape.pump"
|
37
|
+
# => {:crs=>{:properties=>{:type=>"ogcwkt", :href=>"http://spatialreference.org/ref/epsg/4326/ogcwkt/"}, :type=>"link"}, :bounds=>{:southwest=>{:lng=>-0.195426, :lat=>51.484449}, :northeast=>{:lng=>-0.195383, :lat=>51.484476}}, :words=>"prom.cape.pump", :map=>"http://w3w.co/prom.cape.pump", :language=>"en", :geometry=>{:lng=>-0.195405, :lat=>51.484463}, :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
|
37
38
|
|
38
|
-
|
39
|
+
## API
|
40
|
+
### Forward Geocoding
|
41
|
+
Convert a 3 word address into GPS coordinates and return 3 words for the same position in a different language
|
39
42
|
|
40
|
-
what3words.
|
41
|
-
# =>
|
43
|
+
what3words.forward "prom.cape.pump", :lang => "fr"
|
44
|
+
# => {:crs=>{:properties=>{:type=>"ogcwkt", :href=>"http://spatialreference.org/ref/epsg/4326/ogcwkt/"}, :type=>"link"}, :bounds=>{:southwest=>{:lng=>-0.195426, :lat=>51.484449}, :northeast=>{:lng=>-0.195383, :lat=>51.484476}}, :words=>"concevoir.époque.amasser", :map=>"http://w3w.co/concevoir.époque.amasser", :language=>"fr", :geometry=>{:lng=>-0.195405, :lat=>51.484463}, :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
|
42
45
|
|
43
|
-
|
46
|
+
Supported keyword params for `forward` call:
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
* `lang` (defaults to language of 3 words) - optional language code (only use this if you want to return 3 words in a different language to the language submitted)
|
49
|
+
* `format` Return data format type; can be one of json (the default), geojson or xml
|
50
|
+
* `display` Return display type; can be one of full (the default) or terse
|
48
51
|
|
49
|
-
|
52
|
+
### Reverse Geocoding
|
53
|
+
Reverse Geocode : Convert position(latitude) information to a 3 word address
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
* `oneword_password` (default nil) - password for OneWord, if private
|
54
|
-
* `corners` (default false) - "true" or "false" to return the coordinates of the w3w square. Will return an array with the southwest coordinates of the square and then the northeast coordinate
|
55
|
-
* `email` (default nil) - user email if required for private OneWord
|
56
|
-
* `password` (default nil) - user password if required for private OneWord
|
55
|
+
what3words.reverse [51.484463, -0.195405]
|
56
|
+
# => {:crs=>{:properties=>{:type=>"ogcwkt", :href=>"http://spatialreference.org/ref/epsg/4326/ogcwkt/"}, :type=>"link"}, :bounds=>{:southwest=>{:lng=>-0.195426, :lat=>51.484449}, :northeast=>{:lng=>-0.195383, :lat=>51.484476}}, :words=>"prom.cape.pump", :map=>"http://w3w.co/prom.cape.pump", :language=>"en", :geometry=>{:lng=>-0.195405, :lat=>51.484463}, :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
|
57
57
|
|
58
|
-
Convert position information to 3
|
58
|
+
Convert position information to a 3 word address in a specific language
|
59
59
|
|
60
|
-
what3words.
|
61
|
-
# =>
|
60
|
+
what3words.reverse [51.484463, -0.195405], :lang => :fr
|
61
|
+
# => {:crs=>{:properties=>{:type=>"ogcwkt", :href=>"http://spatialreference.org/ref/epsg/4326/ogcwkt/"}, :type=>"link"}, :bounds=>{:southwest=>{:lng=>-0.195426, :lat=>51.484449}, :northeast=>{:lng=>-0.195383, :lat=>51.484476}}, :words=>"concevoir.époque.amasser", :map=>"http://w3w.co/concevoir.époque.amasser", :language=>"fr", :geometry=>{:lng=>-0.195405, :lat=>51.484463}, :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
|
62
62
|
|
63
|
-
|
63
|
+
Supported keyword params for `reverse` call:
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
* `lang` (defaults to en) - optional language code
|
66
|
+
* `format` Return data format type; can be one of json (the default), geojson or xml
|
67
|
+
* `display` Return display type; can be one of full (the default) or terse
|
67
68
|
|
68
|
-
|
69
|
+
### Autosuggest
|
70
|
+
Returns a list of 3 word addresses based on user input and other parameters.
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
72
|
+
This resource provides corrections for the following types of input error:
|
73
|
+
- typing errors
|
74
|
+
- spelling errors
|
75
|
+
- misremembered words (e.g. singular vs. plural)
|
76
|
+
- words in the wrong order
|
73
77
|
|
74
|
-
|
78
|
+
The autosuggest resource determines possible corrections to the supplied 3 word address string based on the probability of the input errors listed above and returns a ranked list of suggestions. This resource can also take into consideration the geographic proximity of possible corrections to a given location to further improve the suggestions returned.
|
75
79
|
|
76
|
-
|
77
|
-
|
80
|
+
see https://docs.what3words.com/api/v2/#autosuggest for detailed information
|
81
|
+
|
82
|
+
Gets suggestions in italian for this address
|
83
|
+
|
84
|
+
what3words.autosuggest "trovò.calore.perder", "it"
|
85
|
+
# => {:suggestions=>[{:score=>12, :country=>"ma", :words=>"trovò.calore.perdere", :rank=>1, :geometry=>{:lng=>-6.665638, :lat=>34.318065}, :place=>"Kenitra, Gharb-Chrarda-Beni Hssen"}, {:score=>12, :country=>"ca", :words=>"trovò.calore.perderò", :rank=>2, :geometry=>{:lng=>-65.036149, :lat=>45.846472}, :place=>"Salisbury, New Brunswick"}, {:score=>17, :country=>"ve", :words=>"trovò.calore.prede", :rank=>3, :geometry=>{:lng=>-70.280645, :lat=>7.24527}, :place=>"Guasdualito, Apure"}], :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
|
78
86
|
|
79
|
-
|
87
|
+
Supported keyword params for `reverse` call:
|
88
|
+
* `format` Return data format type; can be one of json (the default), geojson or xml
|
89
|
+
* `display` Return display type; can be one of full (the default) or terse
|
80
90
|
|
81
|
-
|
82
|
-
|
91
|
+
### Get Languages
|
92
|
+
Get list of available 3 word languages
|
93
|
+
|
94
|
+
what3words.languages
|
95
|
+
# => {:languages=>[{:name=>"German", :native_name=>"Deutsch (beta)", :code=>"de"}, {:name=>"Italian", :native_name=>"Italiano (beta)", :code=>"it"}, {:name=>"Turkish", :native_name=>"Türkçe (beta)", :code=>"tr"}, {:name=>"Portuguese", :native_name=>"Português (beta)", :code=>"pt"}, {:name=>"French", :native_name=>"français, langue française (beta)", :code=>"fr"}, {:name=>"Swedish", :native_name=>"svenska (beta)", :code=>"sv"}, {:name=>"English", :native_name=>"English", :code=>"en"}, {:name=>"Russian", :native_name=>"русский язык (beta)", :code=>"ru"}, {:name=>"Spanish; Castilian", :native_name=>"español, castellano (beta)", :code=>"es"}, {:name=>"Swahili", :native_name=>"Kiswahili (beta)", :code=>"sw"}], :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
|
83
96
|
|
84
|
-
See http://what3words.com
|
97
|
+
See http://developer.what3words.com for the original API call documentation
|
85
98
|
|
86
99
|
## Contributing
|
87
100
|
|
88
|
-
1. Fork it ( http://github.com
|
101
|
+
1. Fork it ( http://github.com/what3words/w3w-ruby-wrapper and click "Fork" )
|
89
102
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
90
103
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
91
104
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -93,5 +106,11 @@ See http://what3words.com/api/reference for the original API call documentation
|
|
93
106
|
|
94
107
|
### Testing
|
95
108
|
|
96
|
-
|
97
|
-
|
109
|
+
Prerequisite : we are using [bundler](https://rubygems.org/gems/bundler)
|
110
|
+
`$ gem install bundler`
|
111
|
+
|
112
|
+
1. `$ cd w3w-ruby-wrapper`
|
113
|
+
1. `$ bundle update`
|
114
|
+
1. `$ rake spec`
|
115
|
+
1. Mock Unit specs require no set up. Look in `spec/mock/`
|
116
|
+
1. Integration specs that hit the API directly are in `spec/what3words`, and need the file `spec/config.yaml` to be filled in (using `spec/config.sample.yaml` as a template) with valid details.
|
data/lib/what3words/api.rb
CHANGED
@@ -9,13 +9,16 @@ module What3Words
|
|
9
9
|
class ResponseError < Error; end
|
10
10
|
class WordError < Error; end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
REGEX_3_WORD_ADDRESS = /^\p{L}+\.\p{L}+\.\p{L}+$/u
|
13
|
+
REGEX_STRICT = /^\p{L}{4,}+\.\p{L}{4,}+\.\p{L}{4,}+$/u
|
14
|
+
|
15
|
+
BASE_URL = "https://api.what3words.com/v2/"
|
14
16
|
|
15
17
|
ENDPOINTS = {
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:languages => "
|
18
|
+
:forward => "forward",
|
19
|
+
:reverse => "reverse",
|
20
|
+
:languages => "languages",
|
21
|
+
:autosuggest => "autosuggest"
|
19
22
|
}
|
20
23
|
|
21
24
|
def initialize(params)
|
@@ -24,67 +27,76 @@ module What3Words
|
|
24
27
|
|
25
28
|
attr_reader :key
|
26
29
|
|
27
|
-
def
|
30
|
+
def forward(words, params = {})
|
28
31
|
words_string = get_words_string words
|
29
|
-
request_params =
|
30
|
-
|
31
|
-
response
|
32
|
-
make_response(response, :position, params[:full_response])
|
32
|
+
request_params = assemble_forward_request_params(words_string, params)
|
33
|
+
response = request! :forward, request_params
|
34
|
+
response
|
33
35
|
end
|
34
36
|
|
35
|
-
def
|
36
|
-
request_params =
|
37
|
-
response = request! :
|
38
|
-
|
37
|
+
def reverse(position, params = {})
|
38
|
+
request_params = assemble_reverse_request_params(position, params)
|
39
|
+
response = request! :reverse, request_params
|
40
|
+
response
|
39
41
|
end
|
40
42
|
|
41
|
-
def languages(
|
42
|
-
request_params = assemble_common_request_params(
|
43
|
+
def languages()
|
44
|
+
request_params = assemble_common_request_params({})
|
43
45
|
response = request! :languages, request_params
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
response
|
47
|
+
end
|
48
|
+
|
49
|
+
def autosuggest(addr, lang, focus = {}, clip = {}, params = {})
|
50
|
+
request_params = assemble_autosuggest_request_params(addr, lang, focus, clip, params)
|
51
|
+
response = request! :autosuggest, request_params
|
52
|
+
response
|
49
53
|
end
|
50
54
|
|
51
55
|
def assemble_common_request_params(params)
|
52
56
|
h = {:key => key}
|
53
|
-
h[:lang] = params[:
|
54
|
-
h[:
|
57
|
+
h[:lang] = params[:lang] if params[:lang]
|
58
|
+
h[:format] = params[:format] if params[:format]
|
59
|
+
h[:display] = params[:format] if params[:format]
|
55
60
|
h
|
56
61
|
end
|
57
62
|
private :assemble_common_request_params
|
58
63
|
|
59
|
-
def
|
60
|
-
h = {:
|
61
|
-
h[:"oneword-password"] = params[:oneword_password] if params[:oneword_password]
|
62
|
-
h[:email] = params[:email] if params[:email]
|
63
|
-
h[:password] = params[:password] if params[:password]
|
64
|
+
def assemble_forward_request_params(words_string, params)
|
65
|
+
h = {:addr => words_string}
|
64
66
|
h.merge(assemble_common_request_params(params))
|
65
67
|
end
|
66
|
-
private :
|
68
|
+
private :assemble_forward_request_params
|
67
69
|
|
68
|
-
def
|
69
|
-
h = {:
|
70
|
+
def assemble_reverse_request_params(position, params)
|
71
|
+
h = {:coords => position.join(",")}
|
70
72
|
h.merge(assemble_common_request_params(params))
|
71
73
|
end
|
72
|
-
private :
|
74
|
+
private :assemble_reverse_request_params
|
73
75
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
def assemble_autosuggest_request_params(addr, lang, focus, clip, params)
|
77
|
+
h = {:addr => addr}
|
78
|
+
h[:lang] = lang
|
79
|
+
if focus.respond_to? :join
|
80
|
+
h[:focus] = focus.join(",")
|
79
81
|
end
|
82
|
+
h[:clip] = clip if clip.respond_to? :to_str
|
83
|
+
h.merge(assemble_common_request_params(params))
|
80
84
|
end
|
81
|
-
private :
|
82
|
-
|
83
|
-
def request!(endpoint_name, params
|
84
|
-
|
85
|
+
private :assemble_autosuggest_request_params
|
86
|
+
|
87
|
+
def request!(endpoint_name, params)
|
88
|
+
# puts endpoint_name.inspect
|
89
|
+
# puts params.inspect
|
90
|
+
begin
|
91
|
+
response = RestClient.get endpoint(endpoint_name), params: params
|
92
|
+
rescue => e
|
93
|
+
response = e.response
|
94
|
+
end
|
95
|
+
# puts "#{response.to_str}"
|
96
|
+
# puts "Response status: #{response.code}"
|
85
97
|
response = JSON.parse(response.body)
|
86
|
-
if response["
|
87
|
-
raise ResponseError, "#{response["
|
98
|
+
if response["code"].to_s.strip != ""
|
99
|
+
raise ResponseError, "#{response["code"]}: #{response["message"]}"
|
88
100
|
end
|
89
101
|
deep_symbolize_keys(response)
|
90
102
|
end
|
@@ -103,8 +115,8 @@ module What3Words
|
|
103
115
|
private :get_words_string
|
104
116
|
|
105
117
|
def check_words(words)
|
106
|
-
unless
|
107
|
-
raise WordError, "#{words} is not valid 3
|
118
|
+
unless REGEX_3_WORD_ADDRESS.match(words)
|
119
|
+
raise WordError, "#{words} is not a valid 3 word address"
|
108
120
|
end
|
109
121
|
return words
|
110
122
|
end
|
@@ -123,21 +135,14 @@ module What3Words
|
|
123
135
|
ni
|
124
136
|
end
|
125
137
|
|
126
|
-
def base_url(
|
127
|
-
|
128
|
-
"#{protocol}://api.what3words.com/"
|
138
|
+
def base_url()
|
139
|
+
BASE_URL
|
129
140
|
end
|
130
141
|
private :base_url
|
131
142
|
|
132
|
-
def endpoint(name
|
133
|
-
return base_url(
|
134
|
-
end
|
135
|
-
|
136
|
-
def needs_ssl?(params)
|
137
|
-
(params.has_key?(:email) and params.has_key?(:password)) or
|
138
|
-
params.has_key?(:"oneword-password")
|
143
|
+
def endpoint(name)
|
144
|
+
return base_url() + ENDPOINTS.fetch(name)
|
139
145
|
end
|
140
|
-
private :needs_ssl?
|
141
146
|
|
142
147
|
end
|
143
148
|
end
|
data/lib/what3words/version.rb
CHANGED
data/spec/config.sample.yaml
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
describe What3Words::API, "integration", :integration => true do
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
WebMock.allow_net_connect!
|
10
|
+
end
|
11
|
+
|
12
|
+
let!(:config) do
|
13
|
+
file = "spec/config.yaml"
|
14
|
+
if ! File.exist? file
|
15
|
+
raise "Add a file #{file} (use spec/config.sample.yaml as a template) with correct values to run integration specs"
|
16
|
+
end
|
17
|
+
YAML.load_file file
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:api_key) { config["api_key"] }
|
21
|
+
|
22
|
+
let(:w3w) { described_class.new(:key => api_key) }
|
23
|
+
|
24
|
+
it "returns errors from API" do
|
25
|
+
badw3w = described_class.new(:key => "")
|
26
|
+
expect { badw3w.forward ["prom", "cape", "pump"] }.
|
27
|
+
to raise_error described_class::ResponseError
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "getting position" do
|
31
|
+
|
32
|
+
it "works with string of 3 words separated by '.'" do
|
33
|
+
result = w3w.forward "prom.cape.pump"
|
34
|
+
expect(result).to include(
|
35
|
+
:words => "prom.cape.pump",
|
36
|
+
:language => "en"
|
37
|
+
)
|
38
|
+
expect(result[:geometry]).to include(
|
39
|
+
:lat => "51.484463",
|
40
|
+
:lng => "-0.195405"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "sends lang parameter for 3 words" do
|
45
|
+
result = w3w.forward ["prom", "cape", "pump"], :lang => "fr"
|
46
|
+
expect(result).to include(
|
47
|
+
:words => "concevoir.époque.amasser",
|
48
|
+
:language => "fr"
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "checks 3 words format matches standard regex" do
|
53
|
+
expect { w3w.forward "1.cape.pump" }.
|
54
|
+
to raise_error described_class::WordError
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "gets 3 words" do
|
60
|
+
it "from position" do
|
61
|
+
result = w3w.reverse [29.567041, 106.587875]
|
62
|
+
expect(result).to include(
|
63
|
+
:words => "disclose.strain.redefined",
|
64
|
+
:language => "en"
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "from position in fr" do
|
69
|
+
result = w3w.reverse [29.567041, 106.587875], :lang => "fr"
|
70
|
+
expect(result).to include(
|
71
|
+
:words => "courgette.spécieuse.infrason",
|
72
|
+
:language => "fr"
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
describe "autosuggest" do
|
78
|
+
it "simple addr" do
|
79
|
+
result = w3w.autosuggest "trop.caler.perdre", "fr"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "with focus" do
|
83
|
+
result = w3w.autosuggest "disclose.strain.redefin", "en", [29.567041, 106.587875]
|
84
|
+
end
|
85
|
+
|
86
|
+
it "with clipping radius around focus" do
|
87
|
+
result = w3w.autosuggest "disclose.strain.redefin", "en", [29.567041, 106.587875], "focus(10)"
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
describe "languages" do
|
92
|
+
it "gets all languages" do
|
93
|
+
result = w3w.languages
|
94
|
+
# expect(result[:languages]).to include(
|
95
|
+
# :code => "fr"
|
96
|
+
# )
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "technical" do
|
101
|
+
it "'s deep_symbolize_keys helper works" do
|
102
|
+
expect(w3w.deep_symbolize_keys("foo" => {"bar" => true})).
|
103
|
+
to eq(:foo => {:bar => true})
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe What3Words::API do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
WebMock.disable_net_connect!
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:api_key) { "APIkey" }
|
12
|
+
|
13
|
+
let(:w3w) { described_class.new(:key => api_key) }
|
14
|
+
|
15
|
+
# it "returns errors from API" do
|
16
|
+
# stub_request(:get, "https://api.what3words.com/v2/forward").
|
17
|
+
# to_return(:status => 200, :body => '{"code": "300", "message": "Invalid or non-existent 3 word address"}')
|
18
|
+
#
|
19
|
+
# expect { w3w.forward "a.b.c" }.
|
20
|
+
# to raise_error described_class::ResponseError
|
21
|
+
# end
|
22
|
+
|
23
|
+
describe "getting position" do
|
24
|
+
|
25
|
+
# def stub!(query_params, response_body = {})
|
26
|
+
# stub_request(:get, "https://api.what3words.com/v2/forward").
|
27
|
+
# with(:query => query_params).
|
28
|
+
# to_return(:status => 200, :body => response_body.to_json)
|
29
|
+
# end
|
30
|
+
|
31
|
+
# it "sends 3 words given as string" do
|
32
|
+
# # stub_request(:get, "https://api.what3words.com/v2/forward?addr=a.b.c&key=APIkey").
|
33
|
+
# # with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
|
34
|
+
# # to_return(:status => 200, :body => '{"words" :"a.b.c"}', :headers => {})
|
35
|
+
# stub_request(:get, "https://api.what3words.com/v2/forward" ).
|
36
|
+
# # with(query: hash_including({"addr" => "a.b.c"}, {"key" => :api_key})).
|
37
|
+
# with(query: hash_including(:add => "abc", :key => :api_key)).
|
38
|
+
# to_return(:status => 200, :body => '{"words" :"a.b.c"}')
|
39
|
+
# # stub! hash_including(:addr => "a.b.c")
|
40
|
+
# result = w3w.forward "a.b.c"
|
41
|
+
# puts result
|
42
|
+
# end
|
43
|
+
|
44
|
+
# it "extracts position from response" do
|
45
|
+
# stub!(hash_including(:addr => "prom.cape.pump"), {"position" => [1, 2]})
|
46
|
+
# result = w3w.forward "prom.cape.pump"
|
47
|
+
# expect(result).to eq [1, 2]
|
48
|
+
# end
|
49
|
+
|
50
|
+
# it "returns full response instead of just coords" do
|
51
|
+
# stub!(hash_including(:addr => "prom.cape.pump"),
|
52
|
+
# {"thanks" => "Thanks from all of us at index.home.raft for using a what3words API"})
|
53
|
+
# result = w3w.forward "prom.cape.pump", :full_response => true
|
54
|
+
# expect(result).to eq :thanks => "Thanks from all of us at index.home.raft for using a what3words API"
|
55
|
+
# end
|
56
|
+
|
57
|
+
# it "sends lang option" do
|
58
|
+
# stub!(hash_including(:addr => "prom.cape.pump", :lang => "fr"))
|
59
|
+
# w3w.forward "prom.cape.pump", :language => "fr"
|
60
|
+
# end
|
61
|
+
|
62
|
+
# it "parses response errors" do
|
63
|
+
# stub! hash_including(:addr => "prom.cape.pump"), {:error => "xx", :message => "msg"}
|
64
|
+
# expect { w3w.forward "prom.cape.pump" }.
|
65
|
+
# to raise_error described_class::ResponseError, "xx: msg"
|
66
|
+
# end
|
67
|
+
|
68
|
+
# it "checks 3 words as string matches standard regex" do
|
69
|
+
# stub! anything
|
70
|
+
# expect { w3w.words_to_position "1.cape.pump" }.
|
71
|
+
# to raise_error described_class::WordError
|
72
|
+
# end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
# describe "gets 3 words" do
|
77
|
+
#
|
78
|
+
# def stub!(request_body, response_body = {})
|
79
|
+
# stub_request(:get, "https://api.what3words.com/v2/reverse").
|
80
|
+
# with(:body => request_body).
|
81
|
+
# to_return(:status => 200, :body => response_body.to_json)
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# it "extracts 3 words from response" do
|
85
|
+
# stub! hash_including(:position => "1,2"), {:words => "prom.cape.pump"}
|
86
|
+
# expect(w3w.reverse([1, 2])).to eq "prom.cape.pump"
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# it "sends lang option" do
|
90
|
+
# stub!(hash_including(:position => "1,2", :lang => "fr"))
|
91
|
+
# w3w.position_to_words([1, 2], :language => "fr")
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# describe "getting available languages" do
|
97
|
+
#
|
98
|
+
# def stub!(request_body, response_body = {})
|
99
|
+
# stub_request(:get, "http://api.what3words.com/get-languages").
|
100
|
+
# with(:body => request_body).
|
101
|
+
# to_return(:status => 200, :body => response_body.to_json)
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# it "gets list of codes" do
|
105
|
+
# stub! anything, {:languages => [{:code => "l1"}, {:code => "l2"}]}
|
106
|
+
# expect(w3w.languages). to eq ["l1", "l2"]
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# it "gets full response" do
|
110
|
+
# stub! anything, {:languages => [{:code => "l1"}, {:code => "l2"}]}
|
111
|
+
# expect(w3w.languages :full_response => true).
|
112
|
+
# to eq(:languages => [{:code => "l1"}, {:code => "l2"}])
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
|
116
|
+
it "'s deep_symbolize_keys helper works" do
|
117
|
+
expect(w3w.deep_symbolize_keys("foo" => {"bar" => 1, "baz" => [{"quux" => "www"}]})).
|
118
|
+
to eq(:foo => {:bar => 1, :baz => [{:quux => "www"}]})
|
119
|
+
end
|
120
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,10 +6,10 @@ require "webmock/rspec"
|
|
6
6
|
|
7
7
|
require "what3words"
|
8
8
|
|
9
|
-
RSpec.configure do |config|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
9
|
+
# RSpec.configure do |config|
|
10
|
+
# # config.filter_run_excluding :integration => true
|
11
|
+
#
|
12
|
+
# config.before(:all) do
|
13
|
+
# WebMock.disable_net_connect!
|
14
|
+
# end
|
15
|
+
# end
|
data/what3words.gemspec
CHANGED
@@ -7,9 +7,9 @@ require "what3words/version"
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = "what3words"
|
9
9
|
spec.version = What3Words::VERSION
|
10
|
-
spec.authors = ["
|
11
|
-
spec.email = ["
|
12
|
-
spec.summary = "
|
10
|
+
spec.authors = ["what3words"]
|
11
|
+
spec.email = ["development@what3words.com"]
|
12
|
+
spec.summary = "what3words API wrapper in Ruby"
|
13
13
|
spec.homepage = "http://rubygems.org/gems/what3words"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^spec/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "rest-client"
|
21
|
+
spec.add_dependency "rest-client", "~> 1.8"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.
|
24
|
-
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "webmock"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 11.1"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
26
|
+
spec.add_development_dependency "webmock", "~> 2.0"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,92 +1,93 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what3words
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- what3words
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.12'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.12'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '11.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '11.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3.4'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '2.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '2.0'
|
83
83
|
description:
|
84
84
|
email:
|
85
|
-
-
|
85
|
+
- development@what3words.com
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".editorconfig"
|
90
91
|
- ".gitignore"
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE.txt
|
@@ -96,9 +97,8 @@ files:
|
|
96
97
|
- lib/what3words/api.rb
|
97
98
|
- lib/what3words/version.rb
|
98
99
|
- spec/config.sample.yaml
|
99
|
-
- spec/
|
100
|
-
- spec/
|
101
|
-
- spec/lib/what3words/api_spec.rb
|
100
|
+
- spec/lib/what3words/what3words_api_spec.rb
|
101
|
+
- spec/mock/api_spec.rb
|
102
102
|
- spec/spec_helper.rb
|
103
103
|
- what3words.gemspec
|
104
104
|
homepage: http://rubygems.org/gems/what3words
|
@@ -121,14 +121,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.5.1
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
|
-
summary:
|
127
|
+
summary: what3words API wrapper in Ruby
|
128
128
|
test_files:
|
129
129
|
- spec/config.sample.yaml
|
130
|
-
- spec/
|
131
|
-
- spec/
|
132
|
-
- spec/lib/what3words/api_spec.rb
|
130
|
+
- spec/lib/what3words/what3words_api_spec.rb
|
131
|
+
- spec/mock/api_spec.rb
|
133
132
|
- spec/spec_helper.rb
|
134
|
-
has_rdoc:
|
@@ -1,30 +0,0 @@
|
|
1
|
-
---
|
2
|
-
:type: OneWord
|
3
|
-
:oneword: "*LibertyTech"
|
4
|
-
:position:
|
5
|
-
- 51.512573
|
6
|
-
- -0.144879
|
7
|
-
:info:
|
8
|
-
:name: Liberty Tech office
|
9
|
-
:address1: 124 New Bond Street
|
10
|
-
:address2: ''
|
11
|
-
:address3: ''
|
12
|
-
:city: London
|
13
|
-
:county: ''
|
14
|
-
:postcode: W1S 1DX
|
15
|
-
:country_id: '0'
|
16
|
-
:website: http://libertytech.com
|
17
|
-
:email: enquiries@libertytech.com
|
18
|
-
:telephone: 0207 493 8140
|
19
|
-
:delivery_notes: Ring bell number 7, we're on the top floor.
|
20
|
-
:notes: Top floor, lots of stairs!
|
21
|
-
:social_facebook: http://www.facebook.com/libertytech
|
22
|
-
:social_twitter: http://www.twitter.com/libertytech
|
23
|
-
:social_google: ''
|
24
|
-
:social_linkedin: ''
|
25
|
-
:social_instagram: ''
|
26
|
-
:words:
|
27
|
-
- boxer
|
28
|
-
- overnight
|
29
|
-
- crate
|
30
|
-
:language: en
|
@@ -1,106 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
require "yaml"
|
5
|
-
|
6
|
-
describe What3Words::API, "integration", :integration => true do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
WebMock.allow_net_connect!
|
10
|
-
end
|
11
|
-
|
12
|
-
let!(:config) do
|
13
|
-
file = "spec/config.yaml"
|
14
|
-
if ! File.exist? file
|
15
|
-
raise "Add a file #{file} (use spec/config.sample.yaml as a template) with correct values to run integration specs"
|
16
|
-
end
|
17
|
-
YAML.load_file file
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:api_key) { config["api_key"] }
|
21
|
-
let(:private_one_word) { config["private_one_word"] }
|
22
|
-
let(:private_one_word_password) { config["private_one_word_password"] }
|
23
|
-
|
24
|
-
let(:w3w) { described_class.new(:key => api_key) }
|
25
|
-
|
26
|
-
it "returns errors from API" do
|
27
|
-
badw3w = described_class.new(:key => "")
|
28
|
-
expect { badw3w.words_to_position ["prom", "cape", "pump"] }.
|
29
|
-
to raise_error described_class::ResponseError
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "getting position" do
|
33
|
-
|
34
|
-
it "works with 3 words in array" do
|
35
|
-
result = w3w.words_to_position ["prom", "cape", "pump"]
|
36
|
-
expect(result).to eq [51.484463, -0.195405]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "works with string of 3 words separated by '.'" do
|
40
|
-
result = w3w.words_to_position "prom.cape.pump"
|
41
|
-
expect(result).to eq [51.484463, -0.195405]
|
42
|
-
end
|
43
|
-
|
44
|
-
it "gets full response from API" do
|
45
|
-
result = w3w.words_to_position ["prom", "cape", "pump"], :full_response => true
|
46
|
-
expect(result).to eq( :type => "3 words", :words => ["prom", "cape", "pump"],
|
47
|
-
:position => [51.484463, -0.195405], :language => "en" )
|
48
|
-
end
|
49
|
-
|
50
|
-
it "sends all possible parameters for 3 words" do
|
51
|
-
result = w3w.words_to_position ["prom", "cape", "pump"], :full_response => true,
|
52
|
-
:language => "fr", :corners => true
|
53
|
-
expect(result).to eq(
|
54
|
-
:type => "3 words", :words => ["concevoir", "époque", "amasser"],
|
55
|
-
:position => [51.484463, -0.195405], :language => "fr",
|
56
|
-
:corners => [[51.484449, -0.195426], [51.484476, -0.195383]])
|
57
|
-
end
|
58
|
-
|
59
|
-
it "checks 3 words format matches standard regex" do
|
60
|
-
expect { w3w.words_to_position ["1", "cape", "pump"] }.
|
61
|
-
to raise_error described_class::WordError
|
62
|
-
|
63
|
-
expect { w3w.words_to_position "1.cape.pump" }.
|
64
|
-
to raise_error described_class::WordError
|
65
|
-
end
|
66
|
-
|
67
|
-
it "checks OneWord format matches standard regex" do
|
68
|
-
expect { w3w.words_to_position "123foo" }.
|
69
|
-
to raise_error described_class::WordError
|
70
|
-
end
|
71
|
-
|
72
|
-
it "works with a OneWord" do
|
73
|
-
result = w3w.words_to_position "*LibertyTech"
|
74
|
-
expect(result).to eq [51.512573, -0.144879]
|
75
|
-
end
|
76
|
-
|
77
|
-
it "disallows access to protected OneWord" do
|
78
|
-
expect { w3w.words_to_position private_one_word }.
|
79
|
-
to raise_error described_class::ResponseError
|
80
|
-
end
|
81
|
-
|
82
|
-
it "accesses OneWord protected by oneword password" do
|
83
|
-
expect(w3w.words_to_position private_one_word,
|
84
|
-
:oneword_password => private_one_word_password).
|
85
|
-
to eq [29.567043, 106.587865]
|
86
|
-
end
|
87
|
-
|
88
|
-
xit "accesses OneWord protected by user credentials (username & password)"
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "gets 3 words" do
|
92
|
-
it "from position" do
|
93
|
-
expect(w3w.position_to_words [29.567041, 106.587875], :language => "fr").
|
94
|
-
to eq ["courgette", "approbateur", "infrason"]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
it "gets languages" do
|
99
|
-
expect(w3w.languages).to include "en"
|
100
|
-
end
|
101
|
-
|
102
|
-
it "'s deep_symbolize_keys helper works" do
|
103
|
-
expect(w3w.deep_symbolize_keys("foo" => {"bar" => true})).
|
104
|
-
to eq(:foo => {:bar => true})
|
105
|
-
end
|
106
|
-
end
|
@@ -1,155 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe What3Words::API do
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
WebMock.disable_net_connect!
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:api_key) { "APIkey" }
|
12
|
-
|
13
|
-
let(:w3w) { described_class.new(:key => api_key) }
|
14
|
-
|
15
|
-
it "returns errors from API" do
|
16
|
-
stub_request(:post, "http://api.what3words.com/w3w").
|
17
|
-
to_return(:status => 200, :body => '{"error": "XX", "message": "msg"}')
|
18
|
-
|
19
|
-
expect { w3w.words_to_position ["prom", "cape", "pump"] }.
|
20
|
-
to raise_error described_class::ResponseError
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "getting position" do
|
24
|
-
|
25
|
-
def stub!(request_body, response_body = {}, protocol = "http")
|
26
|
-
r = stub_request(:post, "#{protocol}://api.what3words.com/w3w").
|
27
|
-
with(:body => request_body).
|
28
|
-
to_return(:status => 200, :body => response_body.to_json)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "sends 3 words given as array" do
|
32
|
-
stub! hash_including(:string => "a.b.c")
|
33
|
-
result = w3w.words_to_position ["a", "b", "c"]
|
34
|
-
end
|
35
|
-
|
36
|
-
it "sends 3 words given as string" do
|
37
|
-
stub! hash_including(:string => "a.b.c")
|
38
|
-
result = w3w.words_to_position "a.b.c"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "extracts position from response" do
|
42
|
-
stub! hash_including(:string => "a.b.c"), {"position" => [1, 2]}
|
43
|
-
result = w3w.words_to_position "a.b.c"
|
44
|
-
expect(result).to eq [1, 2]
|
45
|
-
end
|
46
|
-
|
47
|
-
it "returns full response instead of just coords" do
|
48
|
-
stub!(hash_including(:string => "a.b.c"),
|
49
|
-
{"full" => true})
|
50
|
-
result = w3w.words_to_position "a.b.c", :full_response => true
|
51
|
-
expect(result).to eq :full => true
|
52
|
-
end
|
53
|
-
|
54
|
-
it "sends lang option" do
|
55
|
-
stub!(hash_including(:string => "a.b.c", :lang => "fr"))
|
56
|
-
w3w.words_to_position "a.b.c", :language => "fr"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "sends corners option" do
|
60
|
-
stub!(hash_including(:string => "a.b.c", :corners => "true"))
|
61
|
-
w3w.words_to_position "a.b.c", :corners => true
|
62
|
-
end
|
63
|
-
|
64
|
-
it "uses https for private OneWord with oneword-password" do
|
65
|
-
stub!(hash_including(:string => "a.b.c", :"oneword-password" => "oopw"),
|
66
|
-
{}, "https")
|
67
|
-
w3w.words_to_position "a.b.c", :oneword_password => "oopw"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "uses https for private OneWord with email / password" do
|
71
|
-
stub!(hash_including(:string => "a.b.c", :email => "em", :password => "pw"),
|
72
|
-
{}, "https")
|
73
|
-
w3w.words_to_position "a.b.c", :email => "em", :password => "pw"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "parses response errors" do
|
77
|
-
stub! hash_including(:string => "a.b.c"), {:error => "xx", :message => "msg"}
|
78
|
-
expect { w3w.words_to_position "a.b.c" }.
|
79
|
-
to raise_error described_class::ResponseError, "xx: msg"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "checks 3 words as array matches standard regex" do
|
83
|
-
stub! anything
|
84
|
-
expect { w3w.words_to_position ["1", "cape", "pump"] }.
|
85
|
-
to raise_error described_class::WordError
|
86
|
-
end
|
87
|
-
|
88
|
-
it "checks 3 words as string matches standard regex" do
|
89
|
-
stub! anything
|
90
|
-
expect { w3w.words_to_position "1.cape.pump" }.
|
91
|
-
to raise_error described_class::WordError
|
92
|
-
end
|
93
|
-
|
94
|
-
it "checks OneWord format matches standard regex" do
|
95
|
-
stub! anything
|
96
|
-
expect { w3w.words_to_position "123foo" }.
|
97
|
-
to raise_error described_class::WordError
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "gets 3 words" do
|
102
|
-
|
103
|
-
def stub!(request_body, response_body = {})
|
104
|
-
r = stub_request(:post, "http://api.what3words.com/position").
|
105
|
-
with(:body => request_body).
|
106
|
-
to_return(:status => 200, :body => response_body.to_json)
|
107
|
-
end
|
108
|
-
|
109
|
-
it "extracts 3 words from response" do
|
110
|
-
stub! hash_including(:position => "1,2"), {:words => ["a", "b", "c"]}
|
111
|
-
expect(w3w.position_to_words([1, 2])).to eq ["a", "b", "c"]
|
112
|
-
end
|
113
|
-
|
114
|
-
it "returns full response if asked" do
|
115
|
-
stub! hash_including(:position => "1,2"), {:full => "1"}
|
116
|
-
expect(w3w.position_to_words([1, 2], :full_response => true)).to eq(:full => "1")
|
117
|
-
end
|
118
|
-
|
119
|
-
it "sends lang option" do
|
120
|
-
stub!(hash_including(:position => "1,2", :lang => "fr"))
|
121
|
-
w3w.position_to_words([1, 2], :language => "fr")
|
122
|
-
end
|
123
|
-
|
124
|
-
it "sends corners option" do
|
125
|
-
stub!(hash_including(:position => "1,2", :corners => "true"))
|
126
|
-
w3w.position_to_words([1, 2], :corners => true)
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "getting available languages" do
|
132
|
-
|
133
|
-
def stub!(request_body, response_body = {})
|
134
|
-
r = stub_request(:post, "http://api.what3words.com/get-languages").
|
135
|
-
with(:body => request_body).
|
136
|
-
to_return(:status => 200, :body => response_body.to_json)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "gets list of codes" do
|
140
|
-
stub! anything, {:languages => [{:code => "l1"}, {:code => "l2"}]}
|
141
|
-
expect(w3w.languages). to eq ["l1", "l2"]
|
142
|
-
end
|
143
|
-
|
144
|
-
it "gets full response" do
|
145
|
-
stub! anything, {:languages => [{:code => "l1"}, {:code => "l2"}]}
|
146
|
-
expect(w3w.languages :full_response => true).
|
147
|
-
to eq(:languages => [{:code => "l1"}, {:code => "l2"}])
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
it "'s deep_symbolize_keys helper works" do
|
152
|
-
expect(w3w.deep_symbolize_keys("foo" => {"bar" => 1, "baz" => [{"quux" => "www"}]})).
|
153
|
-
to eq(:foo => {:bar => 1, :baz => [{:quux => "www"}]})
|
154
|
-
end
|
155
|
-
end
|