Class: FbRails::Connect

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookies) ⇒ Connect

Returns a new instance of Connect.



10
11
12
# File 'lib/fb_rails/connect.rb', line 10

def initialize(cookies)
  @cookies = cookies
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



9
10
11
# File 'lib/fb_rails/connect.rb', line 9

def cookies
  @cookies
end

Class Method Details



4
5
6
# File 'lib/fb_rails/connect.rb', line 4

def cookie_name
  "fbs_#{FbRails::Config.app_id}"
end

Instance Method Details

#access_tokenObject



26
27
28
# File 'lib/fb_rails/connect.rb', line 26

def access_token
  connected? ? cookie['access_token'] : nil
end

#connected?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fb_rails/connect.rb', line 18

def connected?
  cookie.present?
end


14
15
16
# File 'lib/fb_rails/connect.rb', line 14

def cookie
  @cookie ||= FbRails::Cookie.decode(cookies[self.class.cookie_name], FbRails::Config.secret)
end

#uidObject



22
23
24
# File 'lib/fb_rails/connect.rb', line 22

def uid
  connected? ? cookie['uid'].to_i : nil
end

#userObject



30
31
32
33
34
35
36
37
38
# File 'lib/fb_rails/connect.rb', line 30

def user
  if connected?
    @user ||= begin
      record = FbRails::Config.user_class.find_or_initialize_by_fb_uid(uid)
      record.access_token = access_token
      record
    end
  end
end