geocodio-ocd 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/lib/geocodio/address.rb +114 -0
  3. data/lib/geocodio/address_set.rb +48 -0
  4. data/lib/geocodio/canadian/electoral_district_base.rb +21 -0
  5. data/lib/geocodio/canadian/electoral_districts.rb +23 -0
  6. data/lib/geocodio/canadian/federal_electoral_district.rb +12 -0
  7. data/lib/geocodio/canadian/provincial_electoral_district.rb +6 -0
  8. data/lib/geocodio/canadian.rb +14 -0
  9. data/lib/geocodio/client/error.rb +15 -0
  10. data/lib/geocodio/client/response.rb +13 -0
  11. data/lib/geocodio/client.rb +155 -0
  12. data/lib/geocodio/congressional_district.rb +30 -0
  13. data/lib/geocodio/legislator.rb +69 -0
  14. data/lib/geocodio/school_district.rb +15 -0
  15. data/lib/geocodio/state_legislative_district.rb +16 -0
  16. data/lib/geocodio/timezone.rb +16 -0
  17. data/lib/geocodio/utils.rb +43 -0
  18. data/lib/geocodio/version.rb +13 -0
  19. data/lib/geocodio.rb +9 -0
  20. data/spec/address_set_spec.rb +31 -0
  21. data/spec/address_spec.rb +235 -0
  22. data/spec/canadian_spec.rb +77 -0
  23. data/spec/client_spec.rb +196 -0
  24. data/spec/congressional_district_spec.rb +45 -0
  25. data/spec/legislator_spec.rb +116 -0
  26. data/spec/school_district_spec.rb +27 -0
  27. data/spec/spec_helper.rb +25 -0
  28. data/spec/state_legislative_district_spec.rb +43 -0
  29. data/spec/timezone_spec.rb +23 -0
  30. data/spec/vcr_cassettes/alaska_geocode_with_fields.yml +68 -0
  31. data/spec/vcr_cassettes/batch_geocode.yml +83 -0
  32. data/spec/vcr_cassettes/batch_geocode_with_bad_address.yml +61 -0
  33. data/spec/vcr_cassettes/batch_geocode_with_fields.yml +121 -0
  34. data/spec/vcr_cassettes/batch_reverse.yml +181 -0
  35. data/spec/vcr_cassettes/batch_reverse_with_fields.yml +384 -0
  36. data/spec/vcr_cassettes/canadian.yml +101 -0
  37. data/spec/vcr_cassettes/geocode.yml +61 -0
  38. data/spec/vcr_cassettes/geocode_bad_address.yml +53 -0
  39. data/spec/vcr_cassettes/geocode_with_fields.yml +71 -0
  40. data/spec/vcr_cassettes/geocode_with_fields_legacy.yml +91 -0
  41. data/spec/vcr_cassettes/geocode_with_postdirectional.yml +61 -0
  42. data/spec/vcr_cassettes/invalid_key.yml +59 -0
  43. data/spec/vcr_cassettes/parse.yml +51 -0
  44. data/spec/vcr_cassettes/reverse.yml +97 -0
  45. data/spec/vcr_cassettes/reverse_with_fields.yml +163 -0
  46. data/spec/vcr_cassettes/reverse_with_fields_no_house_info.yml +138 -0
  47. metadata +189 -0
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geocodio::AddressSet do
4
+ let(:geocodio) { Geocodio::Client.new }
5
+ let(:addresses) do
6
+ [
7
+ '1 Infinite Loop Cupertino CA 95014',
8
+ '54 West Colorado Boulevard Pasadena CA 91105',
9
+ '826 Howard Street San Francisco CA 94103'
10
+ ]
11
+ end
12
+
13
+ subject(:address_set) do
14
+ VCR.use_cassette('batch_geocode') do
15
+ geocodio.geocode(addresses).last
16
+ end
17
+ end
18
+
19
+ it 'has a size' do
20
+ expect(address_set.size).to eq(4)
21
+ end
22
+
23
+ it 'has a best' do
24
+ expect(address_set.best).to be_a(Geocodio::Address)
25
+ expect(address_set.best.accuracy).to eq(1)
26
+ end
27
+
28
+ it 'references the original query' do
29
+ expect(address_set.query).to eq('826 Howard Street San Francisco CA 94103')
30
+ end
31
+ end
@@ -0,0 +1,235 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geocodio::Address do
4
+ let(:geocodio) { Geocodio::Client.new }
5
+
6
+ context 'when parsed' do
7
+ subject(:address) do
8
+ VCR.use_cassette('parse') do
9
+ geocodio.parse('54 West Colorado Boulevard Pasadena CA 91105')
10
+ end
11
+ end
12
+
13
+ it 'has a number' do
14
+ expect(address.number).to eq('54')
15
+ end
16
+
17
+ it 'has a predirectional' do
18
+ expect(address.predirectional).to eq('W')
19
+ end
20
+
21
+ it 'has a street' do
22
+ expect(address.street).to eq('Colorado')
23
+ end
24
+
25
+ it 'has a formatted_street' do
26
+ expect(address.formatted_street).to eq('W Colorado Blvd')
27
+ end
28
+
29
+ it 'has a suffix' do
30
+ expect(address.suffix).to eq('Blvd')
31
+ end
32
+
33
+ it 'has a city' do
34
+ expect(address.city).to eq('Pasadena')
35
+ end
36
+
37
+ it 'has a state' do
38
+ expect(address.state).to eq('CA')
39
+ end
40
+
41
+ it 'has a zip' do
42
+ expect(address.zip).to eq('91105')
43
+ end
44
+
45
+ it 'does not have a latitude' do
46
+ expect(address.latitude).to be_nil
47
+ expect(address.lat).to be_nil
48
+ end
49
+
50
+ it 'does not have a longitude' do
51
+ expect(address.longitude).to be_nil
52
+ expect(address.lng).to be_nil
53
+ end
54
+
55
+ it 'does not have an accuracy' do
56
+ expect(address.accuracy).to be_nil
57
+ end
58
+
59
+ it 'does not have an accuracy_type' do
60
+ expect(address.accuracy_type).to be_nil
61
+ end
62
+ end
63
+
64
+ context 'when geocoded' do
65
+ context 'has predirectional' do
66
+ subject(:address) do
67
+ VCR.use_cassette('geocode') do
68
+ geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105']).best
69
+ end
70
+ end
71
+
72
+ it 'has a number' do
73
+ expect(address.number).to eq('54')
74
+ end
75
+
76
+ it 'has a predirectional' do
77
+ expect(address.predirectional).to eq('W')
78
+ end
79
+
80
+ it 'has a street' do
81
+ expect(address.street).to eq('Colorado')
82
+ end
83
+
84
+ it 'has a formatted_street' do
85
+ expect(address.formatted_street).to eq('W Colorado Blvd')
86
+ end
87
+
88
+ it 'has a suffix' do
89
+ expect(address.suffix).to eq('Blvd')
90
+ end
91
+
92
+ it 'has a city' do
93
+ expect(address.city).to eq('Pasadena')
94
+ end
95
+
96
+ it 'has a county' do
97
+ expect(address.county).to eq('Los Angeles County')
98
+ end
99
+
100
+ it 'has a state' do
101
+ expect(address.state).to eq('CA')
102
+ end
103
+
104
+ it 'has a zip' do
105
+ expect(address.zip).to eq('91105')
106
+ end
107
+
108
+ it 'has a latitude' do
109
+ expect(address.latitude).to eq(34.145375)
110
+ expect(address.lat).to eq(34.145375)
111
+ end
112
+
113
+ it 'has a longitude' do
114
+ expect(address.longitude).to eq(-118.151622)
115
+ expect(address.lng).to eq(-118.151622)
116
+ end
117
+
118
+ it 'has an accuracy' do
119
+ expect(address.accuracy).to eq(1)
120
+ end
121
+
122
+ it 'has an accuracy_type' do
123
+ expect(address.accuracy_type).to eq("rooftop")
124
+ end
125
+
126
+ it 'has a source' do
127
+ expect(address.source).to eq("Los Angeles")
128
+ end
129
+ end
130
+
131
+ context 'has postdirectional' do
132
+ subject(:address) do
133
+ VCR.use_cassette('geocode_with_postdirectional') do
134
+ geocodio.geocode(['1600 Pennsylvania Ave NW Washington DC 20500']).best
135
+ end
136
+ end
137
+
138
+ it 'has a number' do
139
+ expect(address.number).to eq('1600')
140
+ end
141
+
142
+ it 'has a street' do
143
+ expect(address.street).to eq('Pennsylvania')
144
+ end
145
+
146
+ it 'has a formatted_street' do
147
+ expect(address.formatted_street).to eq('Pennsylvania Ave NW')
148
+ end
149
+
150
+ it 'has a postdirectional' do
151
+ expect(address.postdirectional).to eq('NW')
152
+ end
153
+
154
+ it 'has a suffix' do
155
+ expect(address.suffix).to eq('Ave')
156
+ end
157
+
158
+ it 'has a city' do
159
+ expect(address.city).to eq('Washington')
160
+ end
161
+
162
+ it 'has a county' do
163
+ expect(address.county).to eq('District of Columbia')
164
+ end
165
+
166
+ it 'has a state' do
167
+ expect(address.state).to eq('DC')
168
+ end
169
+
170
+ it 'has a zip' do
171
+ expect(address.zip).to eq('20500')
172
+ end
173
+
174
+ it 'has a latitude' do
175
+ expect(address.latitude).to eq(38.897675)
176
+ expect(address.lat).to eq(38.897675)
177
+ end
178
+
179
+ it 'has a longitude' do
180
+ expect(address.longitude).to eq(-77.036547)
181
+ expect(address.lng).to eq(-77.036547)
182
+ end
183
+
184
+ it 'has an accuracy' do
185
+ expect(address.accuracy).to eq(1)
186
+ end
187
+
188
+ it 'has an accuracy_type' do
189
+ expect(address.accuracy_type).to eq("rooftop")
190
+ end
191
+ end
192
+
193
+ context 'with additional fields' do
194
+ subject(:address) do
195
+ VCR.use_cassette('geocode_with_fields') do
196
+ geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105'], fields: %w[cd118 stateleg-next school timezone]).best
197
+ end
198
+ end
199
+
200
+ it 'has congressional districts' do
201
+ address.congressional_districts.each do |district|
202
+ expect(district).to be_a(Geocodio::CongressionalDistrict)
203
+ end
204
+ end
205
+
206
+ it 'has house districts' do
207
+ expect(address.house_districts).to be_a(Array)
208
+ expect(address.house_districts.size).to eq(1)
209
+ expect(address.house_districts.first).to be_a(Geocodio::StateLegislativeDistrict)
210
+ end
211
+
212
+ it 'has senate districts' do
213
+ expect(address.senate_districts).to be_a(Array)
214
+ expect(address.senate_districts.size).to eq(1)
215
+ expect(address.senate_districts.first).to be_a(Geocodio::StateLegislativeDistrict)
216
+ end
217
+
218
+ it 'has a unified school district' do
219
+ expect(address.unified_school_district).to be_a(Geocodio::SchoolDistrict)
220
+ end
221
+
222
+ it 'could have an elementary school district' do
223
+ expect(address.elementary_school_district).to be_nil
224
+ end
225
+
226
+ it 'could have a secondary school district' do
227
+ expect(address.secondary_school_district).to be_nil
228
+ end
229
+
230
+ it 'has a timezone' do
231
+ expect(address.timezone).to be_a(Geocodio::Timezone)
232
+ end
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geocodio::Canadian do
4
+ let(:geocodio) { Geocodio::Client.new }
5
+
6
+ subject do
7
+ VCR.use_cassette('canadian') do
8
+ geocodio.geocode([
9
+ '1 Infinite Loop Cupertino CA 95014',
10
+ '356 Yonge St, Toronto, ON M5G, Canada',
11
+ '3475 Bd Sainte-Anne, Beauport, QC G1E 3L5, Canada'
12
+ ], fields: %w[timezone cd118 provriding riding stateleg-next]).map(&:best)
13
+ end
14
+ end
15
+
16
+ let(:us_address) { subject[0] }
17
+ let(:ca_en_address){ subject[1] }
18
+ let(:ca_fr_address){ subject[2] }
19
+
20
+ it 'is a canadian address' do
21
+ expect(ca_en_address).to be_canadian
22
+ expect(ca_fr_address).to be_canadian
23
+ end
24
+
25
+ it "isn't a canadian address" do
26
+ expect(us_address).to_not be_canadian
27
+ expect(us_address.canadian).to be_nil
28
+ end
29
+
30
+ it 'has canadian federal electoral district' do
31
+ expect(ca_en_address.canadian).to_not be_nil
32
+ expect(ca_en_address.canadian.federal_electoral_district).to_not be_nil
33
+
34
+ federal_district1 = ca_en_address.canadian.federal_electoral_district
35
+
36
+ expect(federal_district1.code).to eq('35110')
37
+ expect(federal_district1.name_english).to eq('University--Rosedale')
38
+ expect(federal_district1.name_french).to eq('University--Rosedale')
39
+ expect(federal_district1.ocd_id).to eq('ocd-division/country:ca/ed:35110-2013')
40
+ expect(federal_district1.source).to eq('Statistics Canada')
41
+
42
+ expect(ca_fr_address.canadian).to_not be_nil
43
+ expect(ca_fr_address.canadian.federal_electoral_district).to_not be_nil
44
+
45
+ federal_district2 = ca_fr_address.canadian.federal_electoral_district
46
+
47
+ expect(federal_district2.code).to eq('24008')
48
+ expect(federal_district2.name_english).to eq('Beauport--Limoilou')
49
+ expect(federal_district2.name_french).to eq('Beauport--Limoilou')
50
+ expect(federal_district2.ocd_id).to eq('ocd-division/country:ca/ed:24008-2013')
51
+ expect(federal_district2.source).to eq('Statistics Canada')
52
+ end
53
+
54
+ it 'has canadian provincial electoral district' do
55
+ expect(ca_en_address.canadian).to_not be_nil
56
+ expect(ca_en_address.canadian.provincial_electoral_district).to_not be_nil
57
+
58
+ provincial_district1 = ca_en_address.canadian.provincial_electoral_district
59
+
60
+ expect(provincial_district1.name_english).to eq('University - Rosedale')
61
+ expect(provincial_district1.name_french).to eq('University - Rosedale')
62
+ expect(provincial_district1.ocd_id).to eq('ocd-division/country:ca/province:on/ed:112-2015')
63
+ expect(provincial_district1.source).to eq('Elections Ontario')
64
+
65
+ expect(ca_fr_address.canadian).to_not be_nil
66
+ expect(ca_fr_address.canadian.provincial_electoral_district).to_not be_nil
67
+
68
+ provincial_district2 = ca_fr_address.canadian.provincial_electoral_district
69
+
70
+ expect(provincial_district2.name_english).to eq('Montmorency')
71
+ expect(provincial_district2.name_french).to eq('Montmorency')
72
+ expect(provincial_district2.ocd_id).to eq('ocd-division/country:ca/province:qc/ed:742-2017')
73
+ expect(provincial_district2.source).to eq("Contains open data granted under the Chief Electoral Officer's Open Data User Licence available at http://dgeq.org/en/. The fact of granting the licence in no way implies that the Chief Electoral Officer approves the use made of the open data.")
74
+ end
75
+
76
+
77
+ end
@@ -0,0 +1,196 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geocodio::Client do
4
+ let(:geocodio) { Geocodio::Client.new }
5
+ let(:address) { '54 West Colorado Boulevard Pasadena CA 91105' }
6
+ let(:coordinates) { '34.145760590909,-118.15204363636' }
7
+
8
+ it 'requires an API key' do
9
+ VCR.use_cassette('invalid_key') do
10
+ expect { geocodio.geocode([address]) }.to raise_error(Geocodio::Client::Error)
11
+ end
12
+ end
13
+
14
+ it 'parses an address into components' do
15
+ VCR.use_cassette('parse') do
16
+ result = geocodio.parse(address)
17
+
18
+ expect(result).to be_a(Geocodio::Address)
19
+ end
20
+ end
21
+
22
+ it 'sets the read_timeout on the underlying Net::HTTP request if passed an option' do
23
+ expect_any_instance_of(Net::HTTP).to receive(:read_timeout=).with(60 * 5)
24
+ VCR.use_cassette('geocode') { geocodio.geocode([address], timeout: 60 * 5) }
25
+ end
26
+
27
+ describe '#geocode' do
28
+ it 'geocodes a single address' do
29
+ VCR.use_cassette('geocode') do
30
+ addresses = geocodio.geocode([address])
31
+
32
+ expect(addresses.size).to eq(2)
33
+ expect(addresses).to be_a(Geocodio::AddressSet)
34
+ end
35
+ end
36
+
37
+ it 'geocodes a single address with an options hash' do
38
+ VCR.use_cassette('geocode_with_fields') do
39
+ addresses = geocodio.geocode([address], fields: %w[cd118 stateleg-next school timezone])
40
+
41
+ expect(addresses.size).to eq(2)
42
+ expect(addresses).to be_a(Geocodio::AddressSet)
43
+ end
44
+ end
45
+
46
+ it 'raises a client error when geocoding a bad address' do
47
+ VCR.use_cassette('geocode_bad_address') do
48
+ expect { geocodio.geocode([' , , ']) }.to raise_error(Geocodio::Client::Error)
49
+ end
50
+ end
51
+
52
+ it 'geocodes multiple addresses' do
53
+ VCR.use_cassette('batch_geocode') do
54
+ addresses = [
55
+ '1 Infinite Loop Cupertino CA 95014',
56
+ '54 West Colorado Boulevard Pasadena CA 91105',
57
+ '826 Howard Street San Francisco CA 94103'
58
+ ]
59
+
60
+ addresses = geocodio.geocode(addresses)
61
+
62
+ expect(addresses.size).to eq(3)
63
+ addresses.each { |address| expect(address).to be_a(Geocodio::AddressSet) }
64
+ end
65
+ end
66
+
67
+ it 'will return empty AddressSets for bad addresses in a batch geocode' do
68
+ VCR.use_cassette('batch_geocode_with_bad_address') do
69
+ addresses = [
70
+ '1 Infinite Loop Cupertino CA 95014',
71
+ ' , , '
72
+ ]
73
+
74
+ addresses = geocodio.geocode(addresses)
75
+
76
+ expect(addresses.last).to be_empty
77
+ end
78
+ end
79
+
80
+ it 'geocodes multiple addresses with an options hash' do
81
+ VCR.use_cassette('batch_geocode_with_fields') do
82
+ addresses = [
83
+ '1 Infinite Loop Cupertino CA 95014',
84
+ '54 West Colorado Boulevard Pasadena CA 91105',
85
+ '826 Howard Street San Francisco CA 94103'
86
+ ]
87
+
88
+ addresses = geocodio.geocode(addresses, fields: %w[cd118 stateleg-next school timezone])
89
+
90
+ expect(addresses.size).to eq(3)
91
+ addresses.each { |address| expect(address).to be_a(Geocodio::AddressSet) }
92
+ end
93
+ end
94
+ end
95
+
96
+ describe '#reverse_geocode' do
97
+ context 'with a single address' do
98
+ it 'uses strings' do
99
+ VCR.use_cassette('reverse') do
100
+ addresses = geocodio.reverse_geocode([coordinates])
101
+
102
+ expect(addresses.size).to eq(13)
103
+ expect(addresses).to be_a(Geocodio::AddressSet)
104
+ end
105
+ end
106
+
107
+ it 'handles a response without legislator house info' do
108
+ VCR.use_cassette('reverse_with_fields_no_house_info') do
109
+ expect { geocodio.reverse_geocode(["41.25,-96.00"], fields: %w[cd118 stateleg-next school timezone]) }.not_to raise_error(NoMethodError)
110
+ end
111
+ end
112
+
113
+ it 'uses hashes' do
114
+ VCR.use_cassette('reverse') do
115
+ lat, lng = coordinates.split(',')
116
+ addresses = geocodio.reverse_geocode([{ latitude: lat, longitude: lng }])
117
+
118
+ expect(addresses.size).to eq(13)
119
+ expect(addresses).to be_a(Geocodio::AddressSet)
120
+ end
121
+ end
122
+
123
+ it 'accepts an options hash' do
124
+ VCR.use_cassette('reverse_with_fields') do
125
+ lat, lng = coordinates.split(',')
126
+ addresses = geocodio.reverse_geocode([{ latitude: lat, longitude: lng} ], fields: %w[cd118 stateleg-next school timezone])
127
+
128
+ expect(addresses.size).to eq(13)
129
+ expect(addresses).to be_a(Geocodio::AddressSet)
130
+ end
131
+ end
132
+ end
133
+
134
+ context 'reverse geocoding multiple addresses' do
135
+ it 'uses strings' do
136
+ VCR.use_cassette('batch_reverse') do
137
+ coordinate_pairs = [
138
+ '37.331669,-122.03074',
139
+ '34.145760590909,-118.15204363636',
140
+ '37.7815,-122.404933'
141
+ ]
142
+
143
+ addresses = geocodio.reverse_geocode(coordinate_pairs)
144
+
145
+ expect(addresses.size).to eq(3)
146
+ addresses.each { |address| expect(address).to be_a(Geocodio::AddressSet) }
147
+ end
148
+ end
149
+
150
+ it 'uses hashes' do
151
+ VCR.use_cassette('batch_reverse') do
152
+ coordinate_pairs = [
153
+ { latitude: 37.331669, longitude: -122.03074 },
154
+ { latitude: 34.145760590909, longitude: -118.15204363636 },
155
+ { latitude: 37.7815, longitude: -122.404933 }
156
+ ]
157
+
158
+ addresses = geocodio.reverse_geocode(coordinate_pairs)
159
+
160
+ expect(addresses.size).to eq(3)
161
+ addresses.each { |address| expect(address).to be_a(Geocodio::AddressSet) }
162
+ end
163
+ end
164
+
165
+ it 'uses an arbitrary combination of strings and hashes' do
166
+ VCR.use_cassette('batch_reverse') do
167
+ coordinate_pairs = [
168
+ { latitude: 37.331669, longitude: -122.03074 },
169
+ '34.145760590909,-118.15204363636',
170
+ { latitude: 37.7815, longitude: -122.404933 }
171
+ ]
172
+
173
+ addresses = geocodio.reverse_geocode(coordinate_pairs)
174
+
175
+ expect(addresses.size).to eq(3)
176
+ addresses.each { |address| expect(address).to be_a(Geocodio::AddressSet) }
177
+ end
178
+ end
179
+
180
+ it 'accepts an options hash' do
181
+ VCR.use_cassette('batch_reverse_with_fields') do
182
+ coordinate_pairs = [
183
+ { latitude: 37.331669, longitude: -122.03074 },
184
+ '34.145760590909,-118.15204363636',
185
+ { latitude: 37.7815, longitude: -122.404933 }
186
+ ]
187
+
188
+ addresses = geocodio.reverse_geocode(coordinate_pairs, fields: %w[cd118 stateleg-next school timezone])
189
+
190
+ expect(addresses.size).to eq(3)
191
+ addresses.each { |address| expect(address).to be_a(Geocodio::AddressSet) }
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geocodio::CongressionalDistrict do
4
+ let(:geocodio) { Geocodio::Client.new }
5
+
6
+ subject(:district) do
7
+ VCR.use_cassette('geocode_with_fields') do
8
+ geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105'], fields: %w[cd118 stateleg-next school timezone]).
9
+ best.
10
+ congressional_districts.
11
+ first
12
+ end
13
+ end
14
+
15
+ it 'has a name' do
16
+ expect(district.name).to eq("Congressional District 28")
17
+ end
18
+
19
+ it 'has a district_number' do
20
+ expect(district.district_number).to eq(28)
21
+ end
22
+
23
+ it 'has a congress_number' do
24
+ expect(district.congress_number).to eq(118)
25
+ end
26
+
27
+ it 'has a congress_years' do
28
+ expect(district.congress_years).to eq(2023..2025)
29
+ end
30
+
31
+ it 'has a proportion' do
32
+ expect(district.proportion).to eq(1)
33
+ end
34
+
35
+ it 'has ocd_id' do
36
+ expect(district.ocd_id).to eq('ocd-division/country:us/state:ca/cd:28')
37
+ end
38
+
39
+
40
+ it 'has current_legislators' do
41
+ district.current_legislators.each do |legislator|
42
+ expect(legislator).to be_a(Geocodio::Legislator)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geocodio::Legislator do
4
+ let(:geocodio) { Geocodio::Client.new }
5
+
6
+ subject(:legislator) do
7
+ VCR.use_cassette('geocode_with_fields_legacy') do
8
+ geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105'], fields: %w[cd stateleg-next school timezone]).
9
+ best.
10
+ congressional_districts.
11
+ first.
12
+ current_legislators.
13
+ first
14
+ end
15
+ end
16
+
17
+ it 'has a type' do
18
+ expect(legislator.type).to eq('representative')
19
+ end
20
+
21
+ it 'has a name' do
22
+ expect(legislator.name).to eq('Judy Chu')
23
+ end
24
+
25
+ it 'has a birthday' do
26
+ expect(legislator.birthday).to eq(Date.new(1953, 07, 07))
27
+ end
28
+
29
+ it 'has a gender' do
30
+ expect(legislator.gender).to eq('F')
31
+ end
32
+
33
+ it 'has a party' do
34
+ expect(legislator.party).to eq('Democrat')
35
+ end
36
+
37
+ it 'has a url' do
38
+ expect(legislator.url).to eq('https://chu.house.gov')
39
+ end
40
+
41
+ it 'has a address' do
42
+ expect(legislator.address).to eq('2423 Rayburn House Office Building Washington DC 20515-0527')
43
+ end
44
+
45
+ it 'has a phone' do
46
+ expect(legislator.phone).to eq('202-225-5464')
47
+ end
48
+
49
+ it 'has a contact_form' do
50
+ expect(legislator.contact_form).to be_nil
51
+ end
52
+
53
+ it 'has a rss_url' do
54
+ expect(legislator.rss_url).to eq('http://chu.house.gov/rss.xml')
55
+ end
56
+
57
+ it 'has a twitter' do
58
+ expect(legislator.twitter).to eq('RepJudyChu')
59
+ end
60
+
61
+ it 'has a facebook' do
62
+ expect(legislator.facebook).to eq('RepJudyChu')
63
+ end
64
+
65
+ it 'has a youtube' do
66
+ expect(legislator.youtube).to eq('RepJudyChu')
67
+ end
68
+
69
+ it 'has a youtube_id' do
70
+ expect(legislator.youtube_id).to eq('UCfcbYOvdEXZNelM8T05nK-w')
71
+ end
72
+
73
+ it 'has a bioguide_id' do
74
+ expect(legislator.bioguide_id).to eq('C001080')
75
+ end
76
+
77
+ it 'has a thomas_id' do
78
+ expect(legislator.thomas_id).to eq('01970')
79
+ end
80
+
81
+ it 'has a opensecrets_id' do
82
+ expect(legislator.opensecrets_id).to eq('N00030600')
83
+ end
84
+
85
+ it 'has a lis_id' do
86
+ expect(legislator.lis_id).to be_nil
87
+ end
88
+
89
+ it 'has a cspan_id' do
90
+ expect(legislator.cspan_id).to eq('92573')
91
+ end
92
+
93
+ it 'has a govtrack_id' do
94
+ expect(legislator.govtrack_id).to eq('412379')
95
+ end
96
+
97
+ it 'has a votesmart_id' do
98
+ expect(legislator.votesmart_id).to eq('16539')
99
+ end
100
+
101
+ it 'has a ballotpedia_id' do
102
+ expect(legislator.ballotpedia_id).to eq('Judy Chu')
103
+ end
104
+
105
+ it 'has a washington_post_id' do
106
+ expect(legislator.washington_post_id).to be_nil
107
+ end
108
+
109
+ it 'has a icpsr_id' do
110
+ expect(legislator.icpsr_id).to eq('20955')
111
+ end
112
+
113
+ it 'has a wikipedia_id' do
114
+ expect(legislator.wikipedia_id).to eq('Judy Chu')
115
+ end
116
+ end