Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extracted follow_url to Behaviour::Helpers

  • Loading branch information...
commit a7b75bd0fd452c448a177eabe732cada9e940031 1 parent bbf9a4f
Roger Leite authored
View
12 lib/restfolia/http.rb
@@ -21,8 +21,7 @@ module Restfolia
# json_parsed = helpers.parse_json(http_response)
# Restfolia.create_resource(json_parsed)
# elsif (location = http_response["location"])
- # http_resp = Request.do_request(:get, location)
- # Restfolia::HTTP.response_by_status_code(http_resp)
+ # helpers.follow_url(location)
# else
# nil
# end
@@ -31,8 +30,7 @@ module Restfolia
# # 3xx
# on(300...400) do |http_response|
# if (location = http_response["location"])
- # http_resp = Request.do_request(:get, location)
- # Restfolia::HTTP.response_by_status_code(http_resp)
+ # helpers.follow_url(location)
# else
# msg_error = "HTTP status #{http_response.code} not supported"
# raise Restfolia::ResponseError.new(msg_error, caller, http_response)
@@ -103,8 +101,7 @@ def self.behaviours(&block)
json_parsed = helpers.parse_json(http_response)
Restfolia.create_resource(json_parsed)
elsif (location = http_response["location"])
- http_resp = Request.do_request(:get, location)
- Restfolia::HTTP.response_by_status_code(http_resp)
+ helpers.follow_url(location)
else
nil
end
@@ -113,8 +110,7 @@ def self.behaviours(&block)
# 3xx
on(300...400) do |http_response|
if (location = http_response["location"])
- http_resp = Request.do_request(:get, location)
- Restfolia::HTTP.response_by_status_code(http_resp)
+ helpers.follow_url(location)
else
msg_error = "HTTP status #{http_response.code} not supported"
raise Restfolia::ResponseError.new(msg_error, caller, http_response)
View
10 lib/restfolia/http/behaviour.rb
@@ -35,6 +35,16 @@ def parse_json(http_response)
end
end
+ # Public: Request url with GET and forwards to Restfolia::HTTP.
+ #
+ # url - String. Ex: http://service.com/resources
+ #
+ # Returns what Restfolia::HTTP.response_by_status_code returns.
+ def follow_url(url)
+ http_resp = Request.do_request(:get, url)
+ Restfolia::HTTP.response_by_status_code(http_resp)
+ end
+
end
# Public: Responsible to store behaviours. See #behaviours for details.
View
3  samples/http_behaviour.rb
@@ -21,8 +21,7 @@
json_parsed = helpers.parse_json(http_response)
Restfolia.create_resource(json_parsed)
elsif (location = http_response["location"])
- http_resp = do_request(:get, location)
- response_by_status_code(http_resp)
+ helpers.follow_url(location)
else
nil
end
Please sign in to comment.
Something went wrong with that request. Please try again.