Class: Consumerable::Connection

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

Class Method Summary collapse

Class Method Details

.connectionObject



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, options = {})
  Consumerable.log "DELETE #{path} with #{options}"
  connection.delete(path, options).success?
end

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



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

def self.get(path, options = {})
  Consumerable.log "GET #{path} with #{options}"
  connection.get(path, options).body
end

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



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

def self.patch(path, options = {})
  Consumerable.log "PATCH #{path} with #{options}"
  connection.patch(path, options).success?
end

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



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

def self.post(path, options = {})
  Consumerable.log "POST #{path} with #{options}"
  connection.post(path, options).tap do |response|
    Consumerable.log "RESPONDED WITH: #{response.body}"
  end.body
end