Class: The86::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/the86-client/connection.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/the86-client/connection.rb', line 21

def initialize
  # Default some basic connection options
  @timeout = 15 #seconds
  @open_timeout = 3 #seconds

  @faraday = Faraday.new(url) do |conn|
    conn.request :json
    conn.response :json
    conn.basic_auth(*Client.credentials)
    conn.adapter *self.class.faraday_adapter
  end
end

Class Attribute Details

.faraday_adapterObject



13
14
15
# File 'lib/the86-client/connection.rb', line 13

def faraday_adapter
  @faraday_adapter || Faraday.default_adapter
end

Instance Attribute Details

#open_timeoutObject

Returns the value of attribute open_timeout.



19
20
21
# File 'lib/the86-client/connection.rb', line 19

def open_timeout
  @open_timeout
end

#timeoutObject

Returns the value of attribute timeout.



19
20
21
# File 'lib/the86-client/connection.rb', line 19

def timeout
  @timeout
end

Instance Method Details

#delete(options) ⇒ Object



54
55
56
# File 'lib/the86-client/connection.rb', line 54

def delete(options)
  dispatch(:delete, options)
end

#get(options) ⇒ Object



39
40
41
# File 'lib/the86-client/connection.rb', line 39

def get(options)
  dispatch(:get, options)
end

#patch(options) ⇒ Object



43
44
45
46
47
48
# File 'lib/the86-client/connection.rb', line 43

def patch(options)
  # TODO: extract HTTP method override into Faraday middleware.
  options[:headers] ||= {}
  options[:headers]["X-Http-Method-Override"] = "patch"
  dispatch(:post, options)
end

#post(options) ⇒ Object



50
51
52
# File 'lib/the86-client/connection.rb', line 50

def post(options)
  dispatch(:post, options)
end

#prepend(*parameters) ⇒ Object

Insert a Faraday middleware at the top of the chain.



35
36
37
# File 'lib/the86-client/connection.rb', line 35

def prepend(*parameters)
  @faraday.builder.insert(0, *parameters)
end