Skip to content
Snippets Groups Projects
Commit bd37a240 authored by Alex Reisner's avatar Alex Reisner
Browse files

Handle different response structures explicitly.

parent ea69f1a1
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ module Geocoder::Result ...@@ -4,7 +4,7 @@ module Geocoder::Result
class SmartyStreets < Base class SmartyStreets < Base
def coordinates def coordinates
%w(latitude longitude).map do |i| %w(latitude longitude).map do |i|
(zipcode_result? && zipcodes.first[i]) || metadata[i] zipcode_endpoint? ? zipcodes.first[i] : metadata[i]
end end
end end
...@@ -17,15 +17,15 @@ module Geocoder::Result ...@@ -17,15 +17,15 @@ module Geocoder::Result
end end
def state def state
components['state_abbreviation'] || city_states.first['state'] zipcode_endpoint? ?
city_states.first['state'] :
components['state_abbreviation']
end end
def state_code def state_code
if cs = city_states.first zipcode_endpoint? ?
cs['state_abbreviation'] city_states.first['state_abbreviation'] :
else components['state_abbreviation']
state
end
end end
def country def country
...@@ -45,11 +45,15 @@ module Geocoder::Result ...@@ -45,11 +45,15 @@ module Geocoder::Result
end end
def city def city
components['city_name'] || city_states.first['city'] zipcode_endpoint? ?
city_states.first['city'] :
components['city_name']
end end
def zipcode def zipcode
components['zipcode'] || zipcodes.first['zipcode'] zipcode_endpoint? ?
zipcodes.first['zipcode'] :
components['zipcode']
end end
alias_method :postal_code, :zipcode alias_method :postal_code, :zipcode
...@@ -59,10 +63,12 @@ module Geocoder::Result ...@@ -59,10 +63,12 @@ module Geocoder::Result
alias_method :postal_code_extended, :zip4 alias_method :postal_code_extended, :zip4
def fips def fips
metadata['county_fips'] || zipcodes.first['county_fips'] zipcode_endpoint? ?
zipcodes.first['county_fips'] :
metadata['county_fips']
end end
def zipcode_result? def zipcode_endpoint?
zipcodes.any? zipcodes.any?
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment