Module: JSONAPI::Consumer::ConnectionConcern::ClassMethods
- Defined in:
- lib/jsonapi/consumer/resource/connection_concern.rb
Instance Method Summary collapse
-
#_connection(reload = false) ⇒ Object
:nodoc:.
-
#_run_request(query_object) ⇒ Object
:nodoc:.
- #parse(response) ⇒ Object
- #parser_class ⇒ Object
Instance Method Details
#_connection(reload = false) ⇒ Object
:nodoc:
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jsonapi/consumer/resource/connection_concern.rb', line 26 def _connection(reload=false) self.connection = nil if !!reload self.connection ||= begin Faraday.new(url: self.host, ssl: self.ssl) do |conn| conn.request :json conn.request :request_headers, accept: "application/json" yield(conn) if block_given? conn.use Middleware::RequestTimeout conn.use Middleware::ParseJson conn.use Middleware::RaiseError conn.adapter Faraday.default_adapter end end end |
#_run_request(query_object) ⇒ Object
:nodoc:
21 22 23 |
# File 'lib/jsonapi/consumer/resource/connection_concern.rb', line 21 def _run_request(query_object) parse(_connection.send(query_object.request_method, query_object.path, query_object.params, query_object.headers)) end |
#parse(response) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/jsonapi/consumer/resource/connection_concern.rb', line 10 def parse(response) parser = parser_class.new(self, response) if response.status && response.status == 204 true else parser.build end end |
#parser_class ⇒ Object
6 7 8 |
# File 'lib/jsonapi/consumer/resource/connection_concern.rb', line 6 def parser_class @parser ||= Parser end |