Class: FaceB::Session
- Inherits:
-
Object
- Object
- FaceB::Session
- Defined in:
- lib/faceb/session.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#session_key ⇒ Object
readonly
Returns the value of attribute session_key.
-
#user_facebook_uid ⇒ Object
readonly
Returns the value of attribute user_facebook_uid.
Class Method Summary collapse
Instance Method Summary collapse
- #call(method, params = {}) ⇒ Object
-
#initialize(api_key, secret_key, session_key = nil) ⇒ Session
constructor
A new instance of Session.
-
#method_missing(method_name, args = {}) ⇒ Object
Allow session to dynamically call API method.
- #reset! ⇒ Object
- #secure_with_session_key!(session_key) ⇒ Object
- #secured? ⇒ Boolean
Constructor Details
#initialize(api_key, secret_key, session_key = nil) ⇒ Session
Returns a new instance of Session.
22 23 24 25 26 27 |
# File 'lib/faceb/session.rb', line 22 def initialize(api_key, secret_key, session_key = nil) @api_key = api_key @secret_key = secret_key @session_key = session_key secure_with_session_key!(session_key) unless !session_key end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, args = {}) ⇒ Object
Allow session to dynamically call API method
44 45 46 47 48 49 50 51 |
# File 'lib/faceb/session.rb', line 44 def method_missing(method_name, args={}) if !!@scope self.call("#{@scope}.#{method_name}", args) else @scope = method_name self end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/faceb/session.rb', line 3 def api_key @api_key end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
3 4 5 |
# File 'lib/faceb/session.rb', line 3 def secret_key @secret_key end |
#session_key ⇒ Object (readonly)
Returns the value of attribute session_key.
3 4 5 |
# File 'lib/faceb/session.rb', line 3 def session_key @session_key end |
#user_facebook_uid ⇒ Object (readonly)
Returns the value of attribute user_facebook_uid.
3 4 5 |
# File 'lib/faceb/session.rb', line 3 def user_facebook_uid @user_facebook_uid end |
Class Method Details
.create(api_key, secret_key, session_key = nil) ⇒ Object
5 6 7 8 |
# File 'lib/faceb/session.rb', line 5 def self.create(api_key, secret_key, session_key = nil) @current_session = self.new(api_key, secret_key, session_key) unless defined?(@current_session) && !!@current_session @current_session end |
.current ⇒ Object
10 11 12 |
# File 'lib/faceb/session.rb', line 10 def self.current @current_session end |
.reset! ⇒ Object
14 15 16 |
# File 'lib/faceb/session.rb', line 14 def self.reset! @current_session = nil end |
Instance Method Details
#call(method, params = {}) ⇒ Object
29 30 31 32 |
# File 'lib/faceb/session.rb', line 29 def call(method, params ={}) @scope = nil Api.new(self).call(method, params) end |
#reset! ⇒ Object
18 19 20 |
# File 'lib/faceb/session.rb', line 18 def reset! self.class.reset! end |
#secure_with_session_key!(session_key) ⇒ Object
34 35 36 37 |
# File 'lib/faceb/session.rb', line 34 def secure_with_session_key!(session_key) @session_key = session_key @user_facebook_uid = self.call('users.getLoggedInUser', :session_key => session_key).data end |
#secured? ⇒ Boolean
39 40 41 |
# File 'lib/faceb/session.rb', line 39 def secured? !!@user_facebook_uid end |