Class: Async::REST::Wrapper::Form

Inherits:
Generic
  • Object
show all
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

Methods inherited from Generic

#process_response, #wrap_response

Constructor Details

#initialize(content_types = DEFAULT_CONTENT_TYPES) ⇒ Form

Returns a new instance of Form.



35
36
37
# File 'lib/async/rest/wrapper/form.rb', line 35

def initialize(content_types = DEFAULT_CONTENT_TYPES)
	@content_types = content_types
end

Instance Method Details

#parser_for(response) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/async/rest/wrapper/form.rb', line 53

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



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/async/rest/wrapper/form.rb', line 39

def prepare_request(payload, headers)
	@content_types.each_key do |key|
		headers.add('accept', key)
	end
	
	if payload
		headers['content-type'] = URLEncoded::APPLICATION_FORM_URLENCODED
		
		::Protocol::HTTP::Body::Buffered.new([
			::Protocol::HTTP::URL.encode(payload)
		])
	end
end