geokit_here_geocoder 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/geokit_here_geocoder.gemspec +1 -1
- data/lib/geokit_here_geocoder.rb +50 -18
- data/spec/cassettes/{fake_location.yml → geocode_fake_location.yml} +18 -18
- data/spec/cassettes/{permission_denied.yml → geocode_permission_denied.yml} +15 -15
- data/spec/cassettes/{sunnyvale_location.yml → geocode_sunnyvale_location.yml} +19 -19
- data/spec/cassettes/reverse_geocode_fake_location.yml +46 -0
- data/spec/cassettes/reverse_geocode_permission_denied.yml +45 -0
- data/spec/cassettes/reverse_geocode_richmond_location.yml +55 -0
- data/spec/geokit_here_geocoder_spec.rb +122 -37
- metadata +15 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 889adc09d233eca49d7c162ed78748e1a5bad09f9ca53e711b4e1d3c6d5451e2
|
4
|
+
data.tar.gz: 3da09d69053fca0b88ef29db82c541c94628be0bdc408e3cc2cf39f4c345ed41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f3fe90b615c7f9d7e122f02b5b3fbfd040596a1333b89b4f00d1565c19f96122c60737b2594fe0aac91adbb4e9a6ec591ab4de4a051704a8733112239fc7ea4
|
7
|
+
data.tar.gz: '059e31caeed8e9b01b0f4fbe78ce96f606b0befa63e055b2b008bc0336f9204d89ac777035aaf27def0a9a537d9fba12b4dc53daad5bb68015fff0a73ec62b7f'
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "geokit_here_geocoder"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.6"
|
8
8
|
spec.authors = ["Serhiy Rozum"]
|
9
9
|
spec.email = ["contact@easypost.com"]
|
10
10
|
spec.summary = %q{Geokit custom geocoder for Here.com service}
|
data/lib/geokit_here_geocoder.rb
CHANGED
@@ -5,20 +5,33 @@ module Geokit
|
|
5
5
|
module Geocoders
|
6
6
|
class HereGeocoder < Geocoder
|
7
7
|
|
8
|
+
PROX = 250 # proximity 250 meters
|
9
|
+
|
10
|
+
XML_MAPPINGS = {
|
11
|
+
street_number: "Location/Address/HouseNumber",
|
12
|
+
street_name: "Location/Address/Street",
|
13
|
+
city: "Location/Address/City",
|
14
|
+
state_name: "Location/Address/AdditionalData[@key='StateName']",
|
15
|
+
state_code: "Location/Address/State",
|
16
|
+
zip: "Location/Address/PostalCode",
|
17
|
+
country_code: "Location/Address/AdditionalData[@key='Country2']",
|
18
|
+
country: "Location/Address/AdditionalData[@key='CountryName']",
|
19
|
+
lat: "Location/DisplayPosition/Latitude",
|
20
|
+
lng: "Location/DisplayPosition/Longitude",
|
21
|
+
}
|
22
|
+
|
8
23
|
config :app_id, :app_code
|
9
24
|
|
10
25
|
private
|
11
26
|
|
12
27
|
def self.do_geocode(address, options = {})
|
13
|
-
|
14
28
|
if (app_id.nil? || app_id.empty?) || (app_code.nil? || app_code.empty?)
|
15
29
|
raise(Geokit::Geocoders::GeocodeError, "Here geocoder API requires auth id and code to use their service.")
|
16
30
|
end
|
17
|
-
|
18
|
-
process :xml, submit_url(address)
|
31
|
+
process :xml, geocode_url(address)
|
19
32
|
end
|
20
33
|
|
21
|
-
def self.
|
34
|
+
def self.geocode_url(address)
|
22
35
|
args = []
|
23
36
|
args << ["app_id", app_id]
|
24
37
|
args << ["app_code", app_code]
|
@@ -30,10 +43,10 @@ module Geokit
|
|
30
43
|
|
31
44
|
args << ["searchtext", address_str]
|
32
45
|
|
33
|
-
[
|
46
|
+
[geocode_endpoint, '?', URI.encode_www_form(args)].join('')
|
34
47
|
end
|
35
48
|
|
36
|
-
def self.
|
49
|
+
def self.geocode_endpoint
|
37
50
|
if ENV['RAKE_ENV'] == 'test'
|
38
51
|
"https://geocoder.cit.api.here.com/6.2/geocode.xml"
|
39
52
|
else
|
@@ -41,18 +54,37 @@ module Geokit
|
|
41
54
|
end
|
42
55
|
end
|
43
56
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
def self.do_reverse_geocode(latlng, options = {})
|
58
|
+
if (app_id.nil? || app_id.empty?) || (app_code.nil? || app_code.empty?)
|
59
|
+
raise(Geokit::Geocoders::GeocodeError, "Here geocoder API requires auth id and code to use their service.")
|
60
|
+
end
|
61
|
+
process :xml, reverse_geocode_url(latlng)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.reverse_geocode_url(latlng)
|
65
|
+
args = []
|
66
|
+
args << ["app_id", app_id]
|
67
|
+
args << ["app_code", app_code]
|
68
|
+
args << ["additionaldata", "Country2,1"]
|
69
|
+
args << ["language", "en-US"]
|
70
|
+
args << ["gen", "9"]
|
71
|
+
args << ["maxresults", 1]
|
72
|
+
args << ["mode", "retrieveAddresses"]
|
73
|
+
|
74
|
+
latlng = LatLng.normalize(latlng)
|
75
|
+
|
76
|
+
args << ["prox", "#{latlng.lat},#{latlng.lng},#{PROX}"]
|
77
|
+
|
78
|
+
[reverse_geocode_endpoint, '?', URI.encode_www_form(args)].join('')
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.reverse_geocode_endpoint
|
82
|
+
if ENV['RAKE_ENV'] == 'test'
|
83
|
+
"https://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.xml"
|
84
|
+
else
|
85
|
+
"https://reverse.geocoder.api.here.com/6.2/reversegeocode.xml"
|
86
|
+
end
|
87
|
+
end
|
56
88
|
|
57
89
|
def self.parse_xml(xml)
|
58
90
|
results = xml.elements.to_a("//Result")
|
@@ -18,31 +18,31 @@ http_interactions:
|
|
18
18
|
code: 200
|
19
19
|
message: OK
|
20
20
|
headers:
|
21
|
-
|
22
|
-
-
|
23
|
-
Cache-Control:
|
24
|
-
- public, max-age=86400
|
21
|
+
Date:
|
22
|
+
- Mon, 11 Nov 2019 22:03:24 GMT
|
25
23
|
Content-Type:
|
26
24
|
- application/xml;charset=utf-8
|
27
|
-
|
28
|
-
-
|
25
|
+
Content-Length:
|
26
|
+
- '182'
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
29
|
Server:
|
30
30
|
- nginx-clojure
|
31
|
-
|
32
|
-
-
|
31
|
+
Cache-Control:
|
32
|
+
- public, max-age=86400
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
X-Served-By:
|
36
|
+
- i-09a2ce08fa1f4510d.us-west-2b
|
33
37
|
X-Nlp-Log:
|
34
38
|
- Z2NfYz0tIGdjX2w9LSBnY19tPWFk
|
35
39
|
X-Nlp-Tid:
|
36
|
-
-
|
37
|
-
X-
|
38
|
-
-
|
39
|
-
Content-Length:
|
40
|
-
- '185'
|
41
|
-
Connection:
|
42
|
-
- keep-alive
|
40
|
+
- 31f95ed6-7884-4e46-86b8-31a10c266ea2
|
41
|
+
X-Nlp-Irt:
|
42
|
+
- '734'
|
43
43
|
body:
|
44
44
|
encoding: ASCII-8BIT
|
45
|
-
string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:Search xmlns:ns2="http://www.navteq.com/lbsp/Search-Search/4"><Response><MetaInfo><Timestamp>
|
45
|
+
string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:Search xmlns:ns2="http://www.navteq.com/lbsp/Search-Search/4"><Response><MetaInfo><Timestamp>2019-11-11T21:59:15.580Z</Timestamp></MetaInfo></Response></ns2:Search>
|
46
46
|
http_version:
|
47
|
-
recorded_at:
|
48
|
-
recorded_with: VCR
|
47
|
+
recorded_at: Mon, 11 Nov 2019 22:03:24 GMT
|
48
|
+
recorded_with: VCR 5.0.0
|
@@ -18,30 +18,30 @@ http_interactions:
|
|
18
18
|
code: 401
|
19
19
|
message: Unauthorized
|
20
20
|
headers:
|
21
|
-
|
22
|
-
-
|
21
|
+
Date:
|
22
|
+
- Mon, 11 Nov 2019 22:03:24 GMT
|
23
23
|
Content-Type:
|
24
24
|
- application/xml;charset=utf-8
|
25
|
-
|
26
|
-
-
|
25
|
+
Content-Length:
|
26
|
+
- '170'
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
27
29
|
Server:
|
28
30
|
- nginx-clojure
|
29
|
-
|
30
|
-
-
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
X-Served-By:
|
34
|
+
- i-09a2ce08fa1f4510d.us-west-2b
|
31
35
|
X-Nlp-Log:
|
32
36
|
- ''
|
33
37
|
X-Nlp-Tid:
|
34
|
-
-
|
35
|
-
X-
|
36
|
-
-
|
37
|
-
Content-Length:
|
38
|
-
- '170'
|
39
|
-
Connection:
|
40
|
-
- keep-alive
|
38
|
+
- 2cbaf860-4741-4a7a-af9b-79a78c57d6bc
|
39
|
+
X-Nlp-Irt:
|
40
|
+
- '603'
|
41
41
|
body:
|
42
42
|
encoding: UTF-8
|
43
43
|
string: <ns2:Error xmlns:ns2="http://www.navteq.com/lbsp/Errors/1" type="PermissionError"
|
44
44
|
subtype="InvalidCredentials"><Details>invalid credentials for test</Details></ns2:Error>
|
45
45
|
http_version:
|
46
|
-
recorded_at:
|
47
|
-
recorded_with: VCR
|
46
|
+
recorded_at: Mon, 11 Nov 2019 22:03:24 GMT
|
47
|
+
recorded_with: VCR 5.0.0
|
@@ -18,37 +18,37 @@ http_interactions:
|
|
18
18
|
code: 200
|
19
19
|
message: OK
|
20
20
|
headers:
|
21
|
-
|
22
|
-
-
|
23
|
-
Cache-Control:
|
24
|
-
- public, max-age=86400
|
21
|
+
Date:
|
22
|
+
- Mon, 11 Nov 2019 22:03:24 GMT
|
25
23
|
Content-Type:
|
26
24
|
- application/xml;charset=utf-8
|
27
|
-
|
28
|
-
-
|
25
|
+
Content-Length:
|
26
|
+
- '626'
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
29
|
Server:
|
30
30
|
- nginx-clojure
|
31
|
-
|
32
|
-
-
|
31
|
+
Cache-Control:
|
32
|
+
- public, max-age=86400
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
X-Served-By:
|
36
|
+
- i-09a2ce08fa1f4510d.us-west-2b
|
33
37
|
X-Nlp-Log:
|
34
38
|
- Z2NfYz1VU0EgZ2NfbD1jaXR5IGdjX209YXI=
|
35
39
|
X-Nlp-Tid:
|
36
|
-
-
|
37
|
-
X-
|
38
|
-
-
|
39
|
-
Content-Length:
|
40
|
-
- '626'
|
41
|
-
Connection:
|
42
|
-
- keep-alive
|
40
|
+
- 24f2b4d6-8794-4a58-9f02-49a7221446e4
|
41
|
+
X-Nlp-Irt:
|
42
|
+
- '843'
|
43
43
|
body:
|
44
44
|
encoding: ASCII-8BIT
|
45
|
-
string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:Search xmlns:ns2="http://www.navteq.com/lbsp/Search-Search/4"><Response><MetaInfo><Timestamp>
|
46
|
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:SearchResultsViewType"><ViewId>0</ViewId><Result><Relevance>1.0</Relevance><MatchLevel>city</MatchLevel><MatchQuality><State>1.0</State><City>1.0</City></MatchQuality><Location><LocationId>NT_FE3T7HawlbK76SxDmyKlUA</LocationId><LocationType>area</LocationType><DisplayPosition><Latitude>37.37172</Latitude><Longitude>-122.03801</Longitude></DisplayPosition><NavigationPosition><Latitude>37.37172</Latitude><Longitude>-122.03801</Longitude></NavigationPosition><MapView><TopLeft><Latitude>37.45103</Latitude><Longitude>-122.06566</Longitude></TopLeft><BottomRight><Latitude>37.
|
45
|
+
string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:Search xmlns:ns2="http://www.navteq.com/lbsp/Search-Search/4"><Response><MetaInfo><Timestamp>2019-11-11T21:59:15.406Z</Timestamp></MetaInfo><View
|
46
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:SearchResultsViewType"><ViewId>0</ViewId><Result><Relevance>1.0</Relevance><MatchLevel>city</MatchLevel><MatchQuality><State>1.0</State><City>1.0</City></MatchQuality><Location><LocationId>NT_FE3T7HawlbK76SxDmyKlUA</LocationId><LocationType>area</LocationType><DisplayPosition><Latitude>37.37172</Latitude><Longitude>-122.03801</Longitude></DisplayPosition><NavigationPosition><Latitude>37.37172</Latitude><Longitude>-122.03801</Longitude></NavigationPosition><MapView><TopLeft><Latitude>37.45103</Latitude><Longitude>-122.06566</Longitude></TopLeft><BottomRight><Latitude>37.33227</Latitude><Longitude>-121.98241</Longitude></BottomRight></MapView><Address><Label>Sunnyvale,
|
47
47
|
CA, United States</Label><Country>USA</Country><State>CA</State><County>Santa
|
48
48
|
Clara</County><City>Sunnyvale</City><PostalCode>94086</PostalCode><AdditionalData
|
49
49
|
key="Country2">US</AdditionalData><AdditionalData key="CountryName">United
|
50
50
|
States</AdditionalData><AdditionalData key="StateName">California</AdditionalData><AdditionalData
|
51
51
|
key="CountyName">Santa Clara</AdditionalData><AdditionalData key="PostalCodeType">N</AdditionalData></Address></Location></Result></View></Response></ns2:Search>
|
52
52
|
http_version:
|
53
|
-
recorded_at:
|
54
|
-
recorded_with: VCR
|
53
|
+
recorded_at: Mon, 11 Nov 2019 22:03:24 GMT
|
54
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.xml?additionaldata=Country2,1&app_code=<HERE_APP_CODE>&app_id=<HERE_APP_ID>&gen=9&language=en-US&maxresults=1&mode=retrieveAddresses&prox=37.7692014,-122.7737106,250
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Mon, 11 Nov 2019 22:03:25 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/xml;charset=utf-8
|
25
|
+
Content-Length:
|
26
|
+
- '224'
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Server:
|
30
|
+
- nginx-clojure
|
31
|
+
Cache-Control:
|
32
|
+
- public, max-age=86400
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
X-Served-By:
|
36
|
+
- i-0febd699fbbdcf495.us-west-2b
|
37
|
+
X-Nlp-Tid:
|
38
|
+
- c33e88aa-254f-4bc0-b262-152cab69100c
|
39
|
+
X-Nlp-Irt:
|
40
|
+
- '1629'
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:Search xmlns:ns2="http://www.navteq.com/lbsp/Search-Search/4"><Response><MetaInfo><Timestamp>2019-11-11T22:03:25.046Z</Timestamp></MetaInfo></Response></ns2:Search>
|
44
|
+
http_version:
|
45
|
+
recorded_at: Mon, 11 Nov 2019 22:03:25 GMT
|
46
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.xml?additionaldata=Country2,1&app_code=fake&app_id=test&gen=9&language=en-US&maxresults=1&mode=retrieveAddresses&prox=37.93053,-122.34358,250
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 401
|
19
|
+
message: Unauthorized
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Mon, 11 Nov 2019 22:03:24 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/xml;charset=utf-8
|
25
|
+
Content-Length:
|
26
|
+
- '170'
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Server:
|
30
|
+
- nginx-clojure
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
X-Served-By:
|
34
|
+
- i-0febd699fbbdcf495.us-west-2b
|
35
|
+
X-Nlp-Tid:
|
36
|
+
- 61641ef6-5f06-48ee-a285-ff7dfe8e0215
|
37
|
+
X-Nlp-Irt:
|
38
|
+
- '962'
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: <ns2:Error xmlns:ns2="http://www.navteq.com/lbsp/Errors/1" type="PermissionError"
|
42
|
+
subtype="InvalidCredentials"><Details>invalid credentials for test</Details></ns2:Error>
|
43
|
+
http_version:
|
44
|
+
recorded_at: Mon, 11 Nov 2019 22:03:24 GMT
|
45
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.xml?additionaldata=Country2,1&app_code=<HERE_APP_CODE>&app_id=<HERE_APP_ID>&gen=9&language=en-US&maxresults=1&mode=retrieveAddresses&prox=37.93053,-122.34358,250
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Mon, 11 Nov 2019 22:03:24 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/xml;charset=utf-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Server:
|
30
|
+
- nginx-clojure
|
31
|
+
Cache-Control:
|
32
|
+
- public, max-age=86400
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
X-Served-By:
|
36
|
+
- i-0febd699fbbdcf495.us-west-2b
|
37
|
+
X-Nlp-Tid:
|
38
|
+
- 6d2e46a2-7d90-4156-aab1-8c595e4b23f4
|
39
|
+
Vary:
|
40
|
+
- Accept-Encoding
|
41
|
+
X-Nlp-Irt:
|
42
|
+
- '4558'
|
43
|
+
body:
|
44
|
+
encoding: ASCII-8BIT
|
45
|
+
string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:Search xmlns:ns2="http://www.navteq.com/lbsp/Search-Search/4"><Response><MetaInfo><Timestamp>2019-11-11T22:03:24.849Z</Timestamp><NextPageInformation>2</NextPageInformation></MetaInfo><View
|
46
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:SearchResultsViewType"><ViewId>0</ViewId><Result><Relevance>1.0</Relevance><Distance>3.5</Distance><MatchLevel>houseNumber</MatchLevel><MatchQuality><Country>1.0</Country><State>1.0</State><County>1.0</County><City>1.0</City><District>1.0</District><Street>1.0</Street><HouseNumber>1.0</HouseNumber><PostalCode>1.0</PostalCode></MatchQuality><MatchType>interpolated</MatchType><Location><LocationId>NT_O1ECr0RHU.ggJtLGox-33A_l_23635076_R_xEDO</LocationId><LocationType>address</LocationType><DisplayPosition><Latitude>37.9305301</Latitude><Longitude>-122.3434851</Longitude></DisplayPosition><NavigationPosition><Latitude>37.9305301</Latitude><Longitude>-122.34362</Longitude></NavigationPosition><MapView><TopLeft><Latitude>37.9316542</Latitude><Longitude>-122.3449103</Longitude></TopLeft><BottomRight><Latitude>37.9294059</Latitude><Longitude>-122.3420599</Longitude></BottomRight></MapView><Address><Label>118
|
47
|
+
S 27th St, Richmond, CA 94804, United States</Label><Country>USA</Country><State>CA</State><County>Contra
|
48
|
+
Costa</County><City>Richmond</City><District>Pullman</District><Street>S 27th
|
49
|
+
St</Street><HouseNumber>118</HouseNumber><PostalCode>94804</PostalCode><AdditionalData
|
50
|
+
key="Country2">US</AdditionalData><AdditionalData key="CountryName">United
|
51
|
+
States</AdditionalData><AdditionalData key="StateName">California</AdditionalData><AdditionalData
|
52
|
+
key="CountyName">Contra Costa</AdditionalData><AdditionalData key="PostalCodeType">N</AdditionalData></Address><MapReference><ReferenceId>23635076</ReferenceId><MapId>NAAM19134</MapId><MapVersion>Q1/2019</MapVersion><MapReleaseDate>2019-10-25</MapReleaseDate><Spot>0.49</Spot><SideOfStreet>right</SideOfStreet><CountryId>21000001</CountryId><StateId>21009408</StateId><CountyId>21009456</CountyId><CityId>21009489</CityId></MapReference></Location></Result></View></Response></ns2:Search>
|
53
|
+
http_version:
|
54
|
+
recorded_at: Mon, 11 Nov 2019 22:03:24 GMT
|
55
|
+
recorded_with: VCR 5.0.0
|
@@ -2,68 +2,153 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Geokit::Geocoders::HereGeocoder do
|
4
4
|
|
5
|
-
|
5
|
+
context "Geocode address" do
|
6
6
|
|
7
|
-
|
7
|
+
let(:address) { "Sunnyvale, CA" }
|
8
8
|
|
9
|
-
|
9
|
+
subject { described_class.geocode(address) }
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
context "when missing credentials" do
|
12
|
+
|
13
|
+
before do
|
14
|
+
Geokit::Geocoders::HereGeocoder.app_id = nil
|
15
|
+
Geokit::Geocoders::HereGeocoder.app_code = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'raises an error' do
|
19
|
+
expect { subject }.to raise_error Geokit::Geocoders::GeocodeError
|
20
|
+
end
|
13
21
|
end
|
14
|
-
end
|
15
22
|
|
16
|
-
|
23
|
+
context "with invalid credentials" do
|
24
|
+
|
25
|
+
before do
|
26
|
+
Geokit::Geocoders::HereGeocoder.app_id = "test"
|
27
|
+
Geokit::Geocoders::HereGeocoder.app_code = "fake"
|
28
|
+
end
|
17
29
|
|
18
|
-
|
19
|
-
|
20
|
-
|
30
|
+
it 'returns invalid location' do
|
31
|
+
VCR.use_cassette("geocode_permission_denied") do
|
32
|
+
expect( subject.success? ).to be false
|
33
|
+
end
|
34
|
+
end
|
21
35
|
end
|
22
36
|
|
23
|
-
|
24
|
-
|
25
|
-
|
37
|
+
context "with correct credentials" do
|
38
|
+
|
39
|
+
before do
|
40
|
+
Geokit::Geocoders::HereGeocoder.app_id = ENV['HERE_APP_ID']
|
41
|
+
Geokit::Geocoders::HereGeocoder.app_code = ENV['HERE_APP_CODE']
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'not raises an error' do
|
45
|
+
VCR.use_cassette("geocode_sunnyvale_location") do
|
46
|
+
expect { subject }.not_to raise_error
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns valid location' do
|
51
|
+
VCR.use_cassette("geocode_sunnyvale_location") do
|
52
|
+
expect( subject.success? ).to be true
|
53
|
+
expect( subject.city ).to eq "Sunnyvale"
|
54
|
+
expect( subject.state_name ).to eq "California"
|
55
|
+
expect( subject.state_code ).to eq "CA"
|
56
|
+
expect( subject.state ).to eq "CA"
|
57
|
+
expect( subject.zip ).to eq "94086"
|
58
|
+
expect( subject.country_code ).to eq "US"
|
59
|
+
expect( subject.country ).to eq "United States"
|
60
|
+
expect( subject.lat ).to eq 37.37172
|
61
|
+
expect( subject.lng ).to eq -122.03801
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "fake location" do
|
66
|
+
|
67
|
+
let(:address) { "Abcdefg" }
|
68
|
+
|
69
|
+
it 'returns invalid location' do
|
70
|
+
VCR.use_cassette("geocode_fake_location") do
|
71
|
+
expect( subject.success? ).to be false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
26
75
|
end
|
76
|
+
|
27
77
|
end
|
78
|
+
|
28
79
|
end
|
29
80
|
|
30
|
-
context "
|
81
|
+
context "Reverse geocode location" do
|
31
82
|
|
32
|
-
|
33
|
-
Geokit::Geocoders::HereGeocoder.app_id = ENV['HERE_APP_ID']
|
34
|
-
Geokit::Geocoders::HereGeocoder.app_code = ENV['HERE_APP_CODE']
|
35
|
-
end
|
83
|
+
let(:latlng) { "37.930530, -122.343580" }
|
36
84
|
|
37
|
-
|
38
|
-
|
39
|
-
|
85
|
+
subject { described_class.reverse_geocode(latlng) }
|
86
|
+
|
87
|
+
context "when missing credentials" do
|
88
|
+
|
89
|
+
before do
|
90
|
+
Geokit::Geocoders::HereGeocoder.app_id = nil
|
91
|
+
Geokit::Geocoders::HereGeocoder.app_code = nil
|
40
92
|
end
|
41
|
-
end
|
42
93
|
|
43
|
-
|
44
|
-
|
45
|
-
expect( subject.success? ).to be true
|
46
|
-
expect( subject.city ).to eq "Sunnyvale"
|
47
|
-
expect( subject.state_name ).to eq "California"
|
48
|
-
expect( subject.state_code ).to eq "CA"
|
49
|
-
expect( subject.state ).to eq "CA"
|
50
|
-
expect( subject.zip ).to eq "94086"
|
51
|
-
expect( subject.country_code ).to eq "US"
|
52
|
-
expect( subject.country ).to eq "United States"
|
53
|
-
expect( subject.lat ).to eq 37.37172
|
54
|
-
expect( subject.lng ).to eq -122.03801
|
94
|
+
it 'raises an error' do
|
95
|
+
expect { subject }.to raise_error Geokit::Geocoders::GeocodeError
|
55
96
|
end
|
56
97
|
end
|
57
98
|
|
58
|
-
context "
|
99
|
+
context "with invalid credentials" do
|
59
100
|
|
60
|
-
|
101
|
+
before do
|
102
|
+
Geokit::Geocoders::HereGeocoder.app_id = "test"
|
103
|
+
Geokit::Geocoders::HereGeocoder.app_code = "fake"
|
104
|
+
end
|
61
105
|
|
62
106
|
it 'returns invalid location' do
|
63
|
-
VCR.use_cassette("
|
107
|
+
VCR.use_cassette("reverse_geocode_permission_denied") do
|
64
108
|
expect( subject.success? ).to be false
|
65
109
|
end
|
66
110
|
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "with correct credentials" do
|
114
|
+
|
115
|
+
before do
|
116
|
+
Geokit::Geocoders::HereGeocoder.app_id = ENV['HERE_APP_ID']
|
117
|
+
Geokit::Geocoders::HereGeocoder.app_code = ENV['HERE_APP_CODE']
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'not raises an error' do
|
121
|
+
VCR.use_cassette("reverse_geocode_richmond_location") do
|
122
|
+
expect { subject }.not_to raise_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'returns valid location' do
|
127
|
+
VCR.use_cassette("reverse_geocode_richmond_location") do
|
128
|
+
expect( subject.success? ).to be true
|
129
|
+
expect( subject.city ).to eq "Richmond"
|
130
|
+
expect( subject.state_name ).to eq "California"
|
131
|
+
expect( subject.state_code ).to eq "CA"
|
132
|
+
expect( subject.state ).to eq "CA"
|
133
|
+
expect( subject.zip ).to eq "94804"
|
134
|
+
expect( subject.country_code ).to eq "US"
|
135
|
+
expect( subject.country ).to eq "United States"
|
136
|
+
expect( subject.lat ).to eq 37.9305301
|
137
|
+
expect( subject.lng ).to eq -122.3434851
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "fake location" do
|
142
|
+
|
143
|
+
let(:latlng) { "37.7692014,-122.7737106" }
|
144
|
+
|
145
|
+
it 'returns invalid location' do
|
146
|
+
VCR.use_cassette("reverse_geocode_fake_location") do
|
147
|
+
expect( subject.success? ).to be false
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
67
152
|
|
68
153
|
end
|
69
154
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geokit_here_geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serhiy Rozum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,9 +110,12 @@ files:
|
|
110
110
|
- Rakefile
|
111
111
|
- geokit_here_geocoder.gemspec
|
112
112
|
- lib/geokit_here_geocoder.rb
|
113
|
-
- spec/cassettes/
|
114
|
-
- spec/cassettes/
|
115
|
-
- spec/cassettes/
|
113
|
+
- spec/cassettes/geocode_fake_location.yml
|
114
|
+
- spec/cassettes/geocode_permission_denied.yml
|
115
|
+
- spec/cassettes/geocode_sunnyvale_location.yml
|
116
|
+
- spec/cassettes/reverse_geocode_fake_location.yml
|
117
|
+
- spec/cassettes/reverse_geocode_permission_denied.yml
|
118
|
+
- spec/cassettes/reverse_geocode_richmond_location.yml
|
116
119
|
- spec/geokit_here_geocoder_spec.rb
|
117
120
|
- spec/spec_helper.rb
|
118
121
|
homepage: https://github.com/easypost/geokit_here_geocoder.git
|
@@ -134,14 +137,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
137
|
- !ruby/object:Gem::Version
|
135
138
|
version: '0'
|
136
139
|
requirements: []
|
137
|
-
|
138
|
-
rubygems_version: 2.2.2
|
140
|
+
rubygems_version: 3.0.6
|
139
141
|
signing_key:
|
140
142
|
specification_version: 4
|
141
143
|
summary: Geokit custom geocoder for Here.com service
|
142
144
|
test_files:
|
143
|
-
- spec/cassettes/
|
144
|
-
- spec/cassettes/
|
145
|
-
- spec/cassettes/
|
145
|
+
- spec/cassettes/geocode_fake_location.yml
|
146
|
+
- spec/cassettes/geocode_permission_denied.yml
|
147
|
+
- spec/cassettes/geocode_sunnyvale_location.yml
|
148
|
+
- spec/cassettes/reverse_geocode_fake_location.yml
|
149
|
+
- spec/cassettes/reverse_geocode_permission_denied.yml
|
150
|
+
- spec/cassettes/reverse_geocode_richmond_location.yml
|
146
151
|
- spec/geokit_here_geocoder_spec.rb
|
147
152
|
- spec/spec_helper.rb
|