module MQReader::ClassMethods
Public Instance Methods
Geocode a address. This method takes an address as a string and performs the geocoding against mapquest’s api. The options hash can have any option accepted by the mapquest geocoding api. The options key can be written ruby-style with underscores, they are transformed to mapquests format. If in the future a new option is added to the api by mapquest, you can add it in the options hash and it will work.
@param [String] address to geocode @param [Hash] options for mapquest geocoding service
# File lib/mq_reader/mq_reader.rb, line 18 def geocode_address(address, options = {}) path = GEOCODING_PATH params = ({ location: CGI::escape(address) }.merge!(to_mapquest_notation(options) )) MQGeocode.new(send_get_to_mapquest(path, params)) end
Private Instance Methods
Method that posts to the mapquest geocoding api
@params [String] path to the geocoding api. /geocoding/v1.. @params [Hash] params to be sent with the request. See open.mapquestapi.com/geocoding/ for params details.
@return [String] with geocoding response body.
# File lib/mq_reader/mq_reader.rb, line 32 def send_get_to_mapquest(path, params) self.get(BASE_URI + path, query: { key: MQReader.configuration.api_key}.merge!(params)).body end
Turns underscore keys into mapquest’s camelized keys I belive a good ruby api wrapper should let the developer write in a rubyish way. Mapquest accepts options that are camelcased and start with a lowercase letter.
@param [Hash] options to turn into mapquest’s key format
@return [Hash] options hash with mapquest’s key format
# File lib/mq_reader/mq_reader.rb, line 43 def to_mapquest_notation(options) Hash[options.map{ |k, v| [camelize_string(k.to_s), v] }] end