Class: Consumerable::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/consumerable/connection.rb

Class Method Summary collapse

Class Method Details

.connectionObject



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, options = {})
  connection.delete(path, options).success?
end

.get(path, options = {}) ⇒ Object



6
7
8
# File 'lib/consumerable/connection.rb', line 6

def self.get(path, options = {})
  connection.get(path, options).body
end

.patch(path, options = {}) ⇒ Object



17
18
19
# File 'lib/consumerable/connection.rb', line 17

def self.patch(path, options = {})
  connection.patch(path, options).success?
end

.post(path, options = {}) ⇒ Object



10
11
12
13
14
15
# File 'lib/consumerable/connection.rb', line 10

def self.post(path, options = {})
  Consumerable.configuration.logger.info(
    "POSTing #{options} to #{path}"
  )
  connection.post(path, options).body
end