Permalink
Browse files

Adding documentation

  • Loading branch information...
1 parent bd1d302 commit 9fa66ff7aa6a16fbf772c22b471411c0d77a1834 @roman committed Sep 16, 2009
Showing with 43 additions and 5 deletions.
  1. +4 −1 lib/warden_oauth/config.rb
  2. +29 −2 lib/warden_oauth/manager.rb
  3. +1 −1 lib/warden_oauth/strategy.rb
  4. +9 −1 lib/warden_oauth/utils.rb
@@ -1,6 +1,9 @@
module Warden
module OAuth
-
+
+ #
+ # Holds all the information of the OAuth service.
+ #
class Config
attr_accessor :provider_name
@@ -1,12 +1,30 @@
module Warden
module OAuth
+ #
+ # Holds all the extensions made to Warden::Manager in order to create OAuth
+ # consumers.
+ #
module Manager
- def self.included(base)
+ def self.included(base) #:nodoc:
base.extend(ClassMethods)
end
+ #
+ # Helps to setup a new OAuth client authentication, to get started you need to define
+ # a service name, and then on the block assign the different values required in order
+ # to boot the OAuth process.
+ # @param [Symbol] service An identifier of the OAuth service
+ #
+ # @example
+ #
+ # Warden::Manager.oauth(:twitter) do
+ # consumer_key "<YOUR CONSUMER KEY>"
+ # consumer_secret "<YOUR CONSUMER SECRET>"
+ # options :site => 'http://twitter.com'
+ # end
+ #
def oauth(service, &block)
config = Warden::OAuth::Config.new
if block_given?
@@ -23,14 +41,23 @@ def oauth(service, &block)
module ClassMethods
+ #
+ # Assigns a block that handles how to find a User given an access_token.
+ # @param [Symbol] oauth_service The identifier specified on Warden::Manager.oauth
+ #
+ # @example
+ # Warden::Manager.access_token_user_finder(:twitter) do |access_token|
+ # # Find user with access_token
+ # end
+ #
def access_token_user_finder(oauth_service, &block)
raise Warden::OAuth::AccessTokenFinderMissing.new("You need to specify a block for Warden::Manager.acess_token_user_finder") unless block_given?
raise Warden::OAuth::AccessTokenFinderMissing.new("You need to specify a block for Warden::Manager.access_token_user_finder, this must receive one parameter") if block.arity != 1
@find_user_by_access_token ||= {}
@find_user_by_access_token[oauth_service] = block
end
- def find_user_by_access_token(oauth_service, access_token)
+ def find_user_by_access_token(oauth_service, access_token) #:nodoc:
raise Warden::OAuth::AccessTokenFinderMissing.new("You need to specify a block for Warden::Manager.acess_token_user_finder") if @find_user_by_access_token.nil?
@find_user_by_access_token[oauth_service].call(access_token)
end
@@ -126,7 +126,7 @@ def authenticate!
end
- def fail!(msg)
+ def fail!(msg) #:nodoc:
self.errors.add(service_param_name.to_sym, msg)
super
end
View
@@ -1,9 +1,14 @@
module Warden
module OAuth
+ #
+ # Contains methods from Rails to avoid unnecessary dependencies
+ #
module Utils
- # Fetched from ActiveSupport to avoid dependencies
+ #
+ # Fetched from ActiveSupport::Inflector.camelize to avoid dependencies
+ #
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
if first_letter_in_uppercase
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
@@ -12,6 +17,9 @@ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
end
end
+ #
+ # Fetched from ActionController::Request to avoid dependencies
+ #
def host_with_port(request)
url = request.scheme + "://"
url << request.host

0 comments on commit 9fa66ff

Please sign in to comment.