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
6eb3361
commit 15409fc
Showing
6 changed files
with
95 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Restfulie | ||
module Client | ||
module Response#:nodoc: | ||
autoload :EnhanceResponse, 'restfulie/client/response/enhance_response' | ||
autoload :IgnoreError, 'restfulie/client/response/ignore_error' | ||
autoload :CatchAndThrow, 'restfulie/client/response/catch_and_throw' | ||
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,43 @@ | ||
module Restfulie | ||
module Client | ||
module Response | ||
class CatchAndThrow | ||
def parse(host, path, http_request, request, response) | ||
case response.code | ||
when 100..299 | ||
response | ||
when 300..399 | ||
raise Error::Redirection.new(request, response) | ||
when 400 | ||
raise Error::BadRequest.new(request, response) | ||
when 401 | ||
raise Error::Unauthorized.new(request, response) | ||
when 403 | ||
raise Error::Forbidden.new(request, response) | ||
when 404 | ||
raise Error::NotFound.new(request, response) | ||
when 405 | ||
raise Error::MethodNotAllowed.new(request, response) | ||
when 407 | ||
raise Error::ProxyAuthenticationRequired.new(request, response) | ||
when 409 | ||
raise Error::Conflict.new(request, response) | ||
when 410 | ||
raise Error::Gone.new(request, response) | ||
when 412 | ||
raise Error::PreconditionFailed.new(request, response) | ||
when 402, 406, 408, 411, 413..499 | ||
raise Error::ClientError.new(request, response) | ||
when 501 | ||
raise Error::NotImplemented.new(request, response) | ||
when 500, 502..599 | ||
raise Error::ServerError.new(request, response) | ||
else | ||
raise Error::UnknownError.new(request, response) | ||
end | ||
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,21 @@ | ||
module Restfulie | ||
module Client | ||
module Response | ||
|
||
class EnhanceResponse | ||
def initialize(requester) | ||
@requester = requester | ||
end | ||
|
||
def parse(host, path, http_request, request, response) | ||
resp = @requester.parse(host, path, http_request, request, response) | ||
unless resp.kind_of? ResponseHolder | ||
resp.extend(ResponseHolder) | ||
resp.response = response | ||
end | ||
resp | ||
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,21 @@ | ||
module Restfulie | ||
module Client | ||
module Response | ||
class IgnoreError | ||
|
||
def initialize(requester) | ||
@requester = requester | ||
end | ||
|
||
def parse(host, path, http_request, request, response) | ||
begin | ||
@requester.parse(host, path, http_request, request, response) | ||
rescue Error::RESTError => se | ||
se | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |