Class: GoogleGeocoder

Inherits:
Geocoder show all
Defined in:
lib/kamelopard/geocode.rb

Instance Attribute Summary collapse

Attributes inherited from Geocoder

#host, #params, #path

Instance Method Summary collapse

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_keyObject (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_formatObject (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