Class: Async::REST::Wrapper::Form
- Defined in:
- lib/async/rest/wrapper/form.rb
Constant Summary collapse
- DEFAULT_CONTENT_TYPES =
{ JSON::APPLICATION_JSON => JSON::Parser, URLEncoded::APPLICATION_FORM_URLENCODED => URLEncoded::Parser, }
Instance Method Summary collapse
-
#initialize(content_types = DEFAULT_CONTENT_TYPES) ⇒ Form
constructor
A new instance of Form.
- #parser_for(response) ⇒ Object
- #prepare_request(payload, headers) ⇒ Object
Methods inherited from Generic
#process_response, #wrap_response
Constructor Details
#initialize(content_types = DEFAULT_CONTENT_TYPES) ⇒ Form
Returns a new instance of Form.
33 34 35 |
# File 'lib/async/rest/wrapper/form.rb', line 33 def initialize(content_types = DEFAULT_CONTENT_TYPES) @content_types = content_types end |
Instance Method Details
#parser_for(response) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/async/rest/wrapper/form.rb', line 49 def parser_for(response) if content_type = response.headers['content-type'] if parser = @content_types[content_type] return parser end end return super end |
#prepare_request(payload, headers) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/async/rest/wrapper/form.rb', line 37 def prepare_request(payload, headers) headers['accept'] ||= @content_types.keys if payload headers['content-type'] = URLEncoded::APPLICATION_FORM_URLENCODED ::Protocol::HTTP::Body::Buffered.new([ ::Protocol::HTTP::URL.encode(payload) ]) end end |