Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Celestino Gomes committed Sep 20, 2013
1 parent e14e151 commit 3bdf427
Showing 1 changed file with 15 additions and 32 deletions.
47 changes: 15 additions & 32 deletions lib/charging/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def basic_credential_for(user, password = nil)
"Basic #{credential}"
end

def should_follow_redirect
def should_follow_redirect(follow = true)
proc { |response, request, result, &block|
if [301, 302, 307].include? response.code
if follow && [301, 302, 307].include?(response.code)
response.follow_redirection(request, result, &block)
else
response.return!(request, result, &block)
Expand All @@ -59,41 +59,24 @@ def should_follow_redirect
def request_with_body(method, path, body, params, token, follow = true)
path = charging_path(path) unless path.start_with?('http')

if follow === :no_follow
RestClient.send(
method,
path,
encoded_body(body),
{params: params}.merge(common_params(token))
)
else
RestClient.send(
method,
path,
encoded_body(body),
{params: params}.merge(common_params(token)),
&should_follow_redirect
)
end
RestClient.send(
method,
path,
encoded_body(body),
{params: params}.merge(common_params(token)),
&should_follow_redirect(follow != :no_follow)
)
end

def request_without_body(method, path, params, token, follow = true)
path = charging_path(path) unless path.start_with?('http')

if follow === :no_follow
RestClient.send(
method,
path,
{params: params}.merge(common_params(token))
)
else
RestClient.send(
method,
path,
{params: params}.merge(common_params(token)),
&should_follow_redirect
)
end
RestClient.send(
method,
path,
{params: params}.merge(common_params(token)),
&should_follow_redirect(follow != :no_follow)
)
end

def charging_path(path)
Expand Down

0 comments on commit 3bdf427

Please sign in to comment.