Created
April 7, 2015 15:54
-
-
Save warmwaffles/ae7155ecd149c9dfa847 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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