Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15409fc
commit 84c3390
Showing
5 changed files
with
55 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Restfulie | ||
module Client | ||
module Response | ||
class CacheHandler | ||
|
||
def initialize(requester) | ||
@requester = requester | ||
end | ||
|
||
def parse(host, path, http_request, request, response) | ||
Restfulie::Client.cache_provider.put([host, path], http_request, response) | ||
@requester.parse(host, path, http_request, request, response) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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) | ||
response = @requester.parse(host, path, http_request, request, response) | ||
if response.code == 201 | ||
request = Restfulie.at(response.headers['location']) | ||
request.accepts(@config.acceptable_mediatypes) if @config.acceptable_mediatypes | ||
request.get! | ||
elsif @config.raw? | ||
response | ||
elsif (!response.body.nil?) && !response.body.empty? | ||
representation = 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 |