Class: FacebookAuth
- Inherits:
-
Object
- Object
- FacebookAuth
- Defined in:
- lib/fbauth/auth.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#expires ⇒ Object
Returns the value of attribute expires.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#user_data ⇒ Object
Returns the value of attribute user_data.
-
#validation_error ⇒ Object
Returns the value of attribute validation_error.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/fbauth/auth.rb', line 3 def access_token @access_token end |
#expires ⇒ Object
Returns the value of attribute expires.
3 4 5 |
# File 'lib/fbauth/auth.rb', line 3 def expires @expires end |
#uid ⇒ Object
Returns the value of attribute uid.
3 4 5 |
# File 'lib/fbauth/auth.rb', line 3 def uid @uid end |
#user_data ⇒ Object
Returns the value of attribute user_data.
4 5 6 |
# File 'lib/fbauth/auth.rb', line 4 def user_data @user_data end |
#validation_error ⇒ Object
Returns the value of attribute validation_error.
4 5 6 |
# File 'lib/fbauth/auth.rb', line 4 def validation_error @validation_error end |
Class Method Details
.create(parms) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fbauth/auth.rb', line 6 def self.create parms auth = self.new # Sense old-style FB auth structure, or new-style if parms.has_key?('access_token') auth.access_token = parms['access_token'] auth.uid = parms['uid'] auth.expires_epoch = parms['expires'].to_i unless parms['expires'].nil? elsif parms.has_key?('oauth_token') auth.access_token = parms['oauth_token'] auth.uid = parms['user_id'] auth.expires_epoch = parms['expires'].to_i if parms.has_key?('expires') end auth end |
Instance Method Details
#expires_epoch=(epoch) ⇒ Object
21 22 23 24 |
# File 'lib/fbauth/auth.rb', line 21 def expires_epoch= epoch # Need to convolve for SanFran TZ? self.expires = Time.at(epoch) end |
#is_expired? ⇒ Boolean
26 27 28 29 30 31 32 |
# File 'lib/fbauth/auth.rb', line 26 def is_expired? if self.expires.nil? true else self.expires < Time.now end end |
#session_data ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/fbauth/auth.rb', line 57 def session_data return { 'access_token' => self.access_token, 'uid' => self.uid, 'expires' => self.expires.to_i }.to_json end |
#validate ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fbauth/auth.rb', line 34 def validate valid = false msgs = [] unless self.uid.nil? || self.access_token.nil? begin self.user_data = FacebookGraph.new(self.access_token).call(self.uid) rescue => e msgs << "Error calling FacebookGraph - #{e}" end if self.user_data && self.user_data.has_key?('error') msgs << self.user_data['error'].inspect self.user_data = nil elsif self.user_data valid = true end else msgs << "UID provided is nil" if self.uid.nil? msgs << "access_token provided is nil" if self.access_token.nil? end self.validation_error = msgs.join(", ") unless valid return valid end |