what3words 3.0.0 → 3.1.0
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/README.md +244 -45
- data/lib/what3words/api.rb +175 -190
- data/lib/what3words/version.rb +1 -1
- metadata +9 -20
- data/.editorconfig +0 -17
- data/.gitignore +0 -17
- data/.travis.yml +0 -7
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -14
- data/spec/config.sample.yaml +0 -1
- data/spec/lib/what3words/what3words_api_spec.rb +0 -297
- data/spec/spec_helper.rb +0 -9
- data/what3words.gemspec +0 -31
@@ -1,297 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
# to run the test type on terminal --> bundle exec rspec
|
6
|
-
|
7
|
-
describe What3Words::API, 'integration', integration: true do
|
8
|
-
before(:all) do
|
9
|
-
WebMock.allow_net_connect!
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:api_key) { ENV['W3W_API_KEY'] }
|
13
|
-
let(:w3w) { described_class.new(key: api_key) }
|
14
|
-
|
15
|
-
it 'returns errors from API' do
|
16
|
-
badw3w = described_class.new(key: 'BADKEY')
|
17
|
-
expect { badw3w.convert_to_coordinates 'prom.cape.pump' }
|
18
|
-
.to raise_error described_class::ResponseError
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'getting position' do
|
22
|
-
# @:param string words: A 3 word address as a string
|
23
|
-
# @:param string format: Return data format type; can be one of json (the default), geojson
|
24
|
-
it 'works with string of 3 words separated by \'.\'' do
|
25
|
-
result = w3w.convert_to_coordinates 'prom.cape.pump'
|
26
|
-
expect(result).to include(
|
27
|
-
words: 'prom.cape.pump',
|
28
|
-
language: 'en'
|
29
|
-
)
|
30
|
-
expect(result[:coordinates]).to include(
|
31
|
-
lat: 51.484463,
|
32
|
-
lng: -0.195405
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'sends language parameter for 3 words' do
|
37
|
-
result = w3w.convert_to_coordinates 'prom.cape.pump'
|
38
|
-
expect(result).to include(
|
39
|
-
words: 'prom.cape.pump',
|
40
|
-
language: 'en'
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'checks 3 words format matches standard regex' do
|
45
|
-
expect { w3w.convert_to_coordinates '1.cape.pump' }
|
46
|
-
.to raise_error described_class::WordError
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'sends json parameter for 3 words' do
|
50
|
-
result = w3w.convert_to_coordinates 'prom.cape.pump', format: 'json'
|
51
|
-
expect(result).to include(
|
52
|
-
words: 'prom.cape.pump',
|
53
|
-
language: 'en',
|
54
|
-
country: 'GB',
|
55
|
-
square: {
|
56
|
-
'southwest': {
|
57
|
-
'lng': -0.195426,
|
58
|
-
'lat': 51.484449
|
59
|
-
},
|
60
|
-
'northeast': {
|
61
|
-
'lng': -0.195383,
|
62
|
-
'lat': 51.484476
|
63
|
-
}
|
64
|
-
},
|
65
|
-
nearestPlace: 'Kensington, London',
|
66
|
-
coordinates: {
|
67
|
-
'lng': -0.195405,
|
68
|
-
'lat': 51.484463
|
69
|
-
},
|
70
|
-
map: 'https://w3w.co/prom.cape.pump'
|
71
|
-
)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'gets 3 words' do
|
76
|
-
# @:param coordinates: the coordinates of the location to convert to 3 word address
|
77
|
-
it 'from position' do
|
78
|
-
result = w3w.convert_to_3wa [29.567041, 106.587875], format: 'json'
|
79
|
-
expect(result).to include(
|
80
|
-
words: 'disclose.strain.redefined',
|
81
|
-
language: 'en'
|
82
|
-
)
|
83
|
-
expect(result[:coordinates]).to include(
|
84
|
-
lat: 29.567041,
|
85
|
-
lng: 106.587875
|
86
|
-
)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'from position in fr' do
|
90
|
-
result = w3w.convert_to_3wa [29.567041, 106.587875], language: 'fr', format: 'json'
|
91
|
-
expect(result).to include(
|
92
|
-
words: 'courgette.rabotons.infrason',
|
93
|
-
language: 'fr'
|
94
|
-
)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe 'autosuggest' do
|
99
|
-
it 'single input returns suggestions' do
|
100
|
-
# @:param string input: The full or partial 3 word address to obtain
|
101
|
-
# suggestions for. At minimum this must be the first two complete words
|
102
|
-
# plus at least one character from the third word.
|
103
|
-
result = w3w.autosuggest 'disclose.strain.redefin'
|
104
|
-
expect(result).not_to be_empty
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'simple input will return 3 suggestions' do
|
108
|
-
# @:param string input: The full or partial 3 word address to obtain
|
109
|
-
# suggestions for. At minimum this must be the first two complete words
|
110
|
-
# plus at least one character from the third word.
|
111
|
-
result = w3w.autosuggest 'disclose.strain.redefin', language: 'en'
|
112
|
-
n_default_results = result[:suggestions].count
|
113
|
-
expect(n_default_results).to eq(3)
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'sends language parameter to an input in a different language' do
|
117
|
-
# @:param string language: A supported 3 word address language as an
|
118
|
-
# ISO 639-1 2 letter code.
|
119
|
-
result = w3w.autosuggest 'trop.caler.perdre', language: 'fr'
|
120
|
-
language = result[:suggestions]
|
121
|
-
language.each do |item|
|
122
|
-
item.each do |k, v|
|
123
|
-
if k == 'language'
|
124
|
-
expect(v).to eq('fr')
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'sends arabic language as a different input' do
|
131
|
-
result = w3w.autosuggest 'مربية.الصباح.المده', language: 'ar'
|
132
|
-
expect(result).not_to be_empty
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'with n-results' do
|
136
|
-
# @:param int n_results: The number of AutoSuggest results to return.
|
137
|
-
# A maximum of 100 results can be specified, if a number greater than this is
|
138
|
-
# requested, this will be truncated to the maximum. The default is 3.
|
139
|
-
result = w3w.autosuggest 'disclose.strain.redefin', language: 'en', 'n-results': 10
|
140
|
-
# puts result[:suggestions].count
|
141
|
-
n_results = result[:suggestions].count
|
142
|
-
expect(n_results).to be >= 10
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'with n-focus-results' do
|
146
|
-
# @:param int n_focus_results: Specifies the number of results (must be <= n_results)
|
147
|
-
# within the results set which will have a focus. Defaults to
|
148
|
-
# n_results. This allows you to run autosuggest with a mix of
|
149
|
-
# focussed and unfocussed results, to give you a "blend" of the two.
|
150
|
-
result = w3w.autosuggest 'disclose.strain.redefin', language: 'en', 'n-focus-results': 3
|
151
|
-
# puts result[:suggestions].count
|
152
|
-
n_focus_results = result[:suggestions].count
|
153
|
-
expect(n_focus_results).to be >= 3
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'with input-type chenged to generic-voice' do
|
157
|
-
# @:param string input-type: For power users, used to specify voice input mode. Can be
|
158
|
-
# text (default), vocon-hybrid, nmdp-asr or generic-voice.
|
159
|
-
result = w3w.autosuggest 'fun with code', 'input-type': 'generic-voice', language: 'en'
|
160
|
-
suggestions = result[:suggestions]
|
161
|
-
output = ['fund.with.code', 'funk.with.code', 'fund.with.cove']
|
162
|
-
suggestions.each_with_index do |item, index|
|
163
|
-
# puts item[:words]
|
164
|
-
expect(item[:words]).to eq(output[index])
|
165
|
-
end
|
166
|
-
|
167
|
-
expect(result).not_to be_empty
|
168
|
-
end
|
169
|
-
|
170
|
-
xit 'with prefer-land' do
|
171
|
-
# @:param string prefer-land: Makes autosuggest prefer results on land to those in the sea.
|
172
|
-
# This setting is on by default. Use false to disable this setting and receive more suggestions in the sea.
|
173
|
-
result_sea = w3w.autosuggest 'disclose.strain.redefin', 'prefer-land': false, 'n-results': 10
|
174
|
-
result_sea_suggestions = result_sea[:suggestions]
|
175
|
-
|
176
|
-
result_land = w3w.autosuggest 'disclose.strain.redefin', 'prefer-land': true, 'n-results': 10
|
177
|
-
result_land_suggestions = result_land[:suggestions]
|
178
|
-
|
179
|
-
expect(result_sea_suggestions).not_to eq(result_land_suggestions)
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'with clip_to_country' do
|
183
|
-
# @:param string clip-to-country: Restricts autosuggest to only return results inside the
|
184
|
-
# countries specified by comma-separated list of uppercase ISO 3166-1
|
185
|
-
# alpha-2 country codes (for example, to restrict to Belgium and the
|
186
|
-
# UK, use clip_to_country="GB,BE")
|
187
|
-
result = w3w.autosuggest 'disclose.strain.redefin', 'clip-to-country': 'GB,BE'
|
188
|
-
country = result[:suggestions]
|
189
|
-
country.each do |item|
|
190
|
-
item.each do |k, v|
|
191
|
-
if k == 'country'
|
192
|
-
if v == 'GB'
|
193
|
-
expect(v).to eq('GB')
|
194
|
-
else
|
195
|
-
expect(v).to eq('BE')
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'with clip-to-bounding-box' do
|
203
|
-
# @:param clip-to-bounding-box: Restrict autosuggest results to a bounding
|
204
|
-
# box, specified by coordinates.
|
205
|
-
result = w3w.autosuggest 'disclose.strain.redefin', 'clip-to-bounding-box': [51.521, -0.343, 52.6, 2.3324]
|
206
|
-
suggestions = result[:suggestions]
|
207
|
-
expect(suggestions).to include(
|
208
|
-
country: 'GB',
|
209
|
-
nearestPlace: 'Saxmundham, Suffolk',
|
210
|
-
words: 'discloses.strain.reddish',
|
211
|
-
rank: 1,
|
212
|
-
language: 'en'
|
213
|
-
)
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'with clip-to-bounding-box raise BadClipToBoundingBox error with 3 coordinates' do
|
217
|
-
# @:param clip-to-bounding-box: Restrict autosuggest results to a bounding
|
218
|
-
# box, specified by coordinates.
|
219
|
-
expect { w3w.autosuggest 'disclose.strain.redefin', 'clip-to-bounding-box': [51.521, -0.343, 52.6] }
|
220
|
-
.to raise_error described_class::ResponseError
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'with clip-to-bounding-box raise 2nd BadClipToBoundingBox error' do
|
224
|
-
# @:param clip-to-bounding-box: Restrictautosuggest results to a bounding
|
225
|
-
# box, specified by coordinates.
|
226
|
-
expect { w3w.autosuggest 'disclose.strain.redefin', 'clip-to-bounding-box': [51.521, -0.343, 55.521, -5.343] }
|
227
|
-
.to raise_error described_class::ResponseError
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'with clip-to-circle' do
|
231
|
-
# @:param clip-to-circle: Restrict autosuggest results to a circle, specified by
|
232
|
-
# the center of the circle, latitude and longitude, and a distance in
|
233
|
-
# kilometres which represents the radius. For convenience, longitude
|
234
|
-
# is allowed to wrap around 180 degrees. For example 181 is equivalent
|
235
|
-
# to -179.
|
236
|
-
result = w3w.autosuggest 'disclose.strain.redefin', 'clip-to-circle': [51.521, -0.343, 142]
|
237
|
-
suggestions = result[:suggestions]
|
238
|
-
expect(suggestions).to include(
|
239
|
-
country: 'GB',
|
240
|
-
nearestPlace: 'Market Harborough, Leicestershire',
|
241
|
-
words: 'discloses.strain.reduce',
|
242
|
-
rank: 1,
|
243
|
-
language: 'en'
|
244
|
-
)
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'with clip-to-polygon' do
|
248
|
-
# @:param clip-to-polygon: Restrict autosuggest results to a polygon,
|
249
|
-
# specified by a list of coordinates. The polygon
|
250
|
-
# should be closed, i.e. the first element should be repeated as the
|
251
|
-
# last element; also the list should contain at least 4 entries.
|
252
|
-
# The API is currently limited to accepting up to 25 pairs.
|
253
|
-
result = w3w.autosuggest 'disclose.strain.redefin', 'clip-to-polygon': [51.521, -0.343, 52.6, 2.3324, 54.234, 8.343, 51.521, -0.343]
|
254
|
-
suggestions = result[:suggestions]
|
255
|
-
expect(suggestions).to include(
|
256
|
-
country: 'GB',
|
257
|
-
nearestPlace: 'Saxmundham, Suffolk',
|
258
|
-
words: 'discloses.strain.reddish',
|
259
|
-
rank: 1,
|
260
|
-
language: 'en'
|
261
|
-
)
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
describe 'grid_section' do
|
266
|
-
# @:param bounding-box: Bounding box, specified by the northeast and
|
267
|
-
# southwest corner coordinates, for which the grid
|
268
|
-
# should be returned.
|
269
|
-
it 'string input not empty' do
|
270
|
-
result = w3w.grid_section '52.208867,0.117540,52.207988,0.116126'
|
271
|
-
expect(result).not_to be_empty
|
272
|
-
end
|
273
|
-
it 'bad bounding box error if the bbox is greater 4km' do
|
274
|
-
expect { w3w.grid_section '50.0,178,50.01,180.0005' }
|
275
|
-
.to raise_error described_class::ResponseError
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
describe 'available_languages' do
|
280
|
-
it 'gets all available languages' do
|
281
|
-
result = w3w.available_languages
|
282
|
-
all_languages = result[:languages].count
|
283
|
-
expect(all_languages).to be >= 51
|
284
|
-
end
|
285
|
-
it 'it does not return an empty list' do
|
286
|
-
result = w3w.available_languages
|
287
|
-
expect(result).not_to be_empty
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
describe 'technical' do
|
292
|
-
it '\'s deep_symbolize_keys helper works' do
|
293
|
-
expect(w3w.deep_symbolize_keys('foo' => { 'bar' => true }))
|
294
|
-
.to eq(foo: { bar: true })
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/what3words.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'what3words/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'what3words'
|
9
|
-
spec.version = What3Words::VERSION
|
10
|
-
spec.authors = ['what3words']
|
11
|
-
spec.email = ['development@what3words.com']
|
12
|
-
spec.description = 'A Ruby wrapper fo the what3words API'
|
13
|
-
spec.summary = 'Ruby wrapper for the what3words API'
|
14
|
-
spec.homepage = 'http://rubygems.org/gems/what3words'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0")
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.test_files = spec.files.grep(%r{^spec/})
|
20
|
-
spec.require_paths = ['lib']
|
21
|
-
spec.platform = Gem::Platform::RUBY
|
22
|
-
spec.required_ruby_version = '~> 2.6'
|
23
|
-
|
24
|
-
spec.add_dependency('rest-client', '>= 1.8', '< 3.0')
|
25
|
-
|
26
|
-
spec.add_development_dependency 'bundler', '>= 1.7.9'
|
27
|
-
spec.add_development_dependency 'rake', '~> 11.1'
|
28
|
-
spec.add_development_dependency 'rspec', '~> 3.4'
|
29
|
-
spec.add_development_dependency 'rubocop', '~> 0.48.1'
|
30
|
-
spec.add_development_dependency 'webmock', '~> 3.0'
|
31
|
-
end
|