Skip to content

Commit

Permalink
fix bugs with getting request and access tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
nullstyle committed May 17, 2008
1 parent 645500b commit f4d7eb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/satisfaction.rb
Expand Up @@ -91,7 +91,9 @@ def set_token(token, secret)
end

def request_token
response = CGI.parse(@loader.get("#{options[:request_token_url]}", :force => true, :consumer => @consumer, :token => nil))
result, body = *@loader.get("#{options[:request_token_url]}", :force => true, :consumer => @consumer, :token => nil)
raise "Could not retrieve request token" unless result == :ok
response = CGI.parse(body)
OAuth::Token.new(response["oauth_token"], response["oauth_token_secret"])
end

Expand All @@ -100,7 +102,9 @@ def authorize_url(token)
end

def access_token(token)
response = CGI.parse(@loader.get("#{options[:access_token_url]}", :force => true, :consumer => @consumer, :token => token))
result, body = *@loader.get("#{options[:access_token_url]}", :force => true, :consumer => @consumer, :token => token)
raise "Could not retrieve access token" unless result == :ok
response = CGI.parse(body)
OAuth::Token.new(response["oauth_token"], response["oauth_token_secret"])
end

Expand Down
6 changes: 3 additions & 3 deletions lib/satisfaction/loader.rb
Expand Up @@ -34,7 +34,7 @@ def get(url, options = {})
end

http = Net::HTTP.new(uri.host, uri.port)
add_authentication(request, options)
add_authentication(request, http, options)
response = execute(http, request)

case response
Expand Down Expand Up @@ -73,7 +73,7 @@ def post(url, options)
request.set_form_data(form)

http = Net::HTTP.new(uri.host, uri.port)
add_authentication(request, options)
add_authentication(request, http, options)
response = execute(http, request)

case response
Expand Down Expand Up @@ -104,7 +104,7 @@ def get_uri(url)
end
end

def add_authentication(request, options)
def add_authentication(request, http, options)
if options[:user]
request.basic_auth(options[:user], options[:password])
elsif options[:consumer]
Expand Down

0 comments on commit f4d7eb5

Please sign in to comment.