-
Notifications
You must be signed in to change notification settings - Fork 43
/
unmarshall_handler.rb
29 lines (27 loc) · 1.06 KB
/
unmarshall_handler.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Restfulie
module Client
module Response
class UnmarshallHandler
def initialize(config, requester)
@config = config
@requester = requester
end
# parses the http response.
# first checks if its a 201, redirecting to the resource location.
# otherwise check if its a raw request, returning the content itself.
# finally, tries to parse the content with a mediatype handler or returns the response itself.
def parse(host, path, http_request, request, response, method)
response = @requester.parse(host, path, http_request, request, response, method)
if @config.raw?
response
elsif (!response.body.nil?) && !response.body.empty?
representation = Restfulie::Client::HTTP::RequestMarshaller.content_type_for(response.headers['content-type']) || Restfulie::Common::Representation::Generic.new
representation.unmarshal(response.body)
else
response
end
end
end
end
end
end