Sha256: 3691a11d7e0135a4a7f298776dbbf3a7d616571101ca9e882783153e397bb52b
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
require "gogo_maps/version" require 'faraday' require 'json' module GogoMaps # @param Hash opts - to support below Ruby1.9x. def self.get(opts={}) fail 'Should provide either address or latlng' unless opts[:address] || opts[:latlng] GoogleMapClient.call( { language: :ja, sensor: false }.merge(opts), opts[:address] ? :to_latlng : :to_address ) end class GoogleMapClient ENDPOINT = 'http://maps.googleapis.com' @@_conn ||= Faraday.new(url: ENDPOINT) do |faraday| faraday.request :url_encoded faraday.response :logger faraday.adapter Faraday.default_adapter end def self.call(params, sym) response = @@_conn.get do |req| req.url '/maps/api/geocode/json' req.params = params end unless location = JSON.parse(response.body)['results'][0] fail 'Something wrong with Google API or your params' end case sym when :to_latlng then location['geometry']['location'] when :to_address then location['formatted_address'] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gogo_maps-0.0.1 | lib/gogo_maps.rb |