what3words 2.0.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 071822e06272c4806cc6493be469b6bf4e03224f
4
- data.tar.gz: 73bd8cb619a5afc0828b1dd2eec47cf29c031f71
3
+ metadata.gz: b8bb59aca6fc868de0c381fdc1985b8f3e8650fe
4
+ data.tar.gz: c307fad087e52b9ff5c0db79a76e6e6bccb62ee8
5
5
  SHA512:
6
- metadata.gz: 2fb0661e08c8e627deb26db2653b881dd5214eb5102b613ba7545ca2c45a45d150516c5e2f772182c5c5c85cf06362b7633713ca7402bcf586359d1abef9ae17
7
- data.tar.gz: d5b964fdc28f5080ea62e421d4eaec85d4fd5c367cacb6ad1b30f2155ed379cea4a7ef5633fa83048fadf1d76da5169a8c3bad2b48f54e34940a60dad00ce334
6
+ metadata.gz: 213c3045d96f526edd78a59b0edc82cbbaab3a5f8f6549d21d9436c8b8d311dc416f567a91dbc71f42dd69118ca3bf76bf46b56a9e0f86eda407e4800f7c52f6
7
+ data.tar.gz: 20b182fadf5e36dde86988a48c81eaec52b1fc1dba6e06bb521c637e40e3882479460f3ba3843f45edf0a87ccf09c1cf2c73fb03975dd24b18be0e8b50a36e65
data/README.md CHANGED
@@ -84,7 +84,37 @@ Gets suggestions in italian for this address
84
84
  what3words.autosuggest "trovò.calore.perder", "it"
85
85
  # => {:suggestions=>[{:score=>12, :country=>"ma", :words=>"trovò.calore.perdere", :rank=>1, :geometry=>{:lng=>-6.665638, :lat=>34.318065}, :place=>"Kenitra, Gharb-Chrarda-Beni Hssen"}, {:score=>12, :country=>"ca", :words=>"trovò.calore.perderò", :rank=>2, :geometry=>{:lng=>-65.036149, :lat=>45.846472}, :place=>"Salisbury, New Brunswick"}, {:score=>17, :country=>"ve", :words=>"trovò.calore.prede", :rank=>3, :geometry=>{:lng=>-70.280645, :lat=>7.24527}, :place=>"Guasdualito, Apure"}], :status=>{:status=>200, :reason=>"OK"}, :thanks=>"Thanks from all of us at index.home.raft for using a what3words API"}
86
86
 
87
- Supported keyword params for `reverse` call:
87
+ Supported keyword params for `autosuggest` call:
88
+ * `format` Return data format type; can be one of json (the default), geojson or xml
89
+ * `display` Return display type; can be one of full (the default) or terse
90
+
91
+ ### Standardblend
92
+ 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.
93
+
94
+ 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.
95
+
96
+ see https://docs.what3words.com/api/v2/#standardblend for detailed information
97
+
98
+ Gets blends in italian for this address
99
+
100
+ what3words.standardblend "trovò.calore.perder", "it"
101
+ # => {: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"}
102
+
103
+ Supported keyword params for `standardblend` call:
104
+ * `format` Return data format type; can be one of json (the default), geojson or xml
105
+ * `display` Return display type; can be one of full (the default) or terse
106
+
107
+ ### Grid
108
+ Returns a section of the 3m x 3m what3words grid for a given area.
109
+
110
+ see https://docs.what3words.com/api/v2/#grid for detailed information
111
+
112
+ Gets blends in italian for this address
113
+
114
+ what3words.grid "52.208867,0.117540,52.207988,0.116126"
115
+ # => {: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"}
116
+
117
+ Supported keyword params for `grid` call:
88
118
  * `format` Return data format type; can be one of json (the default), geojson or xml
89
119
  * `display` Return display type; can be one of full (the default) or terse
90
120
 
@@ -18,7 +18,9 @@ module What3Words
18
18
  :forward => "forward",
19
19
  :reverse => "reverse",
20
20
  :languages => "languages",
21
- :autosuggest => "autosuggest"
21
+ :autosuggest => "autosuggest",
22
+ :standardblend => "standardblend",
23
+ :grid => "grid"
22
24
  }
23
25
 
24
26
  def initialize(params)
@@ -40,6 +42,12 @@ module What3Words
40
42
  response
41
43
  end
42
44
 
45
+ def grid(bbox, params = {})
46
+ request_params = assemble_grid_request_params(bbox, params)
47
+ response = request! :grid, request_params
48
+ response
49
+ end
50
+
43
51
  def languages()
44
52
  request_params = assemble_common_request_params({})
45
53
  response = request! :languages, request_params
@@ -52,6 +60,12 @@ module What3Words
52
60
  response
53
61
  end
54
62
 
63
+ def standardblend(addr, lang, focus = {}, params = {})
64
+ request_params = assemble_standardblend_request_params(addr, lang, focus, params)
65
+ response = request! :standardblend, request_params
66
+ response
67
+ end
68
+
55
69
  def assemble_common_request_params(params)
56
70
  h = {:key => key}
57
71
  h[:lang] = params[:lang] if params[:lang]
@@ -67,6 +81,12 @@ module What3Words
67
81
  end
68
82
  private :assemble_forward_request_params
69
83
 
84
+ def assemble_grid_request_params(bbox, params)
85
+ h = {:bbox => bbox}
86
+ h.merge(assemble_common_request_params(params))
87
+ end
88
+ private :assemble_grid_request_params
89
+
70
90
  def assemble_reverse_request_params(position, params)
71
91
  h = {:coords => position.join(",")}
72
92
  h.merge(assemble_common_request_params(params))
@@ -84,6 +104,16 @@ module What3Words
84
104
  end
85
105
  private :assemble_autosuggest_request_params
86
106
 
107
+ def assemble_standardblend_request_params(addr, lang, focus, params)
108
+ h = {:addr => addr}
109
+ h[:lang] = lang
110
+ if focus.respond_to? :join
111
+ h[:focus] = focus.join(",")
112
+ end
113
+ h.merge(assemble_common_request_params(params))
114
+ end
115
+ private :assemble_standardblend_request_params
116
+
87
117
  def request!(endpoint_name, params)
88
118
  # puts endpoint_name.inspect
89
119
  # puts params.inspect
@@ -1,3 +1,3 @@
1
1
  module What3Words
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -36,8 +36,8 @@ describe What3Words::API, "integration", :integration => true do
36
36
  :language => "en"
37
37
  )
38
38
  expect(result[:geometry]).to include(
39
- :lat => "51.484463",
40
- :lng => "-0.195405"
39
+ :lat => 51.484463,
40
+ :lng => -0.195405
41
41
  )
42
42
  end
43
43
 
@@ -88,12 +88,23 @@ describe What3Words::API, "integration", :integration => true do
88
88
  end
89
89
 
90
90
  end
91
+ describe "standardblend" do
92
+ it "simple addr" do
93
+ result = w3w.standardblend "trop.caler.perdre", "fr"
94
+ end
95
+
96
+ it "with focus" do
97
+ result = w3w.standardblend "disclose.strain.redefin", "en", [29.567041, 106.587875]
98
+ end
99
+ end
100
+ describe "grid" do
101
+ it "string input" do
102
+ result = w3w.grid "52.208867,0.117540,52.207988,0.116126"
103
+ end
104
+ end
91
105
  describe "languages" do
92
106
  it "gets all languages" do
93
107
  result = w3w.languages
94
- # expect(result[:languages]).to include(
95
- # :code => "fr"
96
- # )
97
108
  end
98
109
  end
99
110
 
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.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - what3words
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-10 00:00:00.000000000 Z
11
+ date: 2016-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -98,7 +98,6 @@ files:
98
98
  - lib/what3words/version.rb
99
99
  - spec/config.sample.yaml
100
100
  - spec/lib/what3words/what3words_api_spec.rb
101
- - spec/mock/api_spec.rb
102
101
  - spec/spec_helper.rb
103
102
  - what3words.gemspec
104
103
  homepage: http://rubygems.org/gems/what3words
@@ -128,5 +127,4 @@ summary: what3words API wrapper in Ruby
128
127
  test_files:
129
128
  - spec/config.sample.yaml
130
129
  - spec/lib/what3words/what3words_api_spec.rb
131
- - spec/mock/api_spec.rb
132
130
  - spec/spec_helper.rb
@@ -1,120 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe What3Words::API do
6
-
7
- before(:all) do
8
- WebMock.disable_net_connect!
9
- end
10
-
11
- let(:api_key) { "APIkey" }
12
-
13
- let(:w3w) { described_class.new(:key => api_key) }
14
-
15
- # it "returns errors from API" do
16
- # stub_request(:get, "https://api.what3words.com/v2/forward").
17
- # to_return(:status => 200, :body => '{"code": "300", "message": "Invalid or non-existent 3 word address"}')
18
- #
19
- # expect { w3w.forward "a.b.c" }.
20
- # to raise_error described_class::ResponseError
21
- # end
22
-
23
- describe "getting position" do
24
-
25
- # def stub!(query_params, response_body = {})
26
- # stub_request(:get, "https://api.what3words.com/v2/forward").
27
- # with(:query => query_params).
28
- # to_return(:status => 200, :body => response_body.to_json)
29
- # end
30
-
31
- # it "sends 3 words given as string" do
32
- # # stub_request(:get, "https://api.what3words.com/v2/forward?addr=a.b.c&key=APIkey").
33
- # # with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
34
- # # to_return(:status => 200, :body => '{"words" :"a.b.c"}', :headers => {})
35
- # stub_request(:get, "https://api.what3words.com/v2/forward" ).
36
- # # with(query: hash_including({"addr" => "a.b.c"}, {"key" => :api_key})).
37
- # with(query: hash_including(:add => "abc", :key => :api_key)).
38
- # to_return(:status => 200, :body => '{"words" :"a.b.c"}')
39
- # # stub! hash_including(:addr => "a.b.c")
40
- # result = w3w.forward "a.b.c"
41
- # puts result
42
- # end
43
-
44
- # it "extracts position from response" do
45
- # stub!(hash_including(:addr => "prom.cape.pump"), {"position" => [1, 2]})
46
- # result = w3w.forward "prom.cape.pump"
47
- # expect(result).to eq [1, 2]
48
- # end
49
-
50
- # it "returns full response instead of just coords" do
51
- # stub!(hash_including(:addr => "prom.cape.pump"),
52
- # {"thanks" => "Thanks from all of us at index.home.raft for using a what3words API"})
53
- # result = w3w.forward "prom.cape.pump", :full_response => true
54
- # expect(result).to eq :thanks => "Thanks from all of us at index.home.raft for using a what3words API"
55
- # end
56
-
57
- # it "sends lang option" do
58
- # stub!(hash_including(:addr => "prom.cape.pump", :lang => "fr"))
59
- # w3w.forward "prom.cape.pump", :language => "fr"
60
- # end
61
-
62
- # it "parses response errors" do
63
- # stub! hash_including(:addr => "prom.cape.pump"), {:error => "xx", :message => "msg"}
64
- # expect { w3w.forward "prom.cape.pump" }.
65
- # to raise_error described_class::ResponseError, "xx: msg"
66
- # end
67
-
68
- # it "checks 3 words as string matches standard regex" do
69
- # stub! anything
70
- # expect { w3w.words_to_position "1.cape.pump" }.
71
- # to raise_error described_class::WordError
72
- # end
73
-
74
- end
75
-
76
- # describe "gets 3 words" do
77
- #
78
- # def stub!(request_body, response_body = {})
79
- # stub_request(:get, "https://api.what3words.com/v2/reverse").
80
- # with(:body => request_body).
81
- # to_return(:status => 200, :body => response_body.to_json)
82
- # end
83
- #
84
- # it "extracts 3 words from response" do
85
- # stub! hash_including(:position => "1,2"), {:words => "prom.cape.pump"}
86
- # expect(w3w.reverse([1, 2])).to eq "prom.cape.pump"
87
- # end
88
- #
89
- # it "sends lang option" do
90
- # stub!(hash_including(:position => "1,2", :lang => "fr"))
91
- # w3w.position_to_words([1, 2], :language => "fr")
92
- # end
93
- #
94
- # end
95
- #
96
- # describe "getting available languages" do
97
- #
98
- # def stub!(request_body, response_body = {})
99
- # stub_request(:get, "http://api.what3words.com/get-languages").
100
- # with(:body => request_body).
101
- # to_return(:status => 200, :body => response_body.to_json)
102
- # end
103
- #
104
- # it "gets list of codes" do
105
- # stub! anything, {:languages => [{:code => "l1"}, {:code => "l2"}]}
106
- # expect(w3w.languages). to eq ["l1", "l2"]
107
- # end
108
- #
109
- # it "gets full response" do
110
- # stub! anything, {:languages => [{:code => "l1"}, {:code => "l2"}]}
111
- # expect(w3w.languages :full_response => true).
112
- # to eq(:languages => [{:code => "l1"}, {:code => "l2"}])
113
- # end
114
- # end
115
-
116
- it "'s deep_symbolize_keys helper works" do
117
- expect(w3w.deep_symbolize_keys("foo" => {"bar" => 1, "baz" => [{"quux" => "www"}]})).
118
- to eq(:foo => {:bar => 1, :baz => [{:quux => "www"}]})
119
- end
120
- end