Class: Async::REST::Wrapper::URLEncoded
- Inherits:
-
Object
- Object
- Async::REST::Wrapper::URLEncoded
- Defined in:
- lib/async/rest/wrapper/url_encoded.rb
Defined Under Namespace
Classes: Parser
Constant Summary collapse
- APPLICATION_FORM_URLENCODED =
"application/x-www-form-urlencoded".freeze
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
Instance Method Summary collapse
-
#initialize(content_type = APPLICATION_FORM_URLENCODED) ⇒ URLEncoded
constructor
A new instance of URLEncoded.
- #prepare_request(payload, headers) ⇒ Object
- #process_response(request, response) ⇒ Object
- #split(*args) ⇒ Object
Constructor Details
#initialize(content_type = APPLICATION_FORM_URLENCODED) ⇒ URLEncoded
Returns a new instance of URLEncoded.
32 33 34 |
# File 'lib/async/rest/wrapper/url_encoded.rb', line 32 def initialize(content_type = APPLICATION_FORM_URLENCODED) @content_type = content_type end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
36 37 38 |
# File 'lib/async/rest/wrapper/url_encoded.rb', line 36 def content_type @content_type end |
Instance Method Details
#prepare_request(payload, headers) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/async/rest/wrapper/url_encoded.rb', line 42 def prepare_request(payload, headers) headers['accept'] ||= @content_type if payload headers['content-type'] = @content_type HTTP::Body::Buffered.new([ ::Protocol::HTTP::URL.encode(payload) ]) end end |
#process_response(request, response) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/async/rest/wrapper/url_encoded.rb', line 54 def process_response(request, response) if content_type = response.headers['content-type'] if content_type.start_with? @content_type if body = response.body response.body = Parser.new(body) end else warn "Unknown content type: #{content_type}!" end end return response end |
#split(*args) ⇒ Object
38 39 40 |
# File 'lib/async/rest/wrapper/url_encoded.rb', line 38 def split(*args) @content_type.split end |