mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
29 lines
733 B
Ruby
29 lines
733 B
Ruby
class BeermappingApi
|
|
def self.places_in(city)
|
|
city = city.downcase
|
|
|
|
# gets caught by places.empty?
|
|
# TODO fix error message, No locations in ""
|
|
return "" if city == ""
|
|
|
|
Rails.cache.fetch(city, expires_in: 1.week) { get_places_in city }
|
|
end
|
|
|
|
def self.get_places_in(city)
|
|
url = "http://beermapping.com/webservice/loccity/#{key}/"
|
|
response = HTTParty.get "#{url}#{ERB::Util.url_encode(city)}"
|
|
|
|
places = response.parsed_response["bmp_locations"]["location"]
|
|
return [] if places.is_a?(Hash) && places["id"].nil?
|
|
|
|
places = [places] if places.is_a?(Hash)
|
|
places.map do |place|
|
|
Place.new(place)
|
|
end
|
|
end
|
|
|
|
def self.key
|
|
Rails.application.credentials.beermap_api_key
|
|
end
|
|
end
|