class Geocoder::Lookup::SmartyStreets
def base_query_url(query)
def base_query_url(query) if international?(query) "#{protocol}://international-street.api.smartystreets.com/verify?" elsif zipcode_only?(query) "#{protocol}://us-zipcode.api.smartystreets.com/lookup?" else "#{protocol}://us-street.api.smartystreets.com/street-address?" end end
def international?(query)
def international?(query) !query.options[:country].nil? end
def name
def name "SmartyStreets" end
def query_url_params(query)
def query_url_params(query) params = {} if international?(query) params[:freeform] = query.sanitized_text params[:country] = query.options[:country] params[:geocode] = true elsif zipcode_only?(query) params[:zipcode] = query.sanitized_text else params[:street] = query.sanitized_text end if configuration.api_key.is_a?(Array) params[:"auth-id"] = configuration.api_key[0] params[:"auth-token"] = configuration.api_key[1] else params[:"auth-token"] = configuration.api_key end params.merge(super) end
def required_api_key_parts
def required_api_key_parts %w(auth-id auth-token) end
def results(query)
def results(query) doc = fetch_data(query) || [] if doc.is_a?(Hash) and doc.key?('status') # implies there's an error return [] else return doc end end
def supported_protocols
def supported_protocols [:https] end
def zipcode_only?(query)
def zipcode_only?(query) !query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/ end