From a9c10431174589e9cdbc81062da7d11a5c3c8567 Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 22 Apr 2010 11:39:24 -0400 Subject: [PATCH] use faraday to build Client#authorize_url and Client#access_token_url --- Rakefile | 1 + lib/oauth2/client.rb | 23 +++++++++-------------- spec/spec_helper.rb | 1 + 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Rakefile b/Rakefile index 017f0e01..43973dfb 100644 --- a/Rakefile +++ b/Rakefile @@ -10,6 +10,7 @@ begin gem.email = "michael@intridea.com" gem.homepage = "http://github.com/intridea/oauth2" gem.authors = ["Michael Bleigh"] + gem.add_dependency 'faraday', '~> 0.2.4' gem.add_development_dependency "rspec", ">= 1.2.9" # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings end diff --git a/lib/oauth2/client.rb b/lib/oauth2/client.rb index 8b5b114a..4f61bdfa 100644 --- a/lib/oauth2/client.rb +++ b/lib/oauth2/client.rb @@ -1,8 +1,8 @@ -require 'net/https' +require 'faraday' module OAuth2 class Client - attr_accessor :id, :secret, :site, :options + attr_accessor :id, :secret, :site, :connection, :options # Instantiate a new OAuth 2.0 client using the # client ID and client secret registered to your @@ -16,26 +16,21 @@ class Client # :access_token_path :: Specify the path to the access token endpoint. # :access_token_url :: Specify the full URL of the access token endpoint. def initialize(client_id, client_secret, opts = {}) - self.id = client_id - self.secret = client_secret - self.site = opts.delete(:site) if opts[:site] - self.options = opts + self.id = client_id + self.secret = client_secret + self.site = opts.delete(:site) if opts[:site] + self.options = opts + self.connection = Faraday::Connection.new(site) end def authorize_url return options[:authorize_url] if options[:authorize_url] - - uri = URI.parse(site) - uri.path = options[:authorize_path] || "/oauth/authorize" - uri.to_s + connection.build_url(options[:authorize_path] || "/oauth/authorize").to_s end def access_token_url return options[:access_token_url] if options[:access_token_url] - - uri = URI.parse(site) - uri.path = options[:access_token_path] || "/oauth/access_token" - uri.to_s + connection.build_url(options[:access_token_path] || "/oauth/access_token").to_s end def request(verb, url_or_path, params = {}, headers = {}) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 141488f9..63569be8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require 'rubygems' require 'oauth2' require 'spec' require 'spec/autorun'