Class: Dina::EndpointConnection
- Inherits:
-
Object
- Object
- Dina::EndpointConnection
- Defined in:
- lib/dina/endpoints/endpoint_connection.rb
Instance Attribute Summary collapse
-
#faraday ⇒ Object
readonly
Returns the value of attribute faraday.
Instance Method Summary collapse
- #custom_headers ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ EndpointConnection
constructor
A new instance of EndpointConnection.
- #run(request_method, path, params: nil, headers: {}, body: nil) ⇒ Object
- #use(*args) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ EndpointConnection
Returns a new instance of EndpointConnection.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dina/endpoints/endpoint_connection.rb', line 7 def initialize( = {}) = .slice(:proxy, :ssl, :request, :headers, :params) = Array(.fetch(:adapter, Faraday.default_adapter)) @faraday = Faraday.new(Dina.config.endpoint_url, ) do |builder| builder.request :json builder.response :json builder.adapter(*) end yield(self) if block_given? end |
Instance Attribute Details
#faraday ⇒ Object (readonly)
Returns the value of attribute faraday.
5 6 7 |
# File 'lib/dina/endpoints/endpoint_connection.rb', line 5 def faraday @faraday end |
Instance Method Details
#custom_headers ⇒ Object
19 20 21 |
# File 'lib/dina/endpoints/endpoint_connection.rb', line 19 def custom_headers { content_type: "application/json", authorization: Dina.header } end |
#run(request_method, path, params: nil, headers: {}, body: nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/dina/endpoints/endpoint_connection.rb', line 23 def run(request_method, path, params: nil, headers: {}, body: nil) response = faraday.run_request(request_method, path, body, headers) do |request| request.params.update(params) if params request.headers = custom_headers end response.body end |
#use(*args) ⇒ Object
31 |
# File 'lib/dina/endpoints/endpoint_connection.rb', line 31 def use(*args); end |