Class: RFacebook::FacebookSession

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_session.rb

Direct Known Subclasses

FacebookDesktopSession, FacebookWebSession

Defined Under Namespace

Classes: ExpiredSessionStandardError, NotActivatedStandardError, RemoteStandardError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#loggerObject

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

#networkObject

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_expiresObject (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_keyObject (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_idObject (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)

Returns:

  • (Boolean)


133
134
135
# File 'lib/facebook_session.rb', line 133

def expired?
  return @expired
end

#is_activated?Boolean

DEPRECATED

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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_codeObject

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_messageObject

DEPRECATED



372
373
374
375
# File 'lib/facebook_session.rb', line 372

def last_error_message # :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

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


151
152
153
# File 'lib/facebook_session.rb', line 151

def signature(params)
  raise NotImplementedError
end

#suppress_errorsObject

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