Class: The86::Client::Connection
- Inherits:
-
Object
- Object
- The86::Client::Connection
- Defined in:
- lib/the86-client/connection.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #delete(options) ⇒ Object
- #get(options) ⇒ Object
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #patch(options) ⇒ Object
- #post(options) ⇒ Object
-
#prepend(*parameters) ⇒ Object
Insert a Faraday middleware at the top of the chain.
Constructor Details
#initialize ⇒ Connection
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_adapter ⇒ Object
13 14 15 |
# File 'lib/the86-client/connection.rb', line 13 def faraday_adapter @faraday_adapter || Faraday.default_adapter end |
Instance Attribute Details
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
19 20 21 |
# File 'lib/the86-client/connection.rb', line 19 def open_timeout @open_timeout end |
#timeout ⇒ Object
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() dispatch(:delete, ) end |
#get(options) ⇒ Object
39 40 41 |
# File 'lib/the86-client/connection.rb', line 39 def get() dispatch(:get, ) end |
#patch(options) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/the86-client/connection.rb', line 43 def patch() # TODO: extract HTTP method override into Faraday middleware. [:headers] ||= {} [:headers]["X-Http-Method-Override"] = "patch" dispatch(:post, ) end |
#post(options) ⇒ Object
50 51 52 |
# File 'lib/the86-client/connection.rb', line 50 def post() dispatch(:post, ) 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 |