Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Created April 7, 2015 15:54
Show Gist options
  • Save warmwaffles/ae7155ecd149c9dfa847 to your computer and use it in GitHub Desktop.
Save warmwaffles/ae7155ecd149c9dfa847 to your computer and use it in GitHub Desktop.
class BaseConnection
# @return [Faraday::Connection]
def connection
raise(NotImplementedError, 'not implemented')
end
def get(path, args={}, &block)
request(args.merge(method: :get, url: path), &block)
end
def post(path, args={}, &block)
request(args.merge(method: :post, url: path), &block)
end
def put(path, args={}, &block)
request(args.merge(method: :put, url: path), &block)
end
def patch(path, args={}, &block)
request(args.merge(method: :patch, url: path), &block)
end
def delete(path, args={}, &block)
request(args.merge(method: :delete, url: path), &block)
end
def head(path, args={}, &block)
request(args.merge(method: :head, url: path), &block)
end
def options(path, args={}, &block)
request(args.merge(method: :options, url: path), &block)
end
def request(args={}, &block)
connection.run_request(args[:method], args[:url], args[:body], args[:headers]) do |request|
request.params.update(args[:params]) if args[:params]
yield(request) if block
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment