geocodio 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d1f89d4c1ab8ee23caad6c1685584da9e8d2a75
4
- data.tar.gz: 9c386a5f48939073696b3da37f0894cdd4095dbf
3
+ metadata.gz: afa860ed63dc9a07695e2bf6a03738b48af1ed10
4
+ data.tar.gz: 4d610a6ad6dc2b79056a5ea1ace196a5a56c92ef
5
5
  SHA512:
6
- metadata.gz: 47e4610788b957b4126650e97973fab8dd59ef370728742377127b44a542b515d5aa2294f39bf0c92e53e5553e635b89bf650c31d04d28648b1983f02db8cbb4
7
- data.tar.gz: 0e8edbcac6e4fe31be1b01fb456a3f288764a6799817bbe8121cec2f3e2791a4e55243a06c9ce20c97ac807d3ff84bf71396fd9ac0a4ea07fe1d9d3d1219aa2a
6
+ metadata.gz: 61f829342c1cb880282d1c52960a3d656f306da114f0695eec8556432c5309e60f070bf9cbae63d0a4956c5f4ba32d75b2d0d3b52db6eff92f2100f77162dc48
7
+ data.tar.gz: a2a42d0b529cd8d7431185bc00937df695dc12b57dbca7a334c69fddd554512da9fb24e136151bf01176f9ffa1f2dc44a695aa13ec78272a0ac619144820903e
@@ -5,7 +5,8 @@ require 'geocodio/timezone'
5
5
 
6
6
  module Geocodio
7
7
  class Address
8
- attr_reader :number, :predirectional, :street, :suffix, :city, :state, :zip, :county
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 = attributes['number']
45
- @predirectional = attributes['predirectional']
46
- @street = attributes['street']
47
- @suffix = attributes['suffix']
48
- @city = attributes['city']
49
- @state = attributes['state']
50
- @zip = attributes['zip']
51
- @county = attributes['county']
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)
@@ -5,7 +5,7 @@ module Geocodio
5
5
 
6
6
  def initialize(payload = {})
7
7
  @name = payload['name']
8
- @district_number = payload['district_number'].to_i
8
+ @district_number = payload['district_number']
9
9
  end
10
10
  end
11
11
  end
@@ -2,7 +2,7 @@ module Geocodio
2
2
  class Version
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- PATCH = 2
5
+ PATCH = 3
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].join('.')
@@ -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
- subject(:address) do
58
- VCR.use_cassette('geocode') do
59
- geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105']).best
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
- it 'has a number' do
64
- expect(address.number).to eq('54')
65
- end
68
+ it 'has a number' do
69
+ expect(address.number).to eq('54')
70
+ end
66
71
 
67
- it 'has a predirectional' do
68
- expect(address.predirectional).to eq('W')
69
- end
72
+ it 'has a predirectional' do
73
+ expect(address.predirectional).to eq('W')
74
+ end
70
75
 
71
- it 'has a street' do
72
- expect(address.street).to eq('Colorado')
73
- end
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
- it 'has a suffix' do
76
- expect(address.suffix).to eq('Blvd')
77
- end
84
+ it 'has a suffix' do
85
+ expect(address.suffix).to eq('Blvd')
86
+ end
78
87
 
79
- it 'has a city' do
80
- expect(address.city).to eq('Pasadena')
81
- end
88
+ it 'has a city' do
89
+ expect(address.city).to eq('Pasadena')
90
+ end
82
91
 
83
- it 'has a county' do
84
- expect(address.county).to eq('Los Angeles County')
85
- end
92
+ it 'has a county' do
93
+ expect(address.county).to eq('Los Angeles County')
94
+ end
86
95
 
87
- it 'has a state' do
88
- expect(address.state).to eq('CA')
89
- end
96
+ it 'has a state' do
97
+ expect(address.state).to eq('CA')
98
+ end
90
99
 
91
- it 'has a zip' do
92
- expect(address.zip).to eq('91105')
93
- end
100
+ it 'has a zip' do
101
+ expect(address.zip).to eq('91105')
102
+ end
94
103
 
95
- it 'has a latitude' do
96
- expect(address.latitude).to eq(34.145764409091)
97
- expect(address.lat).to eq(34.145764409091)
98
- end
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
- it 'has a longitude' do
101
- expect(address.longitude).to eq(-118.15159636364)
102
- expect(address.lng).to eq(-118.15159636364)
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
- it 'has an accuracy' do
106
- expect(address.accuracy).to eq(1)
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
- subject(:district) do
7
- VCR.use_cassette('geocode_with_fields') do
8
- geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105'], fields: %w[cd stateleg school timezone]).best.house_district
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
- it 'has a name' do
13
- expect(district.name).to eq("Assembly District 41")
17
+ it 'has a district_number' do
18
+ expect(district.district_number).to eq(41)
19
+ end
14
20
  end
15
21
 
16
- it 'has a district_number' do
17
- expect(district.district_number).to eq(41)
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.2
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: 2015-07-22 00:00:00.000000000 Z
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.4.5
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: