diff --git a/lib/geocodio/address.rb b/lib/geocodio/address.rb index 11433e6..3fd245d 100644 --- a/lib/geocodio/address.rb +++ b/lib/geocodio/address.rb @@ -1,6 +1,7 @@ module Geocodio class Address attr_accessor :number + attr_accessor :predirectional attr_accessor :street attr_accessor :suffix attr_accessor :city @@ -19,12 +20,13 @@ class Address def initialize(payload = {}) if payload['address_components'] - @number = payload['address_components']['number'] - @street = payload['address_components']['street'] - @suffix = payload['address_components']['suffix'] - @city = payload['address_components']['city'] - @state = payload['address_components']['state'] - @zip = payload['address_components']['zip'] + @number = payload['address_components']['number'] + @predirectional = payload['address_components']['predirectional'] + @street = payload['address_components']['street'] + @suffix = payload['address_components']['suffix'] + @city = payload['address_components']['city'] + @state = payload['address_components']['state'] + @zip = payload['address_components']['zip'] end if payload['location'] diff --git a/spec/address_spec.rb b/spec/address_spec.rb index 52646bc..11e38e0 100644 --- a/spec/address_spec.rb +++ b/spec/address_spec.rb @@ -6,24 +6,28 @@ context 'when parsed' do subject(:address) do VCR.use_cassette('parse') do - geocodio.parse('1 Infinite Loop Cupertino CA 95014') + geocodio.parse('54 West Colorado Boulevard Pasadena CA 91105') end end it 'has a number' do - expect(address.number).to eq('1') + expect(address.number).to eq('54') + end + + it 'has a predirectional' do + expect(address.predirectional).to eq('W') end it 'has a street' do - expect(address.street).to eq('Infinite') + expect(address.street).to eq('Colorado') end it 'has a suffix' do - expect(address.suffix).to eq('Loop') + expect(address.suffix).to eq('Blvd') end it 'has a city' do - expect(address.city).to eq('Cupertino') + expect(address.city).to eq('Pasadena') end it 'has a state' do @@ -31,7 +35,7 @@ end it 'has a zip' do - expect(address.zip).to eq('95014') + expect(address.zip).to eq('91105') end it 'does not have a latitude' do @@ -52,24 +56,28 @@ context 'when geocoded' do subject(:address) do VCR.use_cassette('geocode') do - geocodio.geocode('1 Infinite Loop Cupertino CA 95014').best + geocodio.geocode('54 West Colorado Boulevard Pasadena CA 91105').best end end it 'has a number' do - expect(address.number).to eq('1') + expect(address.number).to eq('54') + end + + it 'has a predirectional' do + expect(address.predirectional).to eq('W') end it 'has a street' do - expect(address.street).to eq('Infinite') + expect(address.street).to eq('Colorado') end it 'has a suffix' do - expect(address.suffix).to eq('Loop') + expect(address.suffix).to eq('Blvd') end it 'has a city' do - expect(address.city).to eq('Monta Vista') + expect(address.city).to eq('Pasadena') end it 'has a state' do @@ -77,17 +85,17 @@ end it 'has a zip' do - expect(address.zip).to eq('95014') + expect(address.zip).to eq('91105') end it 'has a latitude' do - expect(address.latitude).to eq(37.331669) - expect(address.lat).to eq(37.331669) + expect(address.latitude).to eq(34.145760590909) + expect(address.lat).to eq(34.145760590909) end it 'has a longitude' do - expect(address.longitude).to eq(-122.03074) - expect(address.lng).to eq(-122.03074) + expect(address.longitude).to eq(-118.15204363636) + expect(address.lng).to eq(-118.15204363636) end it 'has an accuracy' do diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 49839ea..873494b 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -2,7 +2,7 @@ describe Geocodio::Client do let(:geocodio) { Geocodio::Client.new } - let(:address) { '1 Infinite Loop Cupertino CA 95014' } + let(:address) { '54 West Colorado Boulevard Pasadena CA 91105' } it 'requires an API key' do VCR.use_cassette('invalid_key') do @@ -22,7 +22,7 @@ VCR.use_cassette('geocode') do addresses = geocodio.geocode(address) - expect(addresses.size).to eq(1) + expect(addresses.size).to eq(2) expect(addresses).to be_a(Geocodio::AddressSet) end end diff --git a/spec/vcr_cassettes/geocode.yml b/spec/vcr_cassettes/geocode.yml index 81d4f55..67756f1 100644 --- a/spec/vcr_cassettes/geocode.yml +++ b/spec/vcr_cassettes/geocode.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api.geocod.io/v1/geocode?api_key=secret_api_key&q=1%20Infinite%20Loop%20Cupertino%20CA%2095014 + uri: http://api.geocod.io/v1/geocode?api_key=secret_api_key&q=54%20West%20Colorado%20Boulevard%20Pasadena%20CA%2091105 body: encoding: US-ASCII string: '' @@ -19,7 +19,7 @@ http_interactions: message: OK headers: Date: - - Tue, 21 Jan 2014 19:55:27 GMT + - Sun, 02 Feb 2014 17:40:52 GMT Server: - Apache X-Powered-By: @@ -34,10 +34,10 @@ http_interactions: - application/json body: encoding: UTF-8 - string: "{\"input\":{\"address_components\":{\"number\":\"1\",\"street\":\"Infinite\",\"suffix\":\"Loop\",\"city\":\"Cupertino\",\"state\":\"CA\",\"zip\":\"95014\"},\"formatted_address\":\"1 - Infinite Loop, Cupertino CA, 95014\"},\"results\":[{\"address_components\":{\"number\":\"1\",\"street\":\"Infinite\",\"suffix\":\"Loop\",\"city\":\"Monta - Vista\",\"state\":\"CA\",\"zip\":\"95014\"},\"formatted_address\":\"1 Infinite - Loop, Monta Vista CA, 95014\",\"location\":{\"lat\":37.331669,\"lng\":-122.03074},\"accuracy\":1}]}" + string: "{\"input\":{\"address_components\":{\"number\":\"54\",\"predirectional\":\"W\",\"street\":\"Colorado\",\"suffix\":\"Blvd\",\"city\":\"Pasadena\",\"state\":\"CA\",\"zip\":\"91105\"},\"formatted_address\":\"54 + W Colorado Blvd, Pasadena, CA 91105\"},\"results\":[{\"address_components\":{\"number\":\"54\",\"predirectional\":\"W\",\"street\":\"Colorado\",\"suffix\":\"Blvd\",\"city\":\"Pasadena\",\"state\":\"CA\",\"zip\":\"91105\"},\"formatted_address\":\"54 + W Colorado Blvd, Pasadena, CA 91105\",\"location\":{\"lat\":34.145760590909,\"lng\":-118.15204363636},\"accuracy\":1},{\"address_components\":{\"number\":\"54\",\"predirectional\":\"W\",\"street\":\"Colorado\",\"suffix\":\"Blvd\",\"city\":\"Pasadena\",\"state\":\"CA\",\"zip\":\"91105\"},\"formatted_address\":\"54 + W Colorado Blvd, Pasadena, CA 91105\",\"location\":{\"lat\":34.1457634625,\"lng\":-118.15170725},\"accuracy\":0.8}]}" http_version: - recorded_at: Tue, 21 Jan 2014 19:55:28 GMT + recorded_at: Sun, 02 Feb 2014 17:40:53 GMT recorded_with: VCR 2.8.0 diff --git a/spec/vcr_cassettes/invalid_key.yml b/spec/vcr_cassettes/invalid_key.yml index 7c3e85f..2a9e4a3 100644 --- a/spec/vcr_cassettes/invalid_key.yml +++ b/spec/vcr_cassettes/invalid_key.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api.geocod.io/v1/geocode?api_key=secret_api_key&q=1%20Infinite%20Loop%20Cupertino%20CA%2095014 + uri: http://api.geocod.io/v1/geocode?api_key=secret_api_key&q=54%20West%20Colorado%20Boulevard%20Pasadena%20CA%2091105 body: encoding: US-ASCII string: '' @@ -19,7 +19,7 @@ http_interactions: message: Forbidden headers: Date: - - Tue, 21 Jan 2014 20:47:20 GMT + - Sun, 02 Feb 2014 17:43:02 GMT Server: - Apache X-Powered-By: @@ -36,5 +36,5 @@ http_interactions: encoding: UTF-8 string: "{\"error\":\"Invalid API key\"}" http_version: - recorded_at: Tue, 21 Jan 2014 20:47:21 GMT + recorded_at: Sun, 02 Feb 2014 17:43:03 GMT recorded_with: VCR 2.8.0 diff --git a/spec/vcr_cassettes/parse.yml b/spec/vcr_cassettes/parse.yml index 177f85c..75df93d 100644 --- a/spec/vcr_cassettes/parse.yml +++ b/spec/vcr_cassettes/parse.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api.geocod.io/v1/parse?api_key=secret_api_key&q=1%20Infinite%20Loop%20Cupertino%20CA%2095014 + uri: http://api.geocod.io/v1/parse?api_key=secret_api_key&q=54%20West%20Colorado%20Boulevard%20Pasadena%20CA%2091105 body: encoding: US-ASCII string: '' @@ -19,7 +19,7 @@ http_interactions: message: OK headers: Date: - - Tue, 21 Jan 2014 19:39:24 GMT + - Sun, 02 Feb 2014 17:40:52 GMT Server: - Apache X-Powered-By: @@ -34,8 +34,8 @@ http_interactions: - application/json body: encoding: UTF-8 - string: "{\"address_components\":{\"number\":\"1\",\"street\":\"Infinite\",\"suffix\":\"Loop\",\"city\":\"Cupertino\",\"state\":\"CA\",\"zip\":\"95014\"},\"formatted_address\":\"1 - Infinite Loop, Cupertino CA, 95014\"}" + string: "{\"address_components\":{\"number\":\"54\",\"predirectional\":\"W\",\"street\":\"Colorado\",\"suffix\":\"Blvd\",\"city\":\"Pasadena\",\"state\":\"CA\",\"zip\":\"91105\"},\"formatted_address\":\"54 + W Colorado Blvd, Pasadena, CA 91105\"}" http_version: - recorded_at: Tue, 21 Jan 2014 19:39:25 GMT + recorded_at: Sun, 02 Feb 2014 17:40:54 GMT recorded_with: VCR 2.8.0