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.
36 37 38 39 40 41 42 43 |
# File 'lib/kamelopard/geocode.rb', line 36 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.
34 35 36 |
# File 'lib/kamelopard/geocode.rb', line 34 def api_key @api_key end |
#response_format ⇒ Object (readonly)
Returns the value of attribute response_format.
34 35 36 |
# File 'lib/kamelopard/geocode.rb', line 34 def response_format @response_format end |
Instance Method Details
#getURL(params) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/kamelopard/geocode.rb', line 45 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
52 53 54 |
# File 'lib/kamelopard/geocode.rb', line 52 def lookup(address) getURL(processParam(address, 'address').join('&')) end |