what3words 2.0.4 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +86 -17
- data/Rakefile +7 -4
- data/lib/what3words/api.rb +55 -39
- data/lib/what3words/version.rb +1 -1
- data/lib/what3words.rb +2 -2
- data/spec/lib/what3words/what3words_api_spec.rb +91 -56
- data/spec/spec_helper.rb +3 -3
- data/what3words.gemspec +14 -13
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f9631e97c5f664a7205fdb297e03ec68ba80608
|
4
|
+
data.tar.gz: 1f45125f7dd016a8a17f75bd290b89f0f828e6fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b2e3c38f9979c34acc6efb3ddde9e076bce2a50c0e82c17018ea7fef9842a6d8b9d2c805e4b2509b3785a460a314c6f8ee144cb0bc7c52f9af943a0fd502de8
|
7
|
+
data.tar.gz: d006eab3c400debaf673c4d6f98ca8335dc8dbe7c7081b37e7063c62d98814b7383e72989b0e59c6b869ad17181eed7214ee80624887b17c38247706ea12c5cd
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
script: rake spec
|
3
|
+
- 2.4
|
4
|
+
script: rake rubocop spec
|
5
5
|
notifications:
|
6
6
|
slack:
|
7
7
|
secure: DvejcrOH6RdAdrGEPLUrnia9cES8iCHVlVSFAMwx2vaR/I3T9bfUiHnb3VHfiqx4cvDL+9wT3opG0sZkUCFJGqzA3E//VObKNXjwUFCUptFG68qgR7LZ3vDatWlUqU+32gWeYaHM3FpNP2E/IARjphaiF3jRUZbronqVzJZN2MbMsUYBeGq7v0AaLkgbxVgOWtBnMVcBPOnarEJqHyJlqQ2unYnIy+GNoOFtPMPNZobYTf0zxrycldYpP937yT4CTsY3I7RxuEtnY2sPYW+eFBESGLg6EfnjeOruROY+b9cSHIh1Qzr7Oup6a+oQ3+vCvLbYsGpEO04RTeTTtOGc7aRlUylmvuFPi7qQwOTZ+4KD5aIBh4p7bQiPfvAeqDU4pVJxPHHZirgjFpUpAvofj48SvDgwX9cFyAhAlDZ9qBOctmhphW9KNkcAW4MY421AdVAjFWwc5CU8G5oPdKcyWam3ZB3nHwKgZm6LLAcZgbG0rjZT+iPeQBvTKH3kPx7E1CkxZNkEralHJ3l+bDwY3GdzsgcMpT3bWNl3pLszFzgXljDScMU8my1+xjDQINEnI3TCJA4MhKkzYkRgfrEBkgPb2SiF7qnhbyMzSFbCU4jsM1MLQZolNG9EsjsxJLuL4YTC2wKOHajViUUeaCNIcNU5UXBQuit93RyMu7RrLRM=
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -7,15 +7,21 @@ Use the what3words API in your Ruby app (see http://developer.what3words.com/api
|
|
7
7
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
|
-
|
10
|
+
```shell
|
11
|
+
gem 'what3words', '~> 2.1'
|
12
|
+
```
|
11
13
|
|
12
14
|
And then execute:
|
13
15
|
|
16
|
+
```shell
|
14
17
|
$ bundle
|
18
|
+
```
|
15
19
|
|
16
20
|
Or install it yourself as:
|
17
21
|
|
22
|
+
```shell
|
18
23
|
$ gem install what3words
|
24
|
+
```
|
19
25
|
|
20
26
|
## Usage
|
21
27
|
|
@@ -26,24 +32,31 @@ passed to the API calls
|
|
26
32
|
|
27
33
|
If not using Bundler, require it:
|
28
34
|
|
29
|
-
|
35
|
+
```ruby
|
36
|
+
require 'what3words'
|
37
|
+
```
|
30
38
|
|
31
39
|
Then:
|
32
40
|
|
41
|
+
```ruby
|
33
42
|
what3words = What3Words::API.new(:key => "YOURAPIKEY")
|
43
|
+
```
|
34
44
|
|
35
45
|
Forward Geocode : convert a 3 word address into GPS coordinates (WGS-84)
|
36
46
|
|
37
|
-
|
47
|
+
```ruby
|
48
|
+
what3words.forward 'prom.cape.pump'
|
38
49
|
# => {: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"}
|
50
|
+
```
|
39
51
|
|
40
52
|
## API
|
41
53
|
### Forward Geocoding
|
42
54
|
Convert a 3 word address into GPS coordinates and return 3 words for the same position in a different language
|
43
55
|
|
56
|
+
```ruby
|
44
57
|
what3words.forward "prom.cape.pump", :lang => "fr"
|
45
58
|
# => {: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"}
|
46
|
-
|
59
|
+
```
|
47
60
|
Supported keyword params for `forward` call:
|
48
61
|
|
49
62
|
* `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)
|
@@ -53,13 +66,17 @@ Supported keyword params for `forward` call:
|
|
53
66
|
### Reverse Geocoding
|
54
67
|
Reverse Geocode : Convert position(latitude) information to a 3 word address
|
55
68
|
|
69
|
+
```ruby
|
56
70
|
what3words.reverse [51.484463, -0.195405]
|
57
71
|
# => {: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"}
|
72
|
+
```
|
58
73
|
|
59
74
|
Convert position information to a 3 word address in a specific language
|
60
75
|
|
76
|
+
```ruby
|
61
77
|
what3words.reverse [51.484463, -0.195405], :lang => :fr
|
62
78
|
# => {: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"}
|
79
|
+
```
|
63
80
|
|
64
81
|
Supported keyword params for `reverse` call:
|
65
82
|
|
@@ -78,14 +95,28 @@ This resource provides corrections for the following types of input error:
|
|
78
95
|
|
79
96
|
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.
|
80
97
|
|
98
|
+
*Single and Multilingual Variants*
|
99
|
+
|
100
|
+
AutoSuggest is provided via 2 variant resources; single language and multilingual.
|
101
|
+
|
102
|
+
The single language `autosuggest` method requires a language to be specified.
|
103
|
+
|
104
|
+
The multilingual `autosuggest_ml` method requires a language to be specified. This will ensure that the autosuggest-ml resource will look for suggestions in this language, in addition to any other languages that yield relevant suggestions.
|
105
|
+
|
81
106
|
see https://docs.what3words.com/api/v2/#autosuggest for detailed information
|
82
107
|
|
83
108
|
Gets suggestions in italian for this address
|
84
109
|
|
110
|
+
```ruby
|
85
111
|
what3words.autosuggest "trovò.calore.perder", "it"
|
86
112
|
# => {: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"}
|
113
|
+
```
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
what3words.autosuggest_ml "trovò.calore.perder", "it"
|
117
|
+
```
|
87
118
|
|
88
|
-
Supported keyword params for `autosuggest` call:
|
119
|
+
Supported keyword params for `autosuggest` and `autosuggest_ml` call:
|
89
120
|
* `format` Return data format type; can be one of json (the default), geojson or xml
|
90
121
|
* `display` Return display type; can be one of full (the default) or terse
|
91
122
|
|
@@ -94,14 +125,28 @@ Returns a blend of the three most relevant 3 word address candidates for a given
|
|
94
125
|
|
95
126
|
The specified 3 word address may either be a full 3 word address or a partial 3 word address containing the first 2 words in full and at least 1 character of the 3rd word. The standardblend resource provides the search logic that powers the search box on map.what3words.com and in the what3words mobile apps.
|
96
127
|
|
128
|
+
*Single and Multilingual Variants*
|
129
|
+
|
130
|
+
AutoSuggest is provided via 2 variant resources; single language and multilingual.
|
131
|
+
|
132
|
+
The single language `standardblend` method requires a language to be specified.
|
133
|
+
|
134
|
+
The multilingual `standardblend_ml` method requires a language to be specified. This will ensure that the standardblend-ml resource will look for suggestions in this language, in addition to any other languages that yield relevant suggestions.
|
135
|
+
|
97
136
|
see https://docs.what3words.com/api/v2/#standardblend for detailed information
|
98
137
|
|
99
138
|
Gets blends in italian for this address
|
100
139
|
|
140
|
+
```ruby
|
101
141
|
what3words.standardblend "trovò.calore.perder", "it"
|
102
142
|
# => {:blends=>[{:country=>"ma", :words=>"trovò.calore.perdere", :rank=>1, :language=>"it", :geometry=>{:lng=>-6.665638, :lat=>34.318065}, :place=>"Kenitra, Gharb-Chrarda-Beni Hssen"}, {:country=>"ca", :words=>"trovò.calore.perderò", :rank=>2, :language=>"it", :geometry=>{:lng=>-65.036149, :lat=>45.846472}, :place=>"Salisbury, New Brunswick"}, {:country=>"ve", :words=>"trovò.calore.prede", :rank=>3, :language=>"it", :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"}
|
143
|
+
```
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
what3words.standardblend_ml "trovò.calore.perder", "it"
|
147
|
+
```
|
103
148
|
|
104
|
-
Supported keyword params for `standardblend` call:
|
149
|
+
Supported keyword params for `standardblend` and `standardblend_ml` call:
|
105
150
|
* `format` Return data format type; can be one of json (the default), geojson or xml
|
106
151
|
* `display` Return display type; can be one of full (the default) or terse
|
107
152
|
|
@@ -112,8 +157,10 @@ see https://docs.what3words.com/api/v2/#grid for detailed information
|
|
112
157
|
|
113
158
|
Gets grid for these bounding box northeast 52.208867,0.117540, southwest 52.207988,0.116126
|
114
159
|
|
160
|
+
```ruby
|
115
161
|
what3words.grid "52.208867,0.117540,52.207988,0.116126"
|
116
162
|
# => {:lines=>[{:start=>{:lng=>0.11612600000001, :lat=>52.208009918068}, :end=>{:lng=>0.11753999999999, :lat=>52.208009918068}}, ___...___ , :end=>{:lng=>0.11752023935234, :lat=>52.208867}}], :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
|
163
|
+
```
|
117
164
|
|
118
165
|
Supported keyword params for `grid` call:
|
119
166
|
* `format` Return data format type; can be one of json (the default), geojson or xml
|
@@ -122,20 +169,14 @@ Supported keyword params for `grid` call:
|
|
122
169
|
### Get Languages
|
123
170
|
Get list of available 3 word languages
|
124
171
|
|
172
|
+
```ruby
|
125
173
|
what3words.languages
|
126
|
-
# => {:languages=>[{:name=>"German", :native_name=>"Deutsch", :code=>"
|
174
|
+
# => {{:languages=>[{:code=>"de", :name=>"German", :native_name=>"Deutsch"}, {:code=>"mn", :name=>"Mongolian", :native_name=>"Mонгол"}, {:code=>"fi", :name=>"Finnish", :native_name=>"Suomi"}, {:code=>"ru", :name=>"Russian", :native_name=>"Русский"}, {:code=>"sv", :name=>"Swedish", :native_name=>"Svenska"}, {:code=>"pt", :name=>"Portuguese", :native_name=>"Português"}, {:code=>"sw", :name=>"Swahili", :native_name=>"Kiswahili"}, {:code=>"en", :name=>"English", :native_name=>"English"}, {:code=>"it", :name=>"Italian", :native_name=>"Italiano"}, {:code=>"fr", :name=>"French", :native_name=>"Français"}, {:code=>"es", :name=>"Spanish", :native_name=>"Español"}, {:code=>"ar", :name=>"Arabic", :native_name=>"العربية"}, {:code=>"pl", :name=>"Polish", :native_name=>"Polski"}, {:code=>"tr", :name=>"Turkish", :native_name=>"Türkçe"}], :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
|
175
|
+
```
|
127
176
|
|
128
177
|
See http://developer.what3words.com for the original API call documentation
|
129
178
|
|
130
|
-
##
|
131
|
-
|
132
|
-
1. Fork it ( http://github.com/what3words/w3w-ruby-wrapper and click "Fork" )
|
133
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
134
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
135
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
136
|
-
5. Create new Pull Request
|
137
|
-
|
138
|
-
### Testing
|
179
|
+
## Testing
|
139
180
|
|
140
181
|
* Prerequisite : we are using [bundler](https://rubygems.org/gems/bundler) `$ gem install bundler`
|
141
182
|
|
@@ -147,4 +188,32 @@ $ export W3W_API_KEY=<Secret API Key>
|
|
147
188
|
* on you cloned folder
|
148
189
|
1. `$ cd w3w-ruby-wrapper`
|
149
190
|
1. `$ bundle update`
|
150
|
-
1. `$ rake spec`
|
191
|
+
1. `$ rake rubocop spec`
|
192
|
+
|
193
|
+
## Issues
|
194
|
+
|
195
|
+
Find a bug or want to request a new feature? Please let us know by submitting an issue.
|
196
|
+
|
197
|
+
## Contributing
|
198
|
+
Anyone and everyone is welcome to contribute.
|
199
|
+
|
200
|
+
1. Fork it (http://github.com/what3words/w3w-ruby-wrapper and click "Fork")
|
201
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
202
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
203
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
204
|
+
5. Create new Pull Request
|
205
|
+
|
206
|
+
# Revision History
|
207
|
+
|
208
|
+
* `v2.1.1` 22/05/17 - Update gemspec to use rubocop 0.48.1, and fixes spec accordingly
|
209
|
+
* `v2.1.0` 28/03/17 - Added multilingual version of `autosuggest` and `standardblend`
|
210
|
+
* `v2.0.4` 27/03/17 - Updated README with `languages` method result updated from live result
|
211
|
+
* `v2.0.3` 24/10/16 - Fixed `display` in `assemble_common_request_params`
|
212
|
+
* `v2.0.2` 10/06/16 - Added travis-ci builds
|
213
|
+
* `v2.0.0` 10/06/16 - Updated wrapper to use what3words API v2
|
214
|
+
|
215
|
+
## Licensing
|
216
|
+
|
217
|
+
The MIT License (MIT)
|
218
|
+
|
219
|
+
A copy of the license is available in the repository's [license](LICENSE.txt) file.
|
data/Rakefile
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
|
3
3
|
begin
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
6
|
+
t.options = ['--display-cop-names']
|
7
|
+
end
|
4
8
|
require 'rspec/core/rake_task'
|
5
|
-
|
6
9
|
RSpec::Core::RakeTask.new(:spec)
|
7
|
-
rescue LoadError
|
8
|
-
|
10
|
+
rescue LoadError => e
|
11
|
+
print e
|
9
12
|
end
|
data/lib/what3words/api.rb
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'rest-client'
|
4
4
|
|
5
5
|
module What3Words
|
6
|
-
class
|
7
|
-
|
6
|
+
# Document the responsibility of the class
|
7
|
+
#
|
8
|
+
class API # rubocop:disable Metrics/ClassLength
|
8
9
|
class Error < RuntimeError; end
|
9
10
|
class ResponseError < Error; end
|
10
11
|
class WordError < Error; end
|
11
12
|
|
12
13
|
REGEX_3_WORD_ADDRESS = /^\p{L}+\.\p{L}+\.\p{L}+$/u
|
13
|
-
REGEX_STRICT = /^\p{L}{
|
14
|
+
REGEX_STRICT = /^\p{L}{3,}+\.\p{L}{3,}+\.\p{L}{3,}+$/u
|
14
15
|
|
15
|
-
BASE_URL =
|
16
|
+
BASE_URL = 'https://api.what3words.com/v2/'.freeze
|
16
17
|
|
17
18
|
ENDPOINTS = {
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
|
19
|
+
forward: 'forward',
|
20
|
+
reverse: 'reverse',
|
21
|
+
languages: 'languages',
|
22
|
+
autosuggest: 'autosuggest',
|
23
|
+
standardblend: 'standardblend',
|
24
|
+
autosuggest_ml: 'autosuggest-ml',
|
25
|
+
standardblend_ml: 'standardblend-ml',
|
26
|
+
grid: 'grid'
|
27
|
+
}.freeze
|
25
28
|
|
26
29
|
def initialize(params)
|
27
30
|
@key = params.fetch(:key)
|
@@ -48,26 +51,42 @@ module What3Words
|
|
48
51
|
response
|
49
52
|
end
|
50
53
|
|
51
|
-
def languages
|
54
|
+
def languages
|
52
55
|
request_params = assemble_common_request_params({})
|
53
56
|
response = request! :languages, request_params
|
54
57
|
response
|
55
58
|
end
|
56
59
|
|
57
60
|
def autosuggest(addr, lang, focus = {}, clip = {}, params = {})
|
58
|
-
request_params = assemble_autosuggest_request_params(addr, lang, focus,
|
61
|
+
request_params = assemble_autosuggest_request_params(addr, lang, focus,
|
62
|
+
clip, params)
|
59
63
|
response = request! :autosuggest, request_params
|
60
64
|
response
|
61
65
|
end
|
62
66
|
|
67
|
+
def autosuggest_ml(addr, lang, focus = {}, clip = {}, params = {})
|
68
|
+
request_params = assemble_autosuggest_request_params(addr, lang, focus,
|
69
|
+
clip, params)
|
70
|
+
response = request! :autosuggest_ml, request_params
|
71
|
+
response
|
72
|
+
end
|
73
|
+
|
63
74
|
def standardblend(addr, lang, focus = {}, params = {})
|
64
|
-
request_params = assemble_standardblend_request_params(addr, lang, focus,
|
75
|
+
request_params = assemble_standardblend_request_params(addr, lang, focus,
|
76
|
+
params)
|
65
77
|
response = request! :standardblend, request_params
|
66
78
|
response
|
67
79
|
end
|
68
80
|
|
81
|
+
def standardblend_ml(addr, lang, focus = {}, params = {})
|
82
|
+
request_params = assemble_standardblend_request_params(addr, lang, focus,
|
83
|
+
params)
|
84
|
+
response = request! :standardblend_ml, request_params
|
85
|
+
response
|
86
|
+
end
|
87
|
+
|
69
88
|
def assemble_common_request_params(params)
|
70
|
-
h = {:key
|
89
|
+
h = { key: key }
|
71
90
|
h[:lang] = params[:lang] if params[:lang]
|
72
91
|
h[:format] = params[:format] if params[:format]
|
73
92
|
h[:display] = params[:display] if params[:display]
|
@@ -76,40 +95,36 @@ module What3Words
|
|
76
95
|
private :assemble_common_request_params
|
77
96
|
|
78
97
|
def assemble_forward_request_params(words_string, params)
|
79
|
-
h = {:
|
98
|
+
h = { addr: words_string }
|
80
99
|
h.merge(assemble_common_request_params(params))
|
81
100
|
end
|
82
101
|
private :assemble_forward_request_params
|
83
102
|
|
84
103
|
def assemble_grid_request_params(bbox, params)
|
85
|
-
h = {:bbox
|
104
|
+
h = { bbox: bbox }
|
86
105
|
h.merge(assemble_common_request_params(params))
|
87
106
|
end
|
88
107
|
private :assemble_grid_request_params
|
89
108
|
|
90
109
|
def assemble_reverse_request_params(position, params)
|
91
|
-
h = {:
|
110
|
+
h = { coords: position.join(',') }
|
92
111
|
h.merge(assemble_common_request_params(params))
|
93
112
|
end
|
94
113
|
private :assemble_reverse_request_params
|
95
114
|
|
96
115
|
def assemble_autosuggest_request_params(addr, lang, focus, clip, params)
|
97
|
-
h = {:addr
|
116
|
+
h = { addr: addr }
|
98
117
|
h[:lang] = lang
|
99
|
-
if focus.respond_to? :join
|
100
|
-
h[:focus] = focus.join(",")
|
101
|
-
end
|
118
|
+
h[:focus] = focus.join(',') if focus.respond_to? :join
|
102
119
|
h[:clip] = clip if clip.respond_to? :to_str
|
103
120
|
h.merge(assemble_common_request_params(params))
|
104
121
|
end
|
105
122
|
private :assemble_autosuggest_request_params
|
106
123
|
|
107
124
|
def assemble_standardblend_request_params(addr, lang, focus, params)
|
108
|
-
h = {:addr
|
125
|
+
h = { addr: addr }
|
109
126
|
h[:lang] = lang
|
110
|
-
if focus.respond_to? :join
|
111
|
-
h[:focus] = focus.join(",")
|
112
|
-
end
|
127
|
+
h[:focus] = focus.join(',') if focus.respond_to? :join
|
113
128
|
h.merge(assemble_common_request_params(params))
|
114
129
|
end
|
115
130
|
private :assemble_standardblend_request_params
|
@@ -122,11 +137,11 @@ module What3Words
|
|
122
137
|
rescue => e
|
123
138
|
response = e.response
|
124
139
|
end
|
125
|
-
# puts
|
126
|
-
# puts
|
140
|
+
# puts '#{response.to_str}'
|
141
|
+
# puts 'Response status: #{response.code}'
|
127
142
|
response = JSON.parse(response.body)
|
128
|
-
if response[
|
129
|
-
raise ResponseError, "#{response[
|
143
|
+
if response['code'].to_s.strip != ''
|
144
|
+
raise ResponseError, "#{response['code']}: #{response['message']}"
|
130
145
|
end
|
131
146
|
deep_symbolize_keys(response)
|
132
147
|
end
|
@@ -136,7 +151,7 @@ module What3Words
|
|
136
151
|
if words.respond_to? :to_str
|
137
152
|
w = words
|
138
153
|
elsif words.respond_to? :join
|
139
|
-
w = words.join(
|
154
|
+
w = words.join('.')
|
140
155
|
else
|
141
156
|
raise Error, "Cannot get words string for #{words.inspect}"
|
142
157
|
end
|
@@ -148,15 +163,17 @@ module What3Words
|
|
148
163
|
unless REGEX_3_WORD_ADDRESS.match(words)
|
149
164
|
raise WordError, "#{words} is not a valid 3 word address"
|
150
165
|
end
|
151
|
-
|
166
|
+
words
|
152
167
|
end
|
153
168
|
private :check_words
|
154
169
|
|
155
170
|
def deep_symbolize_keys(i)
|
156
|
-
if i.
|
171
|
+
if i.is_a? Hash
|
157
172
|
ni = {}
|
158
|
-
|
159
|
-
|
173
|
+
# rubocop:disable Metrics/LineLength
|
174
|
+
i.each { |k, v| ni[k.respond_to?(:to_sym) ? k.to_sym : k] = deep_symbolize_keys(v) }
|
175
|
+
# rubocop:enable Metrics/LineLength
|
176
|
+
elsif i.is_a? Array
|
160
177
|
ni = i.map(&method(:deep_symbolize_keys))
|
161
178
|
else
|
162
179
|
ni = i
|
@@ -165,14 +182,13 @@ module What3Words
|
|
165
182
|
ni
|
166
183
|
end
|
167
184
|
|
168
|
-
def base_url
|
185
|
+
def base_url
|
169
186
|
BASE_URL
|
170
187
|
end
|
171
188
|
private :base_url
|
172
189
|
|
173
190
|
def endpoint(name)
|
174
|
-
|
191
|
+
base_url + ENDPOINTS.fetch(name)
|
175
192
|
end
|
176
|
-
|
177
193
|
end
|
178
194
|
end
|
data/lib/what3words/version.rb
CHANGED
data/lib/what3words.rb
CHANGED
@@ -1,115 +1,150 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
describe What3Words::API,
|
6
|
-
|
3
|
+
require 'spec_helper'
|
4
|
+
# rubocop:disable Metrics/LineLength
|
5
|
+
describe What3Words::API, 'integration', integration: true do # rubocop:disable Metrics/BlockLength
|
6
|
+
# rubocop:enable Metrics/LineLength
|
7
7
|
before(:all) do
|
8
8
|
WebMock.allow_net_connect!
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:api_key) { ENV[
|
11
|
+
let(:api_key) { ENV['W3W_API_KEY'] }
|
12
12
|
|
13
|
-
let(:w3w) { described_class.new(:
|
13
|
+
let(:w3w) { described_class.new(key: api_key) }
|
14
14
|
|
15
|
-
it
|
16
|
-
badw3w = described_class.new(:
|
17
|
-
expect { badw3w.forward
|
18
|
-
to raise_error described_class::ResponseError
|
15
|
+
it 'returns errors from API' do
|
16
|
+
badw3w = described_class.new(key: '')
|
17
|
+
expect { badw3w.forward 'prom.cape.pump' }
|
18
|
+
.to raise_error described_class::ResponseError
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
|
23
|
-
|
24
|
-
result = w3w.forward "prom.cape.pump"
|
21
|
+
describe 'getting position' do
|
22
|
+
it 'works with string of 3 words separated by \'.\'' do
|
23
|
+
result = w3w.forward 'prom.cape.pump'
|
25
24
|
expect(result).to include(
|
26
|
-
:
|
27
|
-
:
|
25
|
+
words: 'prom.cape.pump',
|
26
|
+
language: 'en'
|
28
27
|
)
|
29
28
|
expect(result[:geometry]).to include(
|
30
|
-
:
|
31
|
-
:
|
29
|
+
lat: 51.484463,
|
30
|
+
lng: -0.195405
|
32
31
|
)
|
33
32
|
end
|
34
33
|
|
35
|
-
it
|
36
|
-
result = w3w.forward
|
34
|
+
it 'sends lang parameter for 3 words' do
|
35
|
+
result = w3w.forward 'prom.cape.pump', lang: 'fr'
|
37
36
|
expect(result).to include(
|
38
|
-
:
|
39
|
-
:
|
37
|
+
words: 'concevoir.époque.amasser',
|
38
|
+
language: 'fr'
|
40
39
|
)
|
41
40
|
end
|
42
41
|
|
43
|
-
it
|
44
|
-
expect { w3w.forward
|
45
|
-
to raise_error described_class::WordError
|
42
|
+
it 'checks 3 words format matches standard regex' do
|
43
|
+
expect { w3w.forward '1.cape.pump' }
|
44
|
+
.to raise_error described_class::WordError
|
46
45
|
end
|
47
|
-
|
48
46
|
end
|
49
47
|
|
50
|
-
describe
|
51
|
-
it
|
48
|
+
describe 'gets 3 words' do
|
49
|
+
it 'from position' do
|
52
50
|
result = w3w.reverse [29.567041, 106.587875]
|
53
51
|
expect(result).to include(
|
54
|
-
:
|
55
|
-
:
|
52
|
+
words: 'disclose.strain.redefined',
|
53
|
+
language: 'en'
|
56
54
|
)
|
57
55
|
end
|
58
56
|
|
59
|
-
it
|
60
|
-
result = w3w.reverse [29.567041, 106.587875], :
|
57
|
+
it 'from position in fr' do
|
58
|
+
result = w3w.reverse [29.567041, 106.587875], lang: 'fr'
|
61
59
|
expect(result).to include(
|
62
|
-
:
|
63
|
-
:
|
60
|
+
words: 'courgette.rabotons.infrason',
|
61
|
+
language: 'fr'
|
64
62
|
)
|
65
63
|
end
|
66
|
-
|
67
64
|
end
|
68
|
-
describe
|
69
|
-
it
|
65
|
+
describe 'autosuggest' do
|
66
|
+
it 'simple addr' do
|
70
67
|
# result =
|
71
|
-
w3w.autosuggest
|
68
|
+
w3w.autosuggest 'trop.caler.perdre', 'fr'
|
72
69
|
end
|
73
70
|
|
74
|
-
it
|
71
|
+
it 'with focus' do
|
75
72
|
# result =
|
76
|
-
w3w.autosuggest
|
73
|
+
w3w.autosuggest 'disclose.strain.redefin', 'en', [29.567041, 106.587875]
|
77
74
|
end
|
78
75
|
|
79
|
-
it
|
76
|
+
it 'with clipping radius around focus' do
|
80
77
|
# result =
|
81
|
-
w3w.autosuggest
|
78
|
+
w3w.autosuggest 'disclose.strain.redefin', 'en', [29.567041, 106.587875],
|
79
|
+
'focus(10)'
|
82
80
|
end
|
83
81
|
|
82
|
+
it 'arabic addr' do
|
83
|
+
# result =
|
84
|
+
w3w.autosuggest 'مربية.الصباح.المده', 'ar'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'autosuggest-ml' do
|
89
|
+
it '3 langs (result prefered de)' do
|
90
|
+
# result =
|
91
|
+
w3w.autosuggest_ml 'geschaft.planter.carciofi', 'de'
|
92
|
+
end
|
93
|
+
it '3 langs (result prefered fr)' do
|
94
|
+
# result =
|
95
|
+
w3w.autosuggest_ml 'geschaft.planter.carciofi', 'fr'
|
96
|
+
end
|
97
|
+
it '3 langs (result prefered it)' do
|
98
|
+
# result =
|
99
|
+
w3w.autosuggest_ml 'geschaft.planter.carciofi', 'it'
|
100
|
+
end
|
84
101
|
end
|
85
|
-
|
86
|
-
|
102
|
+
|
103
|
+
describe 'standardblend' do
|
104
|
+
it 'simple addr' do
|
87
105
|
# result =
|
88
|
-
w3w.standardblend
|
106
|
+
w3w.standardblend 'trop.caler.perdre', 'fr'
|
89
107
|
end
|
90
108
|
|
91
|
-
it
|
109
|
+
it 'with focus' do
|
92
110
|
# result =
|
93
|
-
w3w.standardblend
|
111
|
+
w3w.standardblend 'disclose.strain.redefin', 'en', [29.567041, 106.587875]
|
94
112
|
end
|
95
113
|
end
|
96
|
-
|
97
|
-
|
114
|
+
|
115
|
+
describe 'standardblend-ml' do
|
116
|
+
it '3 langs (result prefered de)' do
|
98
117
|
# result =
|
99
|
-
w3w.
|
118
|
+
w3w.standardblend_ml 'geschaft.planter.carciofi', 'de'
|
119
|
+
end
|
120
|
+
it '3 langs (result prefered fr)' do
|
121
|
+
# result =
|
122
|
+
w3w.standardblend_ml 'geschaft.planter.carciofi', 'fr'
|
123
|
+
end
|
124
|
+
it '3 langs (result prefered it)' do
|
125
|
+
# result =
|
126
|
+
w3w.standardblend_ml 'geschaft.planter.carciofi', 'it'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'grid' do
|
131
|
+
it 'string input' do
|
132
|
+
# result =
|
133
|
+
w3w.grid '52.208867,0.117540,52.207988,0.116126'
|
100
134
|
end
|
101
135
|
end
|
102
|
-
|
103
|
-
|
136
|
+
|
137
|
+
describe 'languages' do
|
138
|
+
it 'gets all languages' do
|
104
139
|
# result =
|
105
140
|
w3w.languages
|
106
141
|
end
|
107
142
|
end
|
108
143
|
|
109
|
-
describe
|
110
|
-
it
|
111
|
-
expect(w3w.deep_symbolize_keys(
|
112
|
-
to eq(:
|
144
|
+
describe 'technical' do
|
145
|
+
it '\'s deep_symbolize_keys helper works' do
|
146
|
+
expect(w3w.deep_symbolize_keys('foo' => { 'bar' => true }))
|
147
|
+
.to eq(foo: { bar: true })
|
113
148
|
end
|
114
149
|
end
|
115
150
|
end
|
data/spec/spec_helper.rb
CHANGED
data/what3words.gemspec
CHANGED
@@ -2,26 +2,27 @@
|
|
2
2
|
|
3
3
|
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require 'what3words/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'what3words'
|
9
9
|
spec.version = What3Words::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
10
|
+
spec.authors = ['what3words']
|
11
|
+
spec.email = ['development@what3words.com']
|
12
|
+
spec.summary = 'what3words API wrapper in Ruby'
|
13
|
+
spec.homepage = 'http://rubygems.org/gems/what3words'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^spec/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'rest-client', '~> 1.8'
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '>= 1.7.9'
|
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
|
+
spec.add_development_dependency 'rubocop', '~> 0.48.1'
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what3words
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- what3words
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.48.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.48.1
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- development@what3words.com
|