Class: JSONAPI::Consumer::Connection
- Inherits:
-
Object
- Object
- JSONAPI::Consumer::Connection
- Defined in:
- lib/jsonapi/consumer/connection.rb
Instance Attribute Summary collapse
-
#faraday ⇒ Object
readonly
Returns the value of attribute faraday.
Instance Method Summary collapse
- #delete(middleware) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Connection
constructor
A new instance of Connection.
- #run(request_method, path, params = {}, headers = {}) ⇒ Object
-
#use(middleware, *args, &block) ⇒ Object
insert middleware before ParseJson - middleware executed in reverse order - inserted middleware will run after json parsed.
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jsonapi/consumer/connection.rb', line 6 def initialize( = {}) site = .fetch(:site) = .slice(:proxy, :ssl, :request, :headers, :params) = Array(.fetch(:adapter, Faraday.default_adapter)) @faraday = Faraday.new(site, ) do |builder| builder.request :json builder.use Middleware::JsonRequest builder.use Middleware::Status builder.use Middleware::ParseJson builder.adapter(*) end yield(self) if block_given? end |
Instance Attribute Details
#faraday ⇒ Object (readonly)
Returns the value of attribute faraday.
4 5 6 |
# File 'lib/jsonapi/consumer/connection.rb', line 4 def faraday @faraday end |
Instance Method Details
#delete(middleware) ⇒ Object
27 28 29 |
# File 'lib/jsonapi/consumer/connection.rb', line 27 def delete(middleware) faraday.builder.delete(middleware) end |
#run(request_method, path, params = {}, headers = {}) ⇒ Object
31 32 33 |
# File 'lib/jsonapi/consumer/connection.rb', line 31 def run(request_method, path, params = {}, headers = {}) faraday.send(request_method, path, params, headers) end |
#use(middleware, *args, &block) ⇒ Object
insert middleware before ParseJson - middleware executed in reverse order -
inserted middleware will run after json parsed
22 23 24 25 |
# File 'lib/jsonapi/consumer/connection.rb', line 22 def use(middleware, *args, &block) return if faraday.builder.locked? faraday.builder.insert_before(Middleware::ParseJson, middleware, *args, &block) end |