Skip to content

Commit

Permalink
use faraday to build Client#authorize_url and Client#access_token_url
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Apr 22, 2010
1 parent d5ac162 commit a9c1043
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -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
Expand Down
23 changes: 9 additions & 14 deletions 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
Expand All @@ -16,26 +16,21 @@ class Client
# <tt>:access_token_path</tt> :: Specify the path to the access token endpoint.
# <tt>:access_token_url</tt> :: 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 = {})
Expand Down
1 change: 1 addition & 0 deletions 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'
Expand Down

0 comments on commit a9c1043

Please sign in to comment.