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.



34
35
36
# File 'lib/async/rest/wrapper/url_encoded.rb', line 34

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.



38
39
40
# File 'lib/async/rest/wrapper/url_encoded.rb', line 38

def content_type
  @content_type
end

Instance Method Details

#parser_for(response) ⇒ Object



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

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



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

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(*args) ⇒ Object



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

def split(*args)
	@content_type.split
end