Class: Async::REST::Wrapper::JSON

Inherits:
Generic
  • Object
show all
Defined in:
lib/async/rest/wrapper/json.rb

Defined Under Namespace

Classes: Parser

Constant Summary collapse

APPLICATION_JSON =
"application/json".freeze
APPLICATION_JSON_STREAM =
"application/json; boundary=NL".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#process_response, #wrap_response

Constructor Details

#initialize(content_type = APPLICATION_JSON) ⇒ JSON

Returns a new instance of JSON.



37
38
39
# File 'lib/async/rest/wrapper/json.rb', line 37

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

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



41
42
43
# File 'lib/async/rest/wrapper/json.rb', line 41

def content_type
  @content_type
end

Instance Method Details

#parser_for(response) ⇒ Object



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

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



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

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

#split(*args) ⇒ Object



43
44
45
# File 'lib/async/rest/wrapper/json.rb', line 43

def split(*args)
	@content_type.split
end