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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/consumerable/connection.rb', line 28 def self.connection Faraday::Connection.new( url: Consumerable.configuration.endpoint, headers: { accept: Consumerable.configuration.accept_header, content_type: Consumerable. content_type_string(Consumerable.configuration.content_type) } ) do |builder| builder.request Consumerable.configuration.content_type builder.response Consumerable.configuration.content_type 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
23 24 25 26 |
# File 'lib/consumerable/connection.rb', line 23 def self.delete(path, = {}) Consumerable.log "DELETE #{path} with #{}" connection.delete(path, ).success? end |
.get(path, options = {}) ⇒ Object
6 7 8 9 |
# File 'lib/consumerable/connection.rb', line 6 def self.get(path, = {}) Consumerable.log "GET #{path} with #{}" connection.get(path, ).body end |
.patch(path, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/consumerable/connection.rb', line 18 def self.patch(path, = {}) Consumerable.log "PATCH #{path} with #{}" connection.patch(path, ).success? end |
.post(path, options = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/consumerable/connection.rb', line 11 def self.post(path, = {}) Consumerable.log "POST #{path} with #{}" connection.post(path, ).tap do |response| Consumerable.log "RESPONDED WITH: #{response.body}" end.body end |