Class: Async::REST::Wrapper::URLEncoded

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

Instance Method Summary collapse

Methods inherited from Generic

#process_response, #wrap_response

Constructor Details

#initialize(content_type = APPLICATION_FORM_URLENCODED) ⇒ URLEncoded

Returns a new instance of URLEncoded.



36
37
38
# File 'lib/async/rest/wrapper/url_encoded.rb', line 36

def initialize(content_type = APPLICATION_FORM_URLENCODED)
	@content_type = content_type
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



40
41
42
# File 'lib/async/rest/wrapper/url_encoded.rb', line 40

def content_type
  @content_type
end

Instance Method Details

#parser_for(response) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/async/rest/wrapper/url_encoded.rb', line 64

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(payload, headers) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/async/rest/wrapper/url_encoded.rb', line 46

def prepare_request(payload, headers)
	headers['accept'] ||= @content_type
	
	if payload
		headers['content-type'] = @content_type
		
		::Protocol::HTTP::Body::Buffered.new([
			::Protocol::HTTP::URL.encode(payload)
		])
	end
end

#split(*arguments) ⇒ Object



42
43
44
# File 'lib/async/rest/wrapper/url_encoded.rb', line 42

def split(*arguments)
	@content_type.split
end