Class: Hanko::Connection
- Inherits:
-
Object
- Object
- Hanko::Connection
- Defined in:
- lib/hanko/connection.rb
Overview
Low-level HTTP wrapper around Faraday.
Configures the Faraday connection with authentication headers, timeouts, and the Middleware::RaiseError middleware.
Instance Attribute Summary collapse
-
#connection ⇒ Faraday::Connection
readonly
The underlying Faraday connection.
Instance Method Summary collapse
-
#delete(path, params = {}) ⇒ Faraday::Response
Performs an HTTP DELETE request.
-
#get(path, params = {}) ⇒ Faraday::Response
Performs an HTTP GET request.
-
#initialize(config, adapter: nil) ⇒ Connection
constructor
Builds a new Connection from the given configuration.
-
#patch(path, body = {}) ⇒ Faraday::Response
Performs an HTTP PATCH request with a JSON body.
-
#post(path, body = {}) ⇒ Faraday::Response
Performs an HTTP POST request with a JSON body.
-
#put(path, body = {}) ⇒ Faraday::Response
Performs an HTTP PUT request with a JSON body.
Constructor Details
#initialize(config, adapter: nil) ⇒ Connection
Builds a new Connection from the given configuration.
21 22 23 |
# File 'lib/hanko/connection.rb', line 21 def initialize(config, adapter: nil) @connection = build_connection(config, adapter) end |
Instance Attribute Details
#connection ⇒ Faraday::Connection (readonly)
Returns the underlying Faraday connection.
14 15 16 |
# File 'lib/hanko/connection.rb', line 14 def connection @connection end |
Instance Method Details
#delete(path, params = {}) ⇒ Faraday::Response
Performs an HTTP DELETE request.
66 67 68 |
# File 'lib/hanko/connection.rb', line 66 def delete(path, params = {}) connection.delete(path, params) end |
#get(path, params = {}) ⇒ Faraday::Response
Performs an HTTP GET request.
30 31 32 |
# File 'lib/hanko/connection.rb', line 30 def get(path, params = {}) connection.get(path, params) end |
#patch(path, body = {}) ⇒ Faraday::Response
Performs an HTTP PATCH request with a JSON body.
57 58 59 |
# File 'lib/hanko/connection.rb', line 57 def patch(path, body = {}) connection.patch(path, JSON.generate(body)) end |
#post(path, body = {}) ⇒ Faraday::Response
Performs an HTTP POST request with a JSON body.
39 40 41 |
# File 'lib/hanko/connection.rb', line 39 def post(path, body = {}) connection.post(path, JSON.generate(body)) end |
#put(path, body = {}) ⇒ Faraday::Response
Performs an HTTP PUT request with a JSON body.
48 49 50 |
# File 'lib/hanko/connection.rb', line 48 def put(path, body = {}) connection.put(path, JSON.generate(body)) end |