what3words 2.2.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +306 -72
- data/lib/what3words/api.rb +198 -144
- data/lib/what3words/version.rb +4 -1
- data/lib/what3words.rb +3 -1
- metadata +18 -30
- data/.editorconfig +0 -17
- data/.gitignore +0 -17
- data/.travis.yml +0 -7
- data/Gemfile +0 -2
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -12
- data/spec/config.sample.yaml +0 -1
- data/spec/lib/what3words/what3words_api_spec.rb +0 -150
- data/spec/spec_helper.rb +0 -7
- data/what3words.gemspec +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 80544ac9c1c8a40237f2172b461ce36232980fb005ce91859e0214956e69141d
|
4
|
+
data.tar.gz: f98a92b21dbb2950bf1464cb297f5adff151aa315f891ff8d7fd563e54b790fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf3e7792855a1c0f187bcd92afee0c4a3455d36159a9a65a542b3a7e75fd74bb6a96ff417c2ef84b67377132868b3df38ecb7656184a716cb9ef9137c50c080
|
7
|
+
data.tar.gz: 2fd293b19039de12b6b52d33bb71588d9e90372723f65f928ccef1a6b6ed56dfc3d909d2aea42b37d5859418d22eb7058b905dc7b13367a318dabb0ac415402d
|
data/README.md
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
# <img src="https://what3words.com/assets/images/w3w_square_red.png" width="32" height="32" alt="what3words"> what3words Ruby wrapper
|
2
|
-
![Build Status](https://travis-ci.org/what3words/w3w-ruby-wrapper.svg?branch=master)
|
3
2
|
|
4
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/what3words/w3w-ruby-wrapper.svg?branch=master)](https://travis-ci.org/what3words/w3w-ruby-wrapper)
|
4
|
+
|
5
|
+
The Ruby wrapper is useful for Ruby developers who wish to seamlessly integrate the [what3words Public API](https://developer.what3words.com/public-api) into their Ruby applications, without the hassle of having to manage the low level API calls themselves.
|
6
|
+
|
7
|
+
The what3words API is a fast, simple interface which allows you to convert what3words addresses such as `///index.home.raft` to latitude and longitude coordinates such as `-0.203586, 51.521251` and vice versa. It features a powerful autosuggest function, which can validate and autocorrect user input and limit it to certain geographic areas (this powers the search box on our map site). It allows you to request a section of the what3words grid (which can be requested as GeoJSON for easy display on online maps), and to request the list of all languages supported by what3words. For advanced users, autosuggest can be used to post-process voice output.
|
8
|
+
|
9
|
+
All coordinates are latitude,longitude pairs in standard `WGS-84` (as commonly used worldwide in GPS systems). All latitudes must be in the range of `-90 to 90 (inclusive)`.
|
5
10
|
|
6
11
|
## Installation
|
7
12
|
|
8
|
-
|
13
|
+
The library is available through [RubyGems](https://rubygems.org/gems/what3words).
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
You can simply add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```
|
18
|
+
gem 'what3words', '~> 3.1'
|
12
19
|
```
|
13
20
|
|
14
21
|
And then execute:
|
@@ -25,10 +32,9 @@ Or install it yourself as:
|
|
25
32
|
|
26
33
|
## Usage
|
27
34
|
|
28
|
-
Sign up for an API key at
|
35
|
+
Sign up for an API key at [https://developer.what3words.com](https://developer.what3words.com)
|
29
36
|
|
30
|
-
See https://docs.what3words.com/api/
|
31
|
-
passed to the API calls
|
37
|
+
See [https://developer.what3words.com/public-api/docs](https://developer.what3words.com/public-api/docs) for all parameters that can be passed to the API calls.
|
32
38
|
|
33
39
|
If not using Bundler, require it:
|
34
40
|
|
@@ -42,50 +48,66 @@ Then:
|
|
42
48
|
what3words = What3Words::API.new(:key => "YOURAPIKEY")
|
43
49
|
```
|
44
50
|
|
45
|
-
|
51
|
+
Convert to Coordinates: convert a what3words address into GPS coordinates (WGS84)
|
46
52
|
|
47
53
|
```ruby
|
48
|
-
|
49
|
-
|
54
|
+
what3words.convert_to_coordinates 'prom.cape.pump'
|
55
|
+
```
|
56
|
+
|
57
|
+
**Expected Output**
|
58
|
+
```
|
59
|
+
# => {:country=>"GB", :square=>{:southwest=>{:lng=>-0.195426, :lat=>51.484449}, :northeast=>{:lng=>-0.195383, :lat=>51.484476}}, :nearestPlace=>"Kensington, London", :coordinates=>{:lng=>-0.195405, :lat=>51.484463}, :words=>"prom.cape.pump", :language=>"en", :map=>"https://w3w.co/prom.cape.pump"}
|
50
60
|
```
|
51
61
|
|
52
62
|
## API
|
53
|
-
###
|
54
|
-
Convert a
|
63
|
+
### Convert to Coordinates
|
64
|
+
Convert a what3words address into GPS coordinates and return what3words for the same position.
|
55
65
|
|
56
66
|
```ruby
|
57
|
-
|
58
|
-
|
67
|
+
what3words.convert_to_coordinates "prom.cape.pump"
|
68
|
+
```
|
69
|
+
|
70
|
+
**Expected Output**
|
71
|
+
```
|
72
|
+
# => {:country=>"GB", :square=>{:southwest=>{:lng=>-0.195426, :lat=>51.484449}, :northeast=>{:lng=>-0.195383, :lat=>51.484476}}, :nearestPlace=>"Kensington, London", :coordinates=>{:lng=>-0.195405, :lat=>51.484463}, :words=>"prom.cape.pump", :language=>"en", :map=>"https://w3w.co/prom.cape.pump"}
|
59
73
|
```
|
60
|
-
Supported keyword params for `
|
74
|
+
Supported keyword params for `convert_to_coordinates` call:
|
75
|
+
|
76
|
+
* `words` A what3words address as a string
|
77
|
+
* `format` Return data format type. It can be one of json (the default) or geojson
|
61
78
|
|
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)
|
63
|
-
* `format` Return data format type; can be one of json (the default), geojson or xml
|
64
|
-
* `display` Return display type; can be one of full (the default) or terse
|
65
79
|
|
66
|
-
###
|
67
|
-
|
80
|
+
### Convert to 3WA
|
81
|
+
Convert position information, latitude and longitude coordinates, into a what3words address.
|
68
82
|
|
69
83
|
```ruby
|
70
|
-
|
71
|
-
|
72
|
-
|
84
|
+
what3words.convert_to_3wa [29.567041, 106.587875]
|
85
|
+
```
|
86
|
+
|
87
|
+
**Expected Output**
|
88
|
+
```
|
89
|
+
# => {:country=>"CN", :square=>{:southwest=>{:lng=>106.58786, :lat=>29.567028}, :northeast=>{:lng=>106.587891, :lat=>29.567055}}, :nearestPlace=>"Chongqing", :coordinates=>{:lng=>106.587875, :lat=>29.567041}, :words=>"disclose.strain.redefined", :language=>"en", :map=>"https://w3w.co/disclose.strain.redefined"}
|
90
|
+
```
|
73
91
|
|
74
|
-
Convert position information to a
|
92
|
+
Convert position information to a what3words address in a specific language
|
75
93
|
|
76
94
|
```ruby
|
77
|
-
|
78
|
-
|
95
|
+
what3words.convert_to_3wa [29.567041, 106.587875], language: 'fr'
|
96
|
+
```
|
97
|
+
|
98
|
+
**Expected Output**
|
99
|
+
```
|
100
|
+
# => :country=>"CN", :square=>{:southwest=>{:lng=>106.58786, :lat=>29.567028}, :northeast=>{:lng=>106.587891, :lat=>29.567055}}, :nearestPlace=>"Chongqing", :coordinates=>{:lng=>106.587875, :lat=>29.567041}, :words=>"courgette.rabotons.infrason", :language=>"fr", :map=>"https://w3w.co/courgette.rabotons.infrason"}
|
79
101
|
```
|
80
102
|
|
81
|
-
Supported keyword params for `
|
103
|
+
Supported keyword params for `convert_to_3wa` call:
|
82
104
|
|
83
|
-
* `
|
84
|
-
* `
|
85
|
-
* `
|
105
|
+
* `coordinates` The coordinates of the location to convert to what3words address
|
106
|
+
* `language` (defaults to en) - A supported what3words address language as an ISO 639-1 2 letter code
|
107
|
+
* `format` Return data format type. It can be one of json (the default) or geojson
|
86
108
|
|
87
109
|
### Autosuggest
|
88
|
-
Returns a list of
|
110
|
+
Returns a list of what3words addresses based on user input and other parameters.
|
89
111
|
|
90
112
|
This resource provides corrections for the following types of input error:
|
91
113
|
- typing errors
|
@@ -93,94 +115,299 @@ This resource provides corrections for the following types of input error:
|
|
93
115
|
- misremembered words (e.g. singular vs. plural)
|
94
116
|
- words in the wrong order
|
95
117
|
|
96
|
-
The autosuggest resource determines possible corrections to the supplied
|
118
|
+
The autosuggest resource determines possible corrections to the supplied what3words 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.
|
119
|
+
|
120
|
+
See [https://developer.what3words.com/public-api/docs#autosuggest](https://developer.what3words.com/public-api/docs#autosuggest) for detailed information
|
121
|
+
|
122
|
+
Gets suggestions in french for this address:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
what3words.autosuggest 'trop.caler.perdre', language: 'fr'
|
126
|
+
```
|
127
|
+
|
128
|
+
**Expected Output**
|
129
|
+
```
|
130
|
+
# => {:suggestions=>[{:country=>"FR", :nearestPlace=>"Saint-Lary-Soulan, Hautes-Pyrénées", :words=>"trier.caler.perdre", :rank=>1, :language=>"fr"}, {:country=>"ET", :nearestPlace=>"Asbe Teferi, Oromiya", :words=>"trôler.caler.perdre", :rank=>2, :language=>"fr"}, {:country=>"CN", :nearestPlace=>"Ulanhot, Inner Mongolia", :words=>"froc.caler.perdre", :rank=>3, :language=>"fr"}]}
|
131
|
+
```
|
97
132
|
|
98
|
-
|
133
|
+
Gets suggestions for a different number of suggestions, i.e. 10 for this address:
|
99
134
|
|
100
|
-
|
135
|
+
```ruby
|
136
|
+
what3words.autosuggest 'disclose.strain.redefin', language: 'en', 'n-results': 10
|
137
|
+
```
|
138
|
+
|
139
|
+
**Expected Output**
|
140
|
+
```
|
141
|
+
# => {:suggestions=>[{:country=>"SO", :nearestPlace=>"Jamaame, Lower Juba", :words=>"disclose.strain.redefine", :rank=>1, :language=>"en"}, {:country=>"ZW", :nearestPlace=>"Mutoko, Mashonaland East", :words=>"discloses.strain.redefine", :rank=>2, :language=>"en"}, {:country=>"MM", :nearestPlace=>"Mogok, Mandalay", :words=>"disclose.strains.redefine", :rank=>3, :language=>"en"}, {:country=>"CN", :nearestPlace=>"Chongqing", :words=>"disclose.strain.redefined", :rank=>4, :language=>"en"}, {:country=>"ZM", :nearestPlace=>"Binga, Matabeleland North", :words=>"disclosing.strain.redefine", :rank=>5, :language=>"en"}, {:country=>"XH", :nearestPlace=>"Leh, Ladakh", :words=>"disclose.straining.redefine", :rank=>6, :language=>"en"}, {:country=>"US", :nearestPlace=>"Kamas, Utah", :words=>"disclose.strain.redefining", :rank=>7, :language=>"en"}, {:country=>"GN", :nearestPlace=>"Boké", :words=>"disclose.strained.redefine", :rank=>8, :language=>"en"}, {:country=>"BO", :nearestPlace=>"Pailón, Santa Cruz", :words=>"discloses.strains.redefine", :rank=>9, :language=>"en"}, {:country=>"US", :nearestPlace=>"McGrath, Alaska", :words=>"discloses.strain.redefined", :rank=>10, :language=>"en"}]}
|
142
|
+
```
|
143
|
+
|
144
|
+
Gets suggestions when the coordinates for focus has been provided for this address:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
what3words.autosuggest 'filled.count.soap', focus: [51.4243877,-0.34745]
|
148
|
+
```
|
149
|
+
|
150
|
+
**Expected Output**
|
151
|
+
```
|
152
|
+
# => {:suggestions=>[{:country=>"US", :nearestPlace=>"Homer, Alaska", :words=>"fund.with.code", :rank=>1, :language=>"en"}, {:country=>"AU", :nearestPlace=>"Kumpupintil, Western Australia", :words=>"funk.with.code", :rank=>2, :language=>"en"}, {:country=>"US", :nearestPlace=>"Charleston, West Virginia", :words=>"fund.with.cove", :rank=>3, :language=>"en"}]}
|
153
|
+
```
|
101
154
|
|
102
|
-
|
155
|
+
Gets suggestions for a different number of focus results for this address:
|
103
156
|
|
104
|
-
|
157
|
+
```ruby
|
158
|
+
what3words.autosuggest 'disclose.strain.redefin', language: 'en', 'n-focus-results': 3
|
159
|
+
```
|
105
160
|
|
106
|
-
|
161
|
+
**Expected Output**
|
162
|
+
```
|
163
|
+
# => {:suggestions=>[{:country=>"SO", :nearestPlace=>"Jamaame, Lower Juba", :words=>"disclose.strain.redefine", :rank=>1, :language=>"en"}, {:country=>"ZW", :nearestPlace=>"Mutoko, Mashonaland East", :words=>"discloses.strain.redefine", :rank=>2, :language=>"en"}, {:country=>"MM", :nearestPlace=>"Mogok, Mandalay", :words=>"disclose.strains.redefine", :rank=>3, :language=>"en"}]}
|
164
|
+
```
|
107
165
|
|
108
|
-
Gets suggestions
|
166
|
+
Gets suggestions for a voice input type mode, i.e. generic-voice, for this address:
|
109
167
|
|
110
168
|
```ruby
|
111
|
-
|
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"}
|
169
|
+
what3words.autosuggest 'fun with code', 'input-type': 'generic-voice', language: 'en'
|
113
170
|
```
|
114
171
|
|
172
|
+
**Expected Output**
|
173
|
+
```
|
174
|
+
# => {:suggestions=>[{:country=>"US", :nearestPlace=>"Homer, Alaska", :words=>"fund.with.code", :rank=>1, :language=>"en"}, {:country=>"AU", :nearestPlace=>"Kumpupintil, Western Australia", :words=>"funk.with.code", :rank=>2, :language=>"en"}, {:country=>"US", :nearestPlace=>"Charleston, West Virginia", :words=>"fund.with.cove", :rank=>3, :language=>"en"}]}
|
175
|
+
```
|
176
|
+
|
177
|
+
Gets suggestions for a restricted area by clipping to country for this address:
|
178
|
+
|
115
179
|
```ruby
|
116
|
-
|
180
|
+
what3words.autosuggest 'disclose.strain.redefin', 'clip-to-country': 'GB,BE'
|
117
181
|
```
|
118
182
|
|
119
|
-
|
120
|
-
|
121
|
-
|
183
|
+
**Expected Output**
|
184
|
+
```
|
185
|
+
# => {:suggestions=>[{:country=>"GB", :nearestPlace=>"Nether Stowey, Somerset", :words=>"disclose.retrain.redefined", :rank=>1, :language=>"en"}, {:country=>"BE", :nearestPlace=>"Zemst, Flanders", :words=>"disclose.strain.reckon", :rank=>2, :language=>"en"}, {:country=>"GB", :nearestPlace=>"Waddington, Lincolnshire", :words=>"discloses.trains.redefined", :rank=>3, :language=>"en"}]}
|
186
|
+
```
|
122
187
|
|
123
|
-
|
124
|
-
Returns a blend of the three most relevant 3 word address candidates for a given location, based on a full or partial 3 word address.
|
188
|
+
Gets suggestions for a restricted area by clipping to a bounding-box for this address:
|
125
189
|
|
126
|
-
|
190
|
+
```ruby
|
191
|
+
what3words.autosuggest 'disclose.strain.redefin', 'clip-to-bounding-box': [51.521, -0.343, 52.6, 2.3324]
|
192
|
+
```
|
127
193
|
|
128
|
-
|
194
|
+
**Expected Output**
|
195
|
+
```
|
196
|
+
# => {:suggestions=>[{:country=>"GB", :nearestPlace=>"Saxmundham, Suffolk", :words=>"discloses.strain.reddish", :rank=>1, :language=>"en"}]}
|
197
|
+
```
|
129
198
|
|
130
|
-
AutoSuggest is provided via 2 variant resources; single language and multilingual.
|
131
199
|
|
132
|
-
|
200
|
+
Gets suggestions for a restricted area by clipping to a circle in km for this address:
|
133
201
|
|
134
|
-
|
202
|
+
```ruby
|
203
|
+
what3words.autosuggest 'disclose.strain.redefin', 'clip-to-circle': [51.521, -0.343, 142]
|
204
|
+
```
|
135
205
|
|
136
|
-
|
206
|
+
**Expected Output**
|
207
|
+
```
|
208
|
+
# => {:suggestions=>[{:country=>"GB", :nearestPlace=>"Market Harborough, Leicestershire", :words=>"discloses.strain.reduce", :rank=>1, :language=>"en"}]}
|
209
|
+
```
|
137
210
|
|
138
|
-
Gets
|
211
|
+
Gets suggestions for a restricted area by clipping to a polygon for this address:
|
139
212
|
|
140
213
|
```ruby
|
141
|
-
|
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"}
|
214
|
+
what3words.autosuggest 'disclose.strain.redefin', 'clip-to-polygon': [51.521, -0.343, 52.6, 2.3324, 54.234, 8.343, 51.521, -0.343]
|
143
215
|
```
|
144
216
|
|
217
|
+
**Expected Output**
|
218
|
+
```
|
219
|
+
# => {:suggestions=>[{:country=>"GB", :nearestPlace=>"Saxmundham, Suffolk", :words=>"discloses.strain.reddish", :rank=>1, :language=>"en"}]}
|
220
|
+
```
|
221
|
+
|
222
|
+
Gets suggestions for a restricted area by clipping to a polygon for this address:
|
223
|
+
|
145
224
|
```ruby
|
146
|
-
|
225
|
+
what3words.w3w.autosuggest 'disclose.strain.redefin', 'prefer-land': false, 'n-results': 10
|
226
|
+
```
|
227
|
+
|
228
|
+
**Expected Output**
|
229
|
+
```
|
230
|
+
# => {:suggestions=>[{:country=>"SO", :nearestPlace=>"Jamaame, Lower Juba", :words=>"disclose.strain.redefine", :rank=>1, :language=>"en"}, {:country=>"ZW", :nearestPlace=>"Mutoko, Mashonaland East", :words=>"discloses.strain.redefine", :rank=>2, :language=>"en"}, {:country=>"MM", :nearestPlace=>"Mogok, Mandalay", :words=>"disclose.strains.redefine", :rank=>3, :language=>"en"}, {:country=>"CN", :nearestPlace=>"Chongqing", :words=>"disclose.strain.redefined", :rank=>4, :language=>"en"}, {:country=>"ZM", :nearestPlace=>"Binga, Matabeleland North", :words=>"disclosing.strain.redefine", :rank=>5, :language=>"en"}, {:country=>"XH", :nearestPlace=>"Leh, Ladakh", :words=>"disclose.straining.redefine", :rank=>6, :language=>"en"}, {:country=>"US", :nearestPlace=>"Kamas, Utah", :words=>"disclose.strain.redefining", :rank=>7, :language=>"en"}, {:country=>"GN", :nearestPlace=>"Boké", :words=>"disclose.strained.redefine", :rank=>8, :language=>"en"}, {:country=>"BO", :nearestPlace=>"Pailón, Santa Cruz", :words=>"discloses.strains.redefine", :rank=>9, :language=>"en"}, {:country=>"US", :nearestPlace=>"McGrath, Alaska", :words=>"discloses.strain.redefined", :rank=>10, :language=>"en"}]}
|
147
231
|
```
|
148
232
|
|
149
|
-
Supported keyword params for `
|
150
|
-
* `
|
151
|
-
* `
|
233
|
+
Supported keyword params for `autosuggest` call:
|
234
|
+
* `input` The full or partial what3words address to obtain suggestions for. At minimum this must be the first two complete words plus at least one character from the third word.
|
235
|
+
* `language` A supported what3words address language as an ISO 639-1 2 letter code. This setting is on by default. Use false to disable this setting and receive more suggestions in the sea.
|
236
|
+
* `n_results` The number of AutoSuggest results to return. A maximum of 100 results can be specified, if a number greater than this is requested, this will be truncated to the maximum. The default is 3.
|
237
|
+
* `n_focus_results` Specifies the number of results (must be <= n_results) within the results set which will have a focus. Defaults to n_results. This allows you to run autosuggest with a mix of focussed and unfocussed results, to give you a "blend" of the two.
|
238
|
+
* `clip-to-country` Restricts autosuggest to only return results inside the countries specified by comma-separated list of uppercase ISO 3166-1 alpha-2 country codes (for example, to restrict to Belgium and the UK, use clip_to_country="GB,BE").
|
239
|
+
* `clip-to-bounding-box` Restrict autosuggest results to a bounding box, specified by coordinates.
|
240
|
+
* `clip-to-circle` Restrict autosuggest results to a circle, specified by the center of the circle, latitude and longitude, and a distance in kilometres which represents the radius. For convenience, longitude is allowed to wrap around 180 degrees. For example 181 is equivalent to -179.
|
241
|
+
* `clip-to-polygon` Restrict autosuggest results to a polygon, specified by a list of coordinates. The polygon should be closed, i.e. the first element should be repeated as the last element; also the list should contain at least 4 entries. The API is currently limited to accepting up to 25 pairs.
|
242
|
+
* `input-type` For power users, used to specify voice input mode. Can be text (default), vocon-hybrid, nmdp-asr or generic-voice.
|
243
|
+
* `prefer-land` Makes autosuggest prefer results on land to those in the sea.
|
152
244
|
|
153
245
|
### Grid
|
154
246
|
Returns a section of the 3m x 3m what3words grid for a given area.
|
155
247
|
|
156
|
-
|
248
|
+
See [https://developer.what3words.com/public-api/docs#grid-section](https://developer.what3words.com/public-api/docs#grid-section) for detailed information.
|
157
249
|
|
158
|
-
Gets grid for these bounding box northeast 52.208867,0.117540,
|
250
|
+
Gets grid for these bounding box northeast 52.208867,0.117540,52.207988,0.116126.
|
159
251
|
|
160
252
|
```ruby
|
161
|
-
|
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"}
|
253
|
+
what3words.grid_section '52.208867,0.117540,52.207988,0.116126'
|
163
254
|
```
|
164
255
|
|
165
|
-
|
166
|
-
|
167
|
-
|
256
|
+
**Expected Output**
|
257
|
+
```
|
258
|
+
# => {:lines=>[{:start=>{:lng=>0.116126, :lat=>52.20801}, :end=>{:lng=>0.11754, :lat=>52.20801}}, {:start=>{:lng=>0.116126, :lat=>52.208037}, :end=>{:lng=>0.11754, :lat=>52.208037}}, {:start=>{:lng=>0.116126, :lat=>52.208064}, :end=>{:lng=>0.11754, :lat=>52.208064}}, ___...___ ]}
|
259
|
+
```
|
260
|
+
|
261
|
+
Supported keyword params for `grid_section` call:
|
262
|
+
* `bounding-box` The bounding box is specified by the northeast and southwest corner coordinates, for which the grid should be returned
|
263
|
+
* `format` Return data format type. It can be one of json (the default) or geojson
|
168
264
|
|
169
265
|
### Get Languages
|
170
|
-
|
266
|
+
Retrieve a list of available what3words languages.
|
267
|
+
|
268
|
+
```ruby
|
269
|
+
what3words.available_languages
|
270
|
+
```
|
271
|
+
|
272
|
+
**Expected Output**
|
273
|
+
```
|
274
|
+
# => {:languages=>[{:nativeName=>"Deutsch", :code=>"de", :name=>"German"}, {:nativeName=>"हिन्दी", :code=>"hi", :name=>"Hindi"}, {:nativeName=>"Português", :code=>"pt", :name=>"Portuguese"}, {:nativeName=>"Magyar", :code=>"hu", :name=>"Hungarian"}, {:nativeName=>"Українська", :code=>"uk", :name=>"Ukrainian"}, {:nativeName=>"Bahasa Indonesia", :code=>"id", :name=>"Bahasa Indonesia"}, {:nativeName=>"اردو", :code=>"ur", :name=>"Urdu"}, ___...___]}
|
275
|
+
```
|
276
|
+
|
277
|
+
See [https://developer.what3words.com/public-api/docs#available-languages](https://developer.what3words.com/public-api/docs#available-languages) for the original API call documentation.
|
278
|
+
|
279
|
+
### RegEx functions
|
280
|
+
|
281
|
+
This section introduces RegEx functions that can assist with checking and finding possible what3words addresses in strings. The three main functions covered are:
|
282
|
+
|
283
|
+
`isPossible3wa` – Match what3words address format;
|
284
|
+
`findPossible3wa` – Find what3words address in Text;
|
285
|
+
`isValid3wa` – Verify a what3words address with the API;
|
286
|
+
|
287
|
+
#### isPossible3wa
|
288
|
+
|
289
|
+
Our API wrapper RegEx function `isPossible3wa` can be used used to detect if a text string (like `filled.count.soap`) in the format of a what3words address without having to ask the API. This functionality checks if a given string could be a what3words address. It returns true if it could be, otherwise false.
|
290
|
+
|
291
|
+
**Note**: This function checks the text format but not the validity of a what3words address. Use `isValid3wa` to verify validity.
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
require 'what3words'
|
295
|
+
|
296
|
+
def main
|
297
|
+
# Initialize the What3Words API with your API key
|
298
|
+
api_key = 'YOUR_API_KEY'
|
299
|
+
w3w = What3Words::API.new(:key => api_key)
|
300
|
+
|
301
|
+
# Example what3words addresses
|
302
|
+
addresses = ["filled.count.soap", "not a 3wa", "not.3wa address"]
|
303
|
+
|
304
|
+
# Check if the addresses are possible what3words addresses
|
305
|
+
addresses.each do |address|
|
306
|
+
is_possible = w3w.isPossible3wa(address)
|
307
|
+
puts "Is '#{address}' a possible what3words address? #{is_possible}"
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
if __FILE__ == $0
|
312
|
+
main
|
313
|
+
end
|
314
|
+
```
|
315
|
+
|
316
|
+
**Expected Output**
|
317
|
+
|
318
|
+
isPossible3wa(“filled.count.soap”) returns true
|
319
|
+
isPossible3wa(“not a 3wa”) returns false
|
320
|
+
isPossible3wa(“not.3wa address”)returns false
|
321
|
+
|
322
|
+
#### findPossible3wa
|
323
|
+
|
324
|
+
Our API wrapper RegEx function `findPossible3wa` can be used to detect a what3words address within a block of text, useful for finding a what3words address in fields like Delivery Notes. For example, it can locate a what3words address in a note like “Leave at my front door ///filled.count.soap”. The function will match if there is a what3words address within the text. If no possible addresses are found, it returns an empty list.
|
325
|
+
|
326
|
+
**Note**:
|
327
|
+
|
328
|
+
- This function checks the text format but not the validity of a what3words address. Use `isValid3wa` to verify validity.
|
329
|
+
- This function is designed to work across languages but do not work for `Vietnamese (VI)` due to spaces within words.
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
require 'what3words'
|
333
|
+
|
334
|
+
def main
|
335
|
+
# Initialize the what3words API with your API key
|
336
|
+
api_key = 'YOUR_API_KEY'
|
337
|
+
w3w = What3Words::API.new(:key => api_key)
|
338
|
+
|
339
|
+
# Example texts
|
340
|
+
texts = [
|
341
|
+
"Please leave by my porch at filled.count.soap",
|
342
|
+
"Please leave by my porch at filled.count.soap or deed.tulip.judge",
|
343
|
+
"Please leave by my porch at"
|
344
|
+
]
|
345
|
+
|
346
|
+
# Check if the texts contain possible what3words addresses
|
347
|
+
texts.each do |text|
|
348
|
+
possible_addresses = w3w.findPossible3wa(text)
|
349
|
+
puts "Possible what3words addresses in '#{text}': #{possible_addresses}"
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
if __FILE__ == $0
|
354
|
+
main
|
355
|
+
end
|
356
|
+
```
|
357
|
+
|
358
|
+
**Expected Output**
|
359
|
+
|
360
|
+
findPossible3wa(“Please leave by my porch at filled.count.soap”) returns ['filled.count.soap']
|
361
|
+
findPossible3wa(“Please leave by my porch at filled.count.soap or deed.tulip.judge”) returns ['filled.count.soap', 'deed.tulip.judge']
|
362
|
+
findPossible3wa(“Please leave by my porch at”) returns []
|
363
|
+
|
364
|
+
#### isValid3wa
|
365
|
+
|
366
|
+
Our API wrapper RegEx function `isValid3wa` can be used to determine if a string is a valid what3words address by checking it against the what3words RegEx filter and verifying it with the what3words API.
|
171
367
|
|
172
368
|
```ruby
|
173
|
-
|
174
|
-
|
369
|
+
require 'what3words'
|
370
|
+
|
371
|
+
def main
|
372
|
+
# Initialize the what3words API with your API key
|
373
|
+
api_key = 'YOUR_API_KEY'
|
374
|
+
w3w = What3Words::API.new(:key => api_key)
|
375
|
+
|
376
|
+
# Example addresses
|
377
|
+
addresses = [
|
378
|
+
"filled.count.soap",
|
379
|
+
"filled.count.",
|
380
|
+
"coding.is.cool"
|
381
|
+
]
|
382
|
+
|
383
|
+
# Check if the addresses are valid what3words addresses
|
384
|
+
addresses.each do |address|
|
385
|
+
is_valid = w3w.isValid3wa(address)
|
386
|
+
puts "Is '#{address}' a valid what3words address? #{is_valid}"
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
if __FILE__ == $0
|
391
|
+
main
|
392
|
+
end
|
175
393
|
```
|
394
|
+
**Expected Outputs**
|
395
|
+
|
396
|
+
isValid3wa(“filled.count.soap”) returns True
|
397
|
+
isValid3wa(“filled.count.”) returns False
|
398
|
+
isValid3wa(“coding.is.cool”) returns False
|
399
|
+
|
400
|
+
Also make sure to replace `<YOUR_API_KEY>` with your actual API key. These functionalities provide different levels of validation for what3words addresses, from simply identifying potential addresses to verifying their existence on Earth.
|
401
|
+
|
402
|
+
|
403
|
+
See [https://developer.what3words.com/tutorial/ruby#regex-functions](https://developer.what3words.com/tutorial/ruby#regex-functions) for further documentation.
|
176
404
|
|
177
|
-
See http://developer.what3words.com for the original API call documentation
|
178
405
|
|
179
406
|
## Testing
|
180
407
|
|
181
408
|
* Prerequisite : we are using [bundler](https://rubygems.org/gems/bundler) `$ gem install bundler`
|
182
409
|
|
183
|
-
* W3W-API-KEY
|
410
|
+
* W3W-API-KEY: For safe storage of your API key on your computer, you can define that API key using your system’s environment variables.
|
184
411
|
```bash
|
185
412
|
$ export W3W_API_KEY=<Secret API Key>
|
186
413
|
```
|
@@ -190,6 +417,11 @@ $ export W3W_API_KEY=<Secret API Key>
|
|
190
417
|
1. `$ bundle update`
|
191
418
|
1. `$ rake rubocop spec`
|
192
419
|
|
420
|
+
To run the tests, type on your terminal:
|
421
|
+
```bash
|
422
|
+
$ bundle exec rspec
|
423
|
+
```
|
424
|
+
|
193
425
|
## Issues
|
194
426
|
|
195
427
|
Find a bug or want to request a new feature? Please let us know by submitting an issue.
|
@@ -206,6 +438,8 @@ Anyone and everyone is welcome to contribute.
|
|
206
438
|
|
207
439
|
# Revision History
|
208
440
|
|
441
|
+
* `v3.1.0` 16/07/24 - Update tests and code to host the regex functions
|
442
|
+
* `v3.0.0` 12/05/22 - Update endpoints and tests to API v3, added HTTP headers
|
209
443
|
* `v2.2.0` 03/01/18 - Enforce Ruby 2.4 Support - Thanks to PR from Dimitrios Zorbas [@Zorbash](https://github.com/zorbash)
|
210
444
|
* `v2.1.1` 22/05/17 - Update gemspec to use rubocop 0.48.1, and fixes spec accordingly
|
211
445
|
* `v2.1.0` 28/03/17 - Added multilingual version of `autosuggest` and `standardblend`
|