Class: Consumerable::Connection
- Inherits:
-
Object
- Object
- Consumerable::Connection
- Defined in:
- lib/consumerable/connection.rb
Class Method Summary collapse
- .connection ⇒ Object
- .delete(path, options = {}) ⇒ Object
- .get(path, options = {}) ⇒ Object
- .patch(path, options = {}) ⇒ Object
- .post(path, options = {}) ⇒ Object
Class Method Details
.connection ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/consumerable/connection.rb', line 25 def self.connection Faraday::Connection.new( url: Consumerable.configuration.endpoint, headers: { accept: Consumerable.configuration.accept_header, content_type: Consumerable.configuration.content_type } ) do |builder| builder.request Consumerable.configuration.content_type builder.response Consumerable.configuration.content_type builder.response :raise_error builder.use Faraday::Response::Mashify builder.adapter :typhoeus end.tap do |connection| if Consumerable.configuration.basic_auth_username connection.basic_auth( Consumerable.configuration.basic_auth_username, Consumerable.configuration.basic_auth_password ) end end end |
.delete(path, options = {}) ⇒ Object
21 22 23 |
# File 'lib/consumerable/connection.rb', line 21 def self.delete(path, = {}) connection.delete(path, ).success? end |
.get(path, options = {}) ⇒ Object
6 7 8 |
# File 'lib/consumerable/connection.rb', line 6 def self.get(path, = {}) connection.get(path, ).body end |
.patch(path, options = {}) ⇒ Object
17 18 19 |
# File 'lib/consumerable/connection.rb', line 17 def self.patch(path, = {}) connection.patch(path, ).success? end |
.post(path, options = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/consumerable/connection.rb', line 10 def self.post(path, = {}) Consumerable.configuration.logger.info( "POSTing #{} to #{path}" ) connection.post(path, ).body end |