Class: GoogleGeocoder
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#response_format ⇒ Object
readonly
Returns the value of attribute response_format.
Attributes inherited from Geocoder
Instance Method Summary collapse
- #getURL(params) ⇒ Object
-
#initialize(key, response_format = 'json') ⇒ GoogleGeocoder
constructor
A new instance of GoogleGeocoder.
- #lookup(address) ⇒ Object
Methods inherited from Geocoder
#parse_response, #processParam
Constructor Details
#initialize(key, response_format = 'json') ⇒ GoogleGeocoder
Returns a new instance of GoogleGeocoder.
37 38 39 40 41 42 43 44 |
# File 'lib/kamelopard/geocode.rb', line 37 def initialize(key, response_format = 'json') super() @proto = 'http' @host = 'maps.googleapis.com' @path = '/maps/api/geocode' @api_key = key @response_format = response_format end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
35 36 37 |
# File 'lib/kamelopard/geocode.rb', line 35 def api_key @api_key end |
#response_format ⇒ Object (readonly)
Returns the value of attribute response_format.
35 36 37 |
# File 'lib/kamelopard/geocode.rb', line 35 def response_format @response_format end |
Instance Method Details
#getURL(params) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/kamelopard/geocode.rb', line 46 def getURL(params) http = Net::HTTP.new(@host) u = URI::HTTP.build([nil, @host, nil, "#{@path}/#{@response_format}", params, nil]) JSON.parse(Net::HTTP.get u) end |
#lookup(address) ⇒ Object
53 54 55 |
# File 'lib/kamelopard/geocode.rb', line 53 def lookup(address) getURL(processParam(address, 'address').join('&')) end |