class FacebookAuth
Attributes
access_token[RW]
expires[RW]
uid[RW]
user_data[RW]
validation_error[RW]
Public Class Methods
create(parms)
click to toggle source
# 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
Public Instance Methods
expires_epoch=(epoch)
click to toggle source
# 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?()
click to toggle source
# File lib/fbauth/auth.rb, line 26 def is_expired? if self.expires.nil? true else self.expires < Time.now end end
session_data()
click to toggle source
# 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()
click to toggle source
# 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