rfacebook 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +28 -28
- data/lib/facebook_rails_controller_extensions.rb +63 -36
- data/lib/facebook_session.rb +2 -2
- metadata +2 -2
data/README
CHANGED
@@ -21,22 +21,22 @@ Then, whenever a user visits
|
|
21
21
|
You can get this behavior by installing the new RFacebook gem. After
|
22
22
|
installing the gem, make your ApplicationController look like this:
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
require "facebook_rails_controller_extensions"
|
25
|
+
|
26
|
+
class ApplicationController < ActionController::Base
|
27
|
+
|
28
|
+
# additions to integrate Facebook into controllers
|
29
|
+
include RFacebook::RailsControllerExtensions
|
30
|
+
|
31
|
+
def facebook_api_key
|
32
|
+
return "YOUR API KEY HERE"
|
33
|
+
end
|
34
|
+
|
35
|
+
def facebook_api_secret
|
36
|
+
return "YOUR API SECRET HERE"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
40
|
|
41
41
|
You will have access to 2 new items in your controllers:
|
42
42
|
|
@@ -55,18 +55,18 @@ And, you have a few new filters to try out:
|
|
55
55
|
|
56
56
|
For example, one of my Rails controllers looks like this:
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
58
|
+
class FacebookController < ApplicationController
|
59
|
+
|
60
|
+
before_filter :require_facebook_install # require users to install the application (less intrusive is to require_facebook_login)
|
61
|
+
|
62
|
+
def index
|
63
|
+
xml = fbsession.users_getInfo(:uids => [fbsession.session_user_id], :fields => ["first_name", "last_name"])
|
64
|
+
@firstName = xml.at("first_name").inner_html
|
65
|
+
@lastName = xml.at("last_name").inner_html
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
70
|
|
71
71
|
|
72
72
|
|
@@ -9,6 +9,7 @@ module RFacebook
|
|
9
9
|
|
10
10
|
class APIKeyNeededException < Exception; end
|
11
11
|
class APISecretNeededException < Exception; end
|
12
|
+
class APIFinisherNeededException < Exception; end
|
12
13
|
|
13
14
|
# SECTION: Template Methods (must be implemented by concrete subclass)
|
14
15
|
|
@@ -20,6 +21,10 @@ module RFacebook
|
|
20
21
|
raise APISecretNeededException
|
21
22
|
end
|
22
23
|
|
24
|
+
def finish_facebook_login
|
25
|
+
raise APIFinisherNeededException
|
26
|
+
end
|
27
|
+
|
23
28
|
|
24
29
|
|
25
30
|
# SECTION: Required Methods
|
@@ -47,24 +52,24 @@ module RFacebook
|
|
47
52
|
|
48
53
|
if !@fbsession
|
49
54
|
|
50
|
-
# create a
|
55
|
+
# create a session no matter what
|
51
56
|
@fbsession = FacebookWebSession.new(facebook_api_key, facebook_api_secret)
|
52
|
-
|
53
|
-
# now we need to activate the session somehow. If the signature parameters are bad, then we don't make the session
|
54
|
-
if fbparams
|
55
|
-
# these might be nil
|
56
|
-
facebookUid = fbparams["user"]
|
57
|
-
facebookSessionKey = fbparams["session_key"]
|
58
|
-
expirationTime = fbparams["expires"]
|
59
57
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
# then try to activate it somehow (or retrieve from previous state)
|
59
|
+
# these might be nil
|
60
|
+
facebookUid = fbparams["user"]
|
61
|
+
facebookSessionKey = fbparams["session_key"]
|
62
|
+
expirationTime = fbparams["expires"]
|
63
|
+
|
64
|
+
if (facebookUid and facebookSessionKey and expirationTime)
|
65
|
+
# Method 1: we have the user id and key from the fb_sig_ params
|
66
|
+
@fbsession.activate_with_previous_session(facebookSessionKey, facebookUid, expirationTime)
|
67
|
+
|
68
|
+
elsif (!in_facebook_canvas? and session[:rfacebook_fbsession])
|
69
|
+
# Method 2: we've logged in the user already
|
70
|
+
@fbsession = session[:rfacebook_fbsession]
|
71
|
+
|
72
|
+
end
|
68
73
|
|
69
74
|
end
|
70
75
|
|
@@ -75,43 +80,65 @@ module RFacebook
|
|
75
80
|
# SECTION: Helpful Methods
|
76
81
|
|
77
82
|
def facebook_redirect_to(url)
|
78
|
-
|
79
|
-
|
80
|
-
render :text => "<fb:redirect url=\"#{url}\" />"
|
81
|
-
|
82
|
-
elsif url =~ /^https?:\/\/([^\/]*\.)?facebook\.com(:\d+)?/i # TODO: why doesn't this just check for iframe?
|
83
|
-
render :text => "<script type=\"text/javascript\">\ntop.location.href = \"#{url}\";\n</script>"
|
84
|
-
|
83
|
+
if in_facebook_canvas?
|
84
|
+
render :text => "<fb:redirect url=\"#{url}\" />"
|
85
85
|
else
|
86
86
|
redirect_to url
|
87
|
-
|
88
87
|
end
|
89
|
-
|
90
88
|
end
|
91
89
|
|
92
90
|
def in_facebook_canvas?
|
93
|
-
return (fbparams["
|
91
|
+
return (fbparams["in_canvas"] != nil)
|
92
|
+
end
|
93
|
+
|
94
|
+
def in_facebook_frame?
|
95
|
+
return (fbparams["in_iframe"] != nil || fbparams["in_canvas"] != nil)
|
94
96
|
end
|
97
|
+
|
98
|
+
def handle_facebook_login
|
99
|
+
|
100
|
+
if (params["auth_token"] and !in_facebook_canvas?)
|
101
|
+
|
102
|
+
# create a session
|
103
|
+
session[:rfacebook_fbsession] = FacebookWebSession.new(facebook_api_key, facebook_api_secret)
|
104
|
+
session[:rfacebook_fbsession].activate_with_token(params["auth_token"])
|
95
105
|
|
96
|
-
|
97
|
-
|
106
|
+
# template method call upon success
|
107
|
+
if session[:rfacebook_fbsession].is_valid?
|
108
|
+
finish_facebook_login
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
98
113
|
end
|
99
114
|
|
100
115
|
def require_facebook_login
|
101
|
-
|
102
|
-
if (
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
116
|
+
|
117
|
+
# handle a facebook login if given (external sites and iframe only)
|
118
|
+
handle_facebook_login
|
119
|
+
|
120
|
+
if !performed?
|
121
|
+
# try to get the session
|
122
|
+
sess = fbsession
|
123
|
+
|
124
|
+
# handle invalid sessions by forcing the user to log in
|
125
|
+
if !sess.is_valid?
|
126
|
+
if in_facebook_canvas?
|
127
|
+
render :text => "<fb:redirect url=\"#{sess.get_login_url(:canvas=>true)}\" />"
|
128
|
+
return false
|
129
|
+
else
|
130
|
+
redirect_to sess.get_login_url
|
131
|
+
return false
|
132
|
+
end
|
107
133
|
end
|
108
134
|
end
|
135
|
+
|
109
136
|
end
|
110
137
|
|
111
138
|
def require_facebook_install
|
112
139
|
sess = fbsession
|
113
|
-
if (
|
114
|
-
render :text => "<fb:redirect url=\"#{sess.get_install_url
|
140
|
+
if (in_facebook_canvas? and !sess.is_valid?)
|
141
|
+
render :text => "<fb:redirect url=\"#{sess.get_install_url}\" />"
|
115
142
|
end
|
116
143
|
end
|
117
144
|
|
data/lib/facebook_session.rb
CHANGED
@@ -39,10 +39,10 @@ require "hpricot"
|
|
39
39
|
|
40
40
|
module RFacebook
|
41
41
|
|
42
|
-
API_SERVER_BASE_URL = "api.
|
42
|
+
API_SERVER_BASE_URL = "api.facebook.com"
|
43
43
|
API_PATH_REST = "/restserver.php"
|
44
44
|
|
45
|
-
WWW_SERVER_BASE_URL = "www.
|
45
|
+
WWW_SERVER_BASE_URL = "www.facebook.com"
|
46
46
|
WWW_PATH_LOGIN = "/login.php"
|
47
47
|
WWW_PATH_ADD = "/add.php"
|
48
48
|
WWW_PATH_INSTALL = "/install.php"
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rfacebook
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.6.
|
7
|
-
date: 2007-05-
|
6
|
+
version: 0.6.1
|
7
|
+
date: 2007-05-31 00:00:00 -07:00
|
8
8
|
summary: A Ruby interface to the Facebook API v1.0+. Supports the new features from F8.
|
9
9
|
require_paths:
|
10
10
|
- lib
|