Last active
December 14, 2015 17:39
-
-
Save BrianTheCoder/5123705 to your computer and use it in GitHub Desktop.
Locu API client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Porter | |
class Locu | |
# http://dev.locu.com/documentation/ | |
DEFAULTS = {api_key: ENV['LOCU']} | |
class << self | |
%w(venue menu_item).each do |section| | |
define_method :"#{section}_search", ->(params = {}){ get("#{section}/search/", params) } | |
define_method :"#{section}_insight", ->(params = {}){ get("#{section}/insight/", params) } | |
define_method :"#{section}_info", ->(id){ get("#{section}/#{id}/") } | |
end | |
end | |
def self.get(path, params = {}) | |
client.get(path, DEFAULTS.merge(params)).body | |
end | |
protected | |
def self.client | |
@client ||= Faraday.new 'http://api.locu.com/v1_0' do |conn| | |
conn.use FaradayMiddleware::EncodeJson | |
conn.use FaradayMiddleware::ParseJson | |
conn.use FaradayMiddleware::Instrumentation | |
# conn.use Faraday::Response::Logger | |
conn.adapter Faraday.default_adapter | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment