geocodio 2.0.2 → 2.0.3
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/lib/geocodio/address.rb +14 -11
- data/lib/geocodio/state_legislative_district.rb +1 -1
- data/lib/geocodio/version.rb +1 -1
- data/spec/address_spec.rb +105 -37
- data/spec/state_legislative_district_spec.rb +26 -8
- data/spec/vcr_cassettes/alaska_geocode_with_fields.yml +52 -0
- data/spec/vcr_cassettes/geocode_with_postdirectional.yml +49 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afa860ed63dc9a07695e2bf6a03738b48af1ed10
|
4
|
+
data.tar.gz: 4d610a6ad6dc2b79056a5ea1ace196a5a56c92ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61f829342c1cb880282d1c52960a3d656f306da114f0695eec8556432c5309e60f070bf9cbae63d0a4956c5f4ba32d75b2d0d3b52db6eff92f2100f77162dc48
|
7
|
+
data.tar.gz: a2a42d0b529cd8d7431185bc00937df695dc12b57dbca7a334c69fddd554512da9fb24e136151bf01176f9ffa1f2dc44a695aa13ec78272a0ac619144820903e
|
data/lib/geocodio/address.rb
CHANGED
@@ -5,7 +5,8 @@ require 'geocodio/timezone'
|
|
5
5
|
|
6
6
|
module Geocodio
|
7
7
|
class Address
|
8
|
-
attr_reader :number, :predirectional, :street, :suffix, :
|
8
|
+
attr_reader :number, :predirectional, :street, :suffix, :postdirectional,
|
9
|
+
:formatted_street, :city, :state, :zip, :county
|
9
10
|
|
10
11
|
attr_reader :latitude, :longitude
|
11
12
|
alias :lat :latitude
|
@@ -41,14 +42,16 @@ module Geocodio
|
|
41
42
|
private
|
42
43
|
|
43
44
|
def set_attributes(attributes)
|
44
|
-
@number
|
45
|
-
@predirectional
|
46
|
-
@street
|
47
|
-
@suffix
|
48
|
-
@
|
49
|
-
@
|
50
|
-
@
|
51
|
-
@
|
45
|
+
@number = attributes['number']
|
46
|
+
@predirectional = attributes['predirectional']
|
47
|
+
@street = attributes['street']
|
48
|
+
@suffix = attributes['suffix']
|
49
|
+
@postdirectional = attributes['postdirectional']
|
50
|
+
@formatted_street = attributes['formatted_street']
|
51
|
+
@city = attributes['city']
|
52
|
+
@state = attributes['state']
|
53
|
+
@zip = attributes['zip']
|
54
|
+
@county = attributes['county']
|
52
55
|
end
|
53
56
|
|
54
57
|
def set_coordinates(coordinates)
|
@@ -72,8 +75,8 @@ module Geocodio
|
|
72
75
|
def set_legislative_districts(districts)
|
73
76
|
return if districts.empty?
|
74
77
|
|
75
|
-
@house_district = StateLegislativeDistrict.new(districts['house'])
|
76
|
-
@senate_district = StateLegislativeDistrict.new(districts['senate'])
|
78
|
+
@house_district = StateLegislativeDistrict.new(districts['house']) if districts['house']
|
79
|
+
@senate_district = StateLegislativeDistrict.new(districts['senate']) if districts['senate']
|
77
80
|
end
|
78
81
|
|
79
82
|
def set_school_districts(schools)
|
data/lib/geocodio/version.rb
CHANGED
data/spec/address_spec.rb
CHANGED
@@ -21,6 +21,10 @@ describe Geocodio::Address do
|
|
21
21
|
it 'has a street' do
|
22
22
|
expect(address.street).to eq('Colorado')
|
23
23
|
end
|
24
|
+
|
25
|
+
it 'has a formatted_street' do
|
26
|
+
expect(address.formatted_street).to eq('W Colorado Blvd')
|
27
|
+
end
|
24
28
|
|
25
29
|
it 'has a suffix' do
|
26
30
|
expect(address.suffix).to eq('Blvd')
|
@@ -54,56 +58,120 @@ describe Geocodio::Address do
|
|
54
58
|
end
|
55
59
|
|
56
60
|
context 'when geocoded' do
|
57
|
-
|
58
|
-
|
59
|
-
|
61
|
+
context 'has predirectional' do
|
62
|
+
subject(:address) do
|
63
|
+
VCR.use_cassette('geocode') do
|
64
|
+
geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105']).best
|
65
|
+
end
|
60
66
|
end
|
61
|
-
end
|
62
67
|
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
it 'has a number' do
|
69
|
+
expect(address.number).to eq('54')
|
70
|
+
end
|
66
71
|
|
67
|
-
|
68
|
-
|
69
|
-
|
72
|
+
it 'has a predirectional' do
|
73
|
+
expect(address.predirectional).to eq('W')
|
74
|
+
end
|
70
75
|
|
71
|
-
|
72
|
-
|
73
|
-
|
76
|
+
it 'has a street' do
|
77
|
+
expect(address.street).to eq('Colorado')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'has a formatted_street' do
|
81
|
+
expect(address.formatted_street).to eq('W Colorado Blvd')
|
82
|
+
end
|
74
83
|
|
75
|
-
|
76
|
-
|
77
|
-
|
84
|
+
it 'has a suffix' do
|
85
|
+
expect(address.suffix).to eq('Blvd')
|
86
|
+
end
|
78
87
|
|
79
|
-
|
80
|
-
|
81
|
-
|
88
|
+
it 'has a city' do
|
89
|
+
expect(address.city).to eq('Pasadena')
|
90
|
+
end
|
82
91
|
|
83
|
-
|
84
|
-
|
85
|
-
|
92
|
+
it 'has a county' do
|
93
|
+
expect(address.county).to eq('Los Angeles County')
|
94
|
+
end
|
86
95
|
|
87
|
-
|
88
|
-
|
89
|
-
|
96
|
+
it 'has a state' do
|
97
|
+
expect(address.state).to eq('CA')
|
98
|
+
end
|
90
99
|
|
91
|
-
|
92
|
-
|
93
|
-
|
100
|
+
it 'has a zip' do
|
101
|
+
expect(address.zip).to eq('91105')
|
102
|
+
end
|
94
103
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
104
|
+
it 'has a latitude' do
|
105
|
+
expect(address.latitude).to eq(34.145764409091)
|
106
|
+
expect(address.lat).to eq(34.145764409091)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'has a longitude' do
|
110
|
+
expect(address.longitude).to eq(-118.15159636364)
|
111
|
+
expect(address.lng).to eq(-118.15159636364)
|
112
|
+
end
|
99
113
|
|
100
|
-
|
101
|
-
|
102
|
-
|
114
|
+
it 'has an accuracy' do
|
115
|
+
expect(address.accuracy).to eq(1)
|
116
|
+
end
|
103
117
|
end
|
118
|
+
|
119
|
+
context 'has postdirectional' do
|
120
|
+
subject(:address) do
|
121
|
+
VCR.use_cassette('geocode_with_postdirectional') do
|
122
|
+
geocodio.geocode(['1600 Pennsylvania Ave NW Washington DC 20500']).best
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'has a number' do
|
127
|
+
expect(address.number).to eq('1600')
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'has a street' do
|
131
|
+
expect(address.street).to eq('Pennsylvania')
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'has a formatted_street' do
|
135
|
+
expect(address.formatted_street).to eq('Pennsylvania Ave NW')
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'has a postdirectional' do
|
139
|
+
expect(address.postdirectional).to eq('NW')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'has a suffix' do
|
143
|
+
expect(address.suffix).to eq('Ave')
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'has a city' do
|
147
|
+
expect(address.city).to eq('Washington')
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'has a county' do
|
151
|
+
expect(address.county).to eq('District of Columbia')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'has a state' do
|
155
|
+
expect(address.state).to eq('DC')
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'has a zip' do
|
159
|
+
expect(address.zip).to eq('20500')
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'has a latitude' do
|
163
|
+
expect(address.latitude).to eq(38.897667)
|
164
|
+
expect(address.lat).to eq(38.897667)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'has a longitude' do
|
168
|
+
expect(address.longitude).to eq(-77.036545)
|
169
|
+
expect(address.lng).to eq(-77.036545)
|
170
|
+
end
|
104
171
|
|
105
|
-
|
106
|
-
|
172
|
+
it 'has an accuracy' do
|
173
|
+
expect(address.accuracy).to eq(1)
|
174
|
+
end
|
107
175
|
end
|
108
176
|
|
109
177
|
context 'with additional fields' do
|
@@ -3,17 +3,35 @@ require 'spec_helper'
|
|
3
3
|
describe Geocodio::StateLegislativeDistrict do
|
4
4
|
let(:geocodio) { Geocodio::Client.new }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
context 'typical numeric district' do
|
7
|
+
subject(:district) do
|
8
|
+
VCR.use_cassette('geocode_with_fields') do
|
9
|
+
geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105'], fields: %w[cd stateleg school timezone]).best.house_district
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a name' do
|
14
|
+
expect(district.name).to eq("Assembly District 41")
|
9
15
|
end
|
10
|
-
end
|
11
16
|
|
12
|
-
|
13
|
-
|
17
|
+
it 'has a district_number' do
|
18
|
+
expect(district.district_number).to eq(41)
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
|
-
|
17
|
-
|
22
|
+
context 'Alaska non-numeric state district' do
|
23
|
+
subject(:alaska_district) do
|
24
|
+
VCR.use_cassette('alaska_geocode_with_fields') do
|
25
|
+
geocodio.geocode(['4141 woronzof dr anchorage ak 99517'], fields: %w[cd stateleg]).best.senate_district
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'has a name' do
|
30
|
+
expect(alaska_district.name).to eq("State Senate District K")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has a district_number' do
|
34
|
+
expect(alaska_district.district_number).to eq('K')
|
35
|
+
end
|
18
36
|
end
|
19
37
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.geocod.io/v1/geocode?api_key=secret_api_key&fields=cd,stateleg&q=4141%20woronzof%20dr%20anchorage%20ak%2099517
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.10.2
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache
|
29
|
+
Date:
|
30
|
+
- Tue, 01 Aug 2017 17:54:13 GMT
|
31
|
+
Request-Handler:
|
32
|
+
- api19
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
Access-Control-Allow-Methods:
|
36
|
+
- GET, POST
|
37
|
+
Access-Control-Allow-Headers:
|
38
|
+
- Content-Type
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"input":{"address_components":{"number":"4141","street":"Woronzof","suffix":"Dr","formatted_street":"Woronzof
|
42
|
+
Dr","city":"Anchorage","state":"AK","zip":"99517","country":"US"},"formatted_address":"4141
|
43
|
+
Woronzof Dr, Anchorage, AK 99517"},"results":[{"address_components":{"number":"4141","street":"Woronzof","suffix":"Dr","formatted_street":"Woronzof
|
44
|
+
Dr","city":"Anchorage","county":"Anchorage Municipality","state":"AK","zip":"99517","country":"US"},"formatted_address":"4141
|
45
|
+
Woronzof Dr, Anchorage, AK 99517","location":{"lat":61.193733,"lng":-149.959449},"accuracy":0.8,"accuracy_type":"range_interpolation","source":"TIGER\/Line\u00ae
|
46
|
+
dataset from the US Census Bureau","fields":{"congressional_district":{"name":"Congressional
|
47
|
+
District (at Large)","district_number":0,"congress_number":"115th","congress_years":"2017-2019"},"state_legislative_districts":{"senate":{"name":"State
|
48
|
+
Senate District K","district_number":"K"},"house":{"name":"State House District
|
49
|
+
21","district_number":"21"}}}}]}'
|
50
|
+
http_version:
|
51
|
+
recorded_at: Tue, 01 Aug 2017 17:54:13 GMT
|
52
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.geocod.io/v1/geocode?api_key=secret_api_key&q=1600%20Pennsylvania%20Ave%20NW%20Washington%20DC%2020500
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.6.2
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache
|
29
|
+
Date:
|
30
|
+
- Mon, 26 Dec 2016 21:50:06 GMT
|
31
|
+
Request-Handler:
|
32
|
+
- api17
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
Access-Control-Allow-Methods:
|
36
|
+
- GET, POST
|
37
|
+
Access-Control-Allow-Headers:
|
38
|
+
- Content-Type
|
39
|
+
body:
|
40
|
+
encoding: ASCII-8BIT
|
41
|
+
string: '{"input":{"address_components":{"number":"1600","street":"Pennsylvania","suffix":"Ave","postdirectional":"NW","formatted_street":"Pennsylvania
|
42
|
+
Ave NW","city":"Washington","state":"DC","zip":"20500","country":"US"},"formatted_address":"1600
|
43
|
+
Pennsylvania Ave NW, Washington, DC 20500"},"results":[{"address_components":{"number":"1600","street":"Pennsylvania","suffix":"Ave","postdirectional":"NW","formatted_street":"Pennsylvania
|
44
|
+
Ave NW","city":"Washington","county":"District of Columbia","state":"DC","zip":"20500","country":"US"},"formatted_address":"1600
|
45
|
+
Pennsylvania Ave NW, Washington, DC 20500","location":{"lat":38.897667,"lng":-77.036545},"accuracy":1,"accuracy_type":"rooftop","source":"DC
|
46
|
+
Geographic Information Systems Program (DC GIS)"}]}'
|
47
|
+
http_version:
|
48
|
+
recorded_at: Mon, 26 Dec 2016 21:50:06 GMT
|
49
|
+
recorded_with: VCR 3.0.3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocodio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- spec/spec_helper.rb
|
110
110
|
- spec/state_legislative_district_spec.rb
|
111
111
|
- spec/timezone_spec.rb
|
112
|
+
- spec/vcr_cassettes/alaska_geocode_with_fields.yml
|
112
113
|
- spec/vcr_cassettes/batch_geocode.yml
|
113
114
|
- spec/vcr_cassettes/batch_geocode_with_bad_address.yml
|
114
115
|
- spec/vcr_cassettes/batch_geocode_with_fields.yml
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- spec/vcr_cassettes/geocode.yml
|
118
119
|
- spec/vcr_cassettes/geocode_bad_address.yml
|
119
120
|
- spec/vcr_cassettes/geocode_with_fields.yml
|
121
|
+
- spec/vcr_cassettes/geocode_with_postdirectional.yml
|
120
122
|
- spec/vcr_cassettes/invalid_key.yml
|
121
123
|
- spec/vcr_cassettes/parse.yml
|
122
124
|
- spec/vcr_cassettes/reverse.yml
|
@@ -141,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
143
|
version: '0'
|
142
144
|
requirements: []
|
143
145
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.6.11
|
145
147
|
signing_key:
|
146
148
|
specification_version: 4
|
147
149
|
summary: An unofficial Ruby client library for geocod.io
|
@@ -154,6 +156,7 @@ test_files:
|
|
154
156
|
- spec/spec_helper.rb
|
155
157
|
- spec/state_legislative_district_spec.rb
|
156
158
|
- spec/timezone_spec.rb
|
159
|
+
- spec/vcr_cassettes/alaska_geocode_with_fields.yml
|
157
160
|
- spec/vcr_cassettes/batch_geocode.yml
|
158
161
|
- spec/vcr_cassettes/batch_geocode_with_bad_address.yml
|
159
162
|
- spec/vcr_cassettes/batch_geocode_with_fields.yml
|
@@ -162,8 +165,8 @@ test_files:
|
|
162
165
|
- spec/vcr_cassettes/geocode.yml
|
163
166
|
- spec/vcr_cassettes/geocode_bad_address.yml
|
164
167
|
- spec/vcr_cassettes/geocode_with_fields.yml
|
168
|
+
- spec/vcr_cassettes/geocode_with_postdirectional.yml
|
165
169
|
- spec/vcr_cassettes/invalid_key.yml
|
166
170
|
- spec/vcr_cassettes/parse.yml
|
167
171
|
- spec/vcr_cassettes/reverse.yml
|
168
172
|
- spec/vcr_cassettes/reverse_with_fields.yml
|
169
|
-
has_rdoc:
|