Class: YaYahooGeocode::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ya_yahoo_geocode/client.rb

Constant Summary collapse

@@YAHOO_GEOCODE_ENDPOINT =
'http://where.yahooapis.com/geocode'
@@YAHOO_PLACES_ENDPOINT =
'http://where.yahooapis.com/v1/place'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/ya_yahoo_geocode/client.rb', line 9

def initialize(app_id = nil) 
  self.app_id = app_id 
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



7
8
9
# File 'lib/ya_yahoo_geocode/client.rb', line 7

def app_id
  @app_id
end

Instance Method Details

#get_place_by_woeid(woeid) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/ya_yahoo_geocode/client.rb', line 33

def get_place_by_woeid(woeid) 
  begin 
    url = @@YAHOO_PLACES_ENDPOINT + '/' + woeid.to_s + '?appid=' + app_id.to_s #app_id is required
    response = do_http_get(url)
    response = Nori.parse(response)
    response['place']
  rescue Exception => e 
    raise "Error searching for location: #{woeid.inspect}.  Got error:  #{e.message}"
  end 
end

#search_for_place(search_terms) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ya_yahoo_geocode/client.rb', line 13

def search_for_place(search_terms)
  begin 
    url = @@YAHOO_GEOCODE_ENDPOINT + '?q=' + URI::escape(search_terms)
    url += '&appid=' + app_id if app_id #app_id is optional for this service call
    do_search(url)
  rescue Exception => e 
    raise "Error searching for location: #{search_terms.inspect}.  Got error:  #{e.message}"
  end 
end

#search_for_place_by_location(lat, lon) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/ya_yahoo_geocode/client.rb', line 23

def search_for_place_by_location(lat, lon)
  begin 
    url = @@YAHOO_GEOCODE_ENDPOINT + '?q=' + lat.to_s + '+' + lon.to_s + '&gflags=R'
    url += '&appid=' + app_id if app_id #app_id is optional for this service call
    do_search(url)
  rescue Exception => e 
    raise "Error searching for location: #{search_terms.inspect}.  Got error:  #{e.message}"
  end 
end