Permalink
Browse files

Extracted follow_url to Behaviour::Helpers

  • Loading branch information...
1 parent bbf9a4f commit a7b75bd0fd452c448a177eabe732cada9e940031 Roger Leite committed May 6, 2012
Showing with 15 additions and 10 deletions.
  1. +4 −8 lib/restfolia/http.rb
  2. +10 −0 lib/restfolia/http/behaviour.rb
  3. +1 −2 samples/http_behaviour.rb
View
@@ -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)
@@ -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.
@@ -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

0 comments on commit a7b75bd

Please sign in to comment.