Class: BeerMapping::API
- Inherits:
-
Object
- Object
- BeerMapping::API
- Defined in:
- lib/beer_mapping/API.rb
Instance Attribute Summary collapse
-
#locations ⇒ Object
readonly
Returns the value of attribute locations.
Instance Method Summary collapse
- #find_by_location(search_location) ⇒ Object
- #find_by_name(search_name) ⇒ Object
-
#initialize(api_key) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(api_key) ⇒ API
Returns a new instance of API.
5 6 7 8 |
# File 'lib/beer_mapping/API.rb', line 5 def initialize(api_key) $api_key = api_key @locations = [] end |
Instance Attribute Details
#locations ⇒ Object (readonly)
Returns the value of attribute locations.
3 4 5 |
# File 'lib/beer_mapping/API.rb', line 3 def locations @locations end |
Instance Method Details
#find_by_location(search_location) ⇒ Object
15 16 17 18 |
# File 'lib/beer_mapping/API.rb', line 15 def find_by_location(search_location) locations = open("http://beermapping.com/webservice/loccity/#{$api_key}/#{CGI.escape(search_location)}") {|f| Hpricot.XML(f) } get_locations(locations) end |
#find_by_name(search_name) ⇒ Object
10 11 12 13 |
# File 'lib/beer_mapping/API.rb', line 10 def find_by_name(search_name) locations = open("http://beermapping.com/webservice/locquery/#{$api_key}/#{CGI.escape(search_name)}") {|f| Hpricot.XML(f) } get_locations(locations) end |