Class: Async::REST::Wrapper::JSON
- Defined in:
- lib/async/rest/wrapper/json.rb
Defined Under Namespace
Classes: Parser
Constant Summary collapse
- APPLICATION_JSON =
"application/json".freeze
- APPLICATION_JSON_STREAM =
"application/json; boundary=NL".freeze
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
Instance Method Summary collapse
-
#initialize(content_type = APPLICATION_JSON) ⇒ JSON
constructor
A new instance of JSON.
- #parser_for(response) ⇒ Object
- #prepare_request(request, payload) ⇒ Object
- #split(*arguments) ⇒ Object
Methods inherited from Generic
#call, #process_response, #response_for, #retry_after_duration, #wrap_response
Constructor Details
#initialize(content_type = APPLICATION_JSON) ⇒ JSON
Returns a new instance of JSON.
20 21 22 |
# File 'lib/async/rest/wrapper/json.rb', line 20 def initialize(content_type = APPLICATION_JSON) @content_type = content_type end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
24 25 26 |
# File 'lib/async/rest/wrapper/json.rb', line 24 def content_type @content_type end |
Instance Method Details
#parser_for(response) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/async/rest/wrapper/json.rb', line 48 def parser_for(response) if content_type = response.headers["content-type"] if content_type.start_with? @content_type return Parser end end return super end |
#prepare_request(request, payload) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/async/rest/wrapper/json.rb', line 30 def prepare_request(request, payload) request.headers["accept"] ||= @content_type if payload request.headers["content-type"] = @content_type request.body = ::Protocol::HTTP::Body::Buffered.new([ ::JSON.dump(payload) ]) end end |
#split(*arguments) ⇒ Object
26 27 28 |
# File 'lib/async/rest/wrapper/json.rb', line 26 def split(*arguments) @content_type.split end |