Class: RFacebook::FacebookSession
- Inherits:
-
Object
- Object
- RFacebook::FacebookSession
- Defined in:
- lib/facebook_session.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ExpiredSessionStandardError, NotActivatedStandardError, RemoteStandardError
Instance Attribute Summary collapse
-
#logger ⇒ Object
Can be set to any valid logger (for example, RAIL_DEFAULT_LOGGER).
-
#session_expires ⇒ Object
readonly
The expiration time of this session, as given from Facebook API login.
-
#session_key ⇒ Object
readonly
The key for this session.
-
#session_user_id ⇒ Object
readonly
The user id of the user associated with this sesssion.
Class Method Summary collapse
-
._load(dumpedStr) ⇒ Object
load from a serialized string.
Instance Method Summary collapse
-
#_dump(depth) ⇒ Object
dump to a serialized string, removing the logger object (which cannot be serialized).
-
#expired? ⇒ Boolean
Returns true if the session is expired (will often mean that the session is not ready as well).
-
#initialize(api_key, api_secret, quiet = false) ⇒ FacebookSession
constructor
Constructs a FacebookSession.
-
#is_activated? ⇒ Boolean
DEPRECATED.
-
#is_expired? ⇒ Boolean
DEPRECATED.
-
#is_ready? ⇒ Boolean
DEPRECATED.
-
#is_valid? ⇒ Boolean
DEPRECATED.
-
#last_error_code ⇒ Object
DEPRECATED.
-
#last_error_message ⇒ Object
DEPRECATED.
-
#quiet=(val) ⇒ Object
Sets whether or not we suppress exceptions from being thrown.
-
#quiet? ⇒ Boolean
Returns true if exceptions are being suppressed in favor of log messages.
-
#ready? ⇒ Boolean
Template method.
-
#signature(params) ⇒ Object
Template method.
-
#suppress_errors ⇒ Object
DEPRECATED.
-
#suppress_errors=(val) ⇒ Object
DEPRECATED.
Constructor Details
#initialize(api_key, api_secret, quiet = false) ⇒ FacebookSession
Constructs a FacebookSession.
- api_key
-
your API key
- api_secret
-
your API secret
- quiet
-
boolean, set to true if you don’t want exceptions to be thrown (defaults to false)
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/facebook_session.rb', line 95 def initialize(api_key, api_secret, quiet = false) # required parameters @api_key = api_key @api_secret = api_secret # optional parameters @quiet = quiet # initialize internal state @last_error_message = nil # DEPRECATED @last_error_code = nil # DEPRECATED @expired = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodSymbol, *params) ⇒ Object (private)
This allows any Facebook method to be called, using the Ruby mechanism for responding to unimplemented methods. Basically, this converts a call to “auth_getSession” to “auth.getSession” and does the proper API call using the parameter hash given.
This allows you to call an API method such as facebook.users.getInfo by calling “fbsession.users_getInfo”
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/facebook_session.rb', line 150 def method_missing(methodSymbol, *params) # get the remote method name remoteMethod = methodSymbol.to_s.gsub("_", ".") if methodSymbol.to_s.match(/cached_(.*)/) log_debug "** RFACEBOOK(GEM) - DEPRECATION NOTICE - cached methods are deprecated, making a raw call without caching." tokens.shift end # there can only be one parameter, a Hash, for remote methods unless (params.size == 1 and params.first.is_a?(Hash)) log_debug "** RFACEBOOK(GEM) - when you call a remote Facebook method" end # make the remote method call return remote_call(remoteMethod, params.first) end |
Instance Attribute Details
#logger ⇒ Object
Can be set to any valid logger (for example, RAIL_DEFAULT_LOGGER)
83 84 85 |
# File 'lib/facebook_session.rb', line 83 def logger @logger end |
#session_expires ⇒ Object (readonly)
The expiration time of this session, as given from Facebook API login.
80 81 82 |
# File 'lib/facebook_session.rb', line 80 def session_expires @session_expires end |
#session_key ⇒ Object (readonly)
The key for this session. You will need to save this for infinite sessions.
77 78 79 |
# File 'lib/facebook_session.rb', line 77 def session_key @session_key end |
#session_user_id ⇒ Object (readonly)
The user id of the user associated with this sesssion.
74 75 76 |
# File 'lib/facebook_session.rb', line 74 def session_user_id @session_user_id end |
Class Method Details
._load(dumpedStr) ⇒ Object
load from a serialized string
308 309 310 311 312 313 314 315 |
# File 'lib/facebook_session.rb', line 308 def self._load(dumpedStr) # :nodoc: instance = self.new(nil,nil) dumped = Marshal.load(dumpedStr) dumped.each do |k,v| instance.instance_variable_set(k,v) end return instance end |
Instance Method Details
#_dump(depth) ⇒ Object
dump to a serialized string, removing the logger object (which cannot be serialized)
301 302 303 304 305 |
# File 'lib/facebook_session.rb', line 301 def _dump(depth) # :nodoc: instanceVarHash = {} self.instance_variables.each { |k| instanceVarHash[k] = self.instance_variable_get(k) } return Marshal.dump(instanceVarHash.delete_if{|k,v| k == "@logger"}) end |
#expired? ⇒ Boolean
Returns true if the session is expired (will often mean that the session is not ready as well)
115 116 117 |
# File 'lib/facebook_session.rb', line 115 def expired? return @expired end |
#is_activated? ⇒ Boolean
DEPRECATED
331 332 333 334 |
# File 'lib/facebook_session.rb', line 331 def is_activated? # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: is_activated? is deprecated, use ready? instead" return ready? end |
#is_expired? ⇒ Boolean
DEPRECATED
325 326 327 328 |
# File 'lib/facebook_session.rb', line 325 def is_expired? # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: is_expired? is deprecated, use expired? instead" return expired? end |
#is_ready? ⇒ Boolean
DEPRECATED
343 344 345 346 |
# File 'lib/facebook_session.rb', line 343 def is_ready? # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: is_valid? is deprecated, use ready? instead" return ready? end |
#is_valid? ⇒ Boolean
DEPRECATED
337 338 339 340 |
# File 'lib/facebook_session.rb', line 337 def is_valid? # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: is_valid? is deprecated, use ready? instead" return ready? end |
#last_error_code ⇒ Object
DEPRECATED
355 356 357 358 |
# File 'lib/facebook_session.rb', line 355 def last_error_code # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: last_error_code is deprecated" return @last_error_code end |
#last_error_message ⇒ Object
DEPRECATED
349 350 351 352 |
# File 'lib/facebook_session.rb', line 349 def # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: last_error_message is deprecated" return @last_error_message end |
#quiet=(val) ⇒ Object
Sets whether or not we suppress exceptions from being thrown
125 126 127 |
# File 'lib/facebook_session.rb', line 125 def quiet=(val) @quiet = val end |
#quiet? ⇒ Boolean
Returns true if exceptions are being suppressed in favor of log messages
120 121 122 |
# File 'lib/facebook_session.rb', line 120 def quiet? return @quiet end |
#ready? ⇒ Boolean
Template method. Returns true when the session is definitely prepared to make API calls.
110 111 112 |
# File 'lib/facebook_session.rb', line 110 def ready? raise NotImplementedError end |
#signature(params) ⇒ Object
Template method. Used for signing a set of parameters in the way that Facebook specifies: <developers.facebook.com/documentation.php?v=1.0&doc=auth>
- params
-
a Hash containing the parameters to sign
133 134 135 |
# File 'lib/facebook_session.rb', line 133 def signature(params) raise NotImplementedError end |
#suppress_errors ⇒ Object
DEPRECATED
361 362 363 364 |
# File 'lib/facebook_session.rb', line 361 def suppress_errors # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: suppress_errors is deprecated, use quiet? instead" return quiet? end |
#suppress_errors=(val) ⇒ Object
DEPRECATED
367 368 369 370 |
# File 'lib/facebook_session.rb', line 367 def suppress_errors=(val) # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: suppress_errors= is deprecated, use quiet= instead" @quiet=val end |