Module: Passport::Oauth::Defineable::ClassMethods
- Defined in:
- lib/passport/oauth/client/defineable.rb
Instance Method Summary collapse
-
#identify(access_token) ⇒ Object
this is a method used to identify the user uniquely from the oauth protocol.
-
#key(value = nil, &block) ⇒ Object
unique key that we will use from the AccessToken response to identify the user by.
- #service ⇒ Object
- #setting(key) ⇒ Object
- #settings(site = nil, hash = {}) ⇒ Object
-
#version(value = nil) ⇒ Object
oauth version, 1.0 or 2.0, should be a float b/c we may encounter 1.1 for example.
Instance Method Details
#identify(access_token) ⇒ Object
this is a method used to identify the user uniquely from the oauth protocol
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/passport/oauth/client/defineable.rb', line 46 def identify(access_token) if key if key.is_a?(Proc) return key.call(access_token) else return (access_token.params[key.to_s] || access_token.params[key.to_sym]) # try both end else raise "please set an oauth key for #{service.to_s}" end end |
#key(value = nil, &block) ⇒ Object
unique key that we will use from the AccessToken response to identify the user by. in Twitter, its “user_id”. Twitter has “screen_name”, but that’s more subject to change than user_id. Pick whatever is least likely to change
26 27 28 29 30 31 32 33 34 |
# File 'lib/passport/oauth/client/defineable.rb', line 26 def key(value = nil, &block) if block_given? @key = block elsif value @key = value.is_a?(Symbol) ? value : value.to_sym end @key end |
#service ⇒ Object
11 12 13 |
# File 'lib/passport/oauth/client/defineable.rb', line 11 def service @service ||= self.to_s.underscore.scan(/^(.*?)(_token)?$/)[0][0].to_s end |
#setting(key) ⇒ Object
41 42 43 |
# File 'lib/passport/oauth/client/defineable.rb', line 41 def setting(key) settings ? settings[key.to_sym] : "" end |
#settings(site = nil, hash = {}) ⇒ Object
36 37 38 39 |
# File 'lib/passport/oauth/client/defineable.rb', line 36 def settings(site = nil, hash = {}) @settings = hash.merge(:site => site) if site @settings end |
#version(value = nil) ⇒ Object
oauth version, 1.0 or 2.0, should be a float b/c we may encounter 1.1 for example.
16 17 18 19 20 |
# File 'lib/passport/oauth/client/defineable.rb', line 16 def version(value = nil) @version = value if value @version ||= 1.0 @version end |