what3words 2.0.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,115 +1,297 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require "spec_helper"
3
+ require 'spec_helper'
4
4
 
5
- describe What3Words::API, "integration", :integration => true do
5
+ # to run the test type on terminal --> bundle exec rspec
6
6
 
7
+ describe What3Words::API, 'integration', integration: true do
7
8
  before(:all) do
8
9
  WebMock.allow_net_connect!
9
10
  end
10
11
 
11
- let(:api_key) { ENV["W3W_API_KEY"] }
12
+ let(:api_key) { ENV['W3W_API_KEY'] }
13
+ let(:w3w) { described_class.new(key: api_key) }
12
14
 
13
- let(:w3w) { described_class.new(:key => api_key) }
14
-
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
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
19
  end
20
20
 
21
- describe "getting position" do
22
-
23
- it "works with string of 3 words separated by '.'" do
24
- result = w3w.forward "prom.cape.pump"
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'
25
26
  expect(result).to include(
26
- :words => "prom.cape.pump",
27
- :language => "en"
27
+ words: 'prom.cape.pump',
28
+ language: 'en'
28
29
  )
29
- expect(result[:geometry]).to include(
30
- :lat => 51.484463,
31
- :lng => -0.195405
30
+ expect(result[:coordinates]).to include(
31
+ lat: 51.484463,
32
+ lng: -0.195405
32
33
  )
33
34
  end
34
35
 
35
- it "sends lang parameter for 3 words" do
36
- result = w3w.forward ["prom", "cape", "pump"], :lang => "fr"
36
+ it 'sends language parameter for 3 words' do
37
+ result = w3w.convert_to_coordinates 'prom.cape.pump'
37
38
  expect(result).to include(
38
- :words => "concevoir.époque.amasser",
39
- :language => "fr"
39
+ words: 'prom.cape.pump',
40
+ language: 'en'
40
41
  )
41
42
  end
42
43
 
43
- it "checks 3 words format matches standard regex" do
44
- expect { w3w.forward "1.cape.pump" }.
45
- to raise_error described_class::WordError
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
46
47
  end
47
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
48
73
  end
49
74
 
50
- describe "gets 3 words" do
51
- it "from position" do
52
- result = w3w.reverse [29.567041, 106.587875]
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'
53
79
  expect(result).to include(
54
- :words => "disclose.strain.redefined",
55
- :language => "en"
80
+ words: 'disclose.strain.redefined',
81
+ language: 'en'
82
+ )
83
+ expect(result[:coordinates]).to include(
84
+ lat: 29.567041,
85
+ lng: 106.587875
56
86
  )
57
87
  end
58
88
 
59
- it "from position in fr" do
60
- result = w3w.reverse [29.567041, 106.587875], :lang => "fr"
89
+ it 'from position in fr' do
90
+ result = w3w.convert_to_3wa [29.567041, 106.587875], language: 'fr', format: 'json'
61
91
  expect(result).to include(
62
- :words => "courgette.rabotons.infrason",
63
- :language => "fr"
92
+ words: 'courgette.rabotons.infrason',
93
+ language: 'fr'
64
94
  )
65
95
  end
66
-
67
96
  end
68
- describe "autosuggest" do
69
- it "simple addr" do
70
- # result =
71
- w3w.autosuggest "trop.caler.perdre", "fr"
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
72
105
  end
73
106
 
74
- it "with focus" do
75
- # result =
76
- w3w.autosuggest "disclose.strain.redefin", "en", [29.567041, 106.587875]
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)
77
114
  end
78
115
 
79
- it "with clipping radius around focus" do
80
- # result =
81
- w3w.autosuggest "disclose.strain.redefin", "en", [29.567041, 106.587875], "focus(10)"
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
82
128
  end
83
129
 
84
- end
85
- describe "standardblend" do
86
- it "simple addr" do
87
- # result =
88
- w3w.standardblend "trop.caler.perdre", "fr"
130
+ it 'sends arabic language as a different input' do
131
+ result = w3w.autosuggest 'مربية.الصباح.المده', language: 'ar'
132
+ expect(result).not_to be_empty
89
133
  end
90
134
 
91
- it "with focus" do
92
- # result =
93
- w3w.standardblend "disclose.strain.redefin", "en", [29.567041, 106.587875]
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
+ )
94
262
  end
95
263
  end
96
- describe "grid" do
97
- it "string input" do
98
- # result =
99
- w3w.grid "52.208867,0.117540,52.207988,0.116126"
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
100
276
  end
101
277
  end
102
- describe "languages" do
103
- it "gets all languages" do
104
- # result =
105
- w3w.languages
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
106
288
  end
107
289
  end
108
290
 
109
- describe "technical" do
110
- it "'s deep_symbolize_keys helper works" do
111
- expect(w3w.deep_symbolize_keys("foo" => {"bar" => true})).
112
- to eq(:foo => {:bar => true})
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 })
113
295
  end
114
296
  end
115
297
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
- require "bundler/setup"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
2
4
 
3
5
  Bundler.setup
4
6
 
5
- require "webmock/rspec"
7
+ require 'webmock/rspec'
6
8
 
7
- require "what3words"
9
+ require 'what3words'
data/what3words.gemspec CHANGED
@@ -1,27 +1,31 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "what3words/version"
5
+ require 'what3words/version'
6
6
 
7
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.summary = "what3words API wrapper in Ruby"
13
- spec.homepage = "http://rubygems.org/gems/what3words"
14
- spec.license = "MIT"
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'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^spec/})
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
+ spec.platform = Gem::Platform::RUBY
22
+ spec.required_ruby_version = '~> 2.6'
20
23
 
21
- spec.add_dependency "rest-client", "~> 1.8"
24
+ spec.add_dependency('rest-client', '>= 1.8', '< 3.0')
22
25
 
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"
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'
27
31
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: what3words
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 3.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: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2022-06-17 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
19
  version: '1.8'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.8'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -66,21 +72,35 @@ dependencies:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
74
  version: '3.4'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.48.1
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.48.1
69
89
  - !ruby/object:Gem::Dependency
70
90
  name: webmock
71
91
  requirement: !ruby/object:Gem::Requirement
72
92
  requirements:
73
93
  - - "~>"
74
94
  - !ruby/object:Gem::Version
75
- version: '2.0'
95
+ version: '3.0'
76
96
  type: :development
77
97
  prerelease: false
78
98
  version_requirements: !ruby/object:Gem::Requirement
79
99
  requirements:
80
100
  - - "~>"
81
101
  - !ruby/object:Gem::Version
82
- version: '2.0'
83
- description:
102
+ version: '3.0'
103
+ description: A Ruby wrapper fo the what3words API
84
104
  email:
85
105
  - development@what3words.com
86
106
  executables: []
@@ -111,20 +131,19 @@ require_paths:
111
131
  - lib
112
132
  required_ruby_version: !ruby/object:Gem::Requirement
113
133
  requirements:
114
- - - ">="
134
+ - - "~>"
115
135
  - !ruby/object:Gem::Version
116
- version: '0'
136
+ version: '2.6'
117
137
  required_rubygems_version: !ruby/object:Gem::Requirement
118
138
  requirements:
119
139
  - - ">="
120
140
  - !ruby/object:Gem::Version
121
141
  version: '0'
122
142
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.6.10
143
+ rubygems_version: 3.0.3
125
144
  signing_key:
126
145
  specification_version: 4
127
- summary: what3words API wrapper in Ruby
146
+ summary: Ruby wrapper for the what3words API
128
147
  test_files:
129
148
  - spec/config.sample.yaml
130
149
  - spec/lib/what3words/what3words_api_spec.rb