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).
-
#network ⇒ Object
The network this session is being used on (Bebo, Facebook, etc).
-
#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)
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/facebook_session.rb', line 113 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”
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/facebook_session.rb', line 173 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)
101 102 103 |
# File 'lib/facebook_session.rb', line 101 def logger @logger end |
#network ⇒ Object
The network this session is being used on (Bebo, Facebook, etc)
89 90 91 |
# File 'lib/facebook_session.rb', line 89 def network @network end |
#session_expires ⇒ Object (readonly)
The expiration time of this session, as given from Facebook API login.
98 99 100 |
# File 'lib/facebook_session.rb', line 98 def session_expires @session_expires end |
#session_key ⇒ Object (readonly)
The key for this session. You will need to save this for infinite sessions.
95 96 97 |
# File 'lib/facebook_session.rb', line 95 def session_key @session_key end |
#session_user_id ⇒ Object (readonly)
The user id of the user associated with this sesssion.
92 93 94 |
# File 'lib/facebook_session.rb', line 92 def session_user_id @session_user_id end |
Class Method Details
._load(dumpedStr) ⇒ Object
load from a serialized string
331 332 333 334 335 336 337 338 |
# File 'lib/facebook_session.rb', line 331 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)
324 325 326 327 328 |
# File 'lib/facebook_session.rb', line 324 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)
133 134 135 |
# File 'lib/facebook_session.rb', line 133 def expired? return @expired end |
#is_activated? ⇒ Boolean
DEPRECATED
354 355 356 357 |
# File 'lib/facebook_session.rb', line 354 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
348 349 350 351 |
# File 'lib/facebook_session.rb', line 348 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
366 367 368 369 |
# File 'lib/facebook_session.rb', line 366 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
360 361 362 363 |
# File 'lib/facebook_session.rb', line 360 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
378 379 380 381 |
# File 'lib/facebook_session.rb', line 378 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
372 373 374 375 |
# File 'lib/facebook_session.rb', line 372 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
143 144 145 |
# File 'lib/facebook_session.rb', line 143 def quiet=(val) @quiet = val end |
#quiet? ⇒ Boolean
Returns true if exceptions are being suppressed in favor of log messages
138 139 140 |
# File 'lib/facebook_session.rb', line 138 def quiet? return @quiet end |
#ready? ⇒ Boolean
Template method. Returns true when the session is definitely prepared to make API calls.
128 129 130 |
# File 'lib/facebook_session.rb', line 128 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
151 152 153 |
# File 'lib/facebook_session.rb', line 151 def signature(params) raise NotImplementedError end |
#suppress_errors ⇒ Object
DEPRECATED
384 385 386 387 |
# File 'lib/facebook_session.rb', line 384 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
390 391 392 393 |
# File 'lib/facebook_session.rb', line 390 def suppress_errors=(val) # :nodoc: RAILS_DEFAULT_LOGGER.info "** RFACEBOOK(GEM) DEPRECATION WARNING: suppress_errors= is deprecated, use quiet= instead" @quiet=val end |