rfacebook 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ # Copyright (c) 2007, Matt Pizzimenti (www.livelearncode.com)
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # Neither the name of the original author nor the names of contributors
15
+ # may be used to endorse or promote products derived from this software
16
+ # without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ #
29
+
30
+ require "rfacebook_on_rails/view_extensions"
31
+ require "rfacebook_on_rails/controller_extensions"
32
+ require "rfacebook_on_rails/model_extensions"
33
+
34
+ module RFacebook
35
+ module Rails
36
+ module Plugin
37
+ #####
38
+ module ControllerExtensions
39
+ def facebook_api_key
40
+ FACEBOOK["key"]
41
+ end
42
+ def facebook_api_secret
43
+ FACEBOOK["secret"]
44
+ end
45
+ def facebook_canvas_path
46
+ FACEBOOK["canvas_path"]
47
+ end
48
+ def facebook_callback_path
49
+ FACEBOOK["callback_path"]
50
+ end
51
+ end
52
+ #####
53
+ module ModelExtensions
54
+ def facebook_api_key
55
+ FACEBOOK["key"]
56
+ end
57
+ def facebook_api_secret
58
+ FACEBOOK["secret"]
59
+ end
60
+ end
61
+ #####
62
+ module ViewExtensions
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ begin
69
+ FACEBOOK = YAML.load_file("#{RAILS_ROOT}/config/facebook.yml")[RAILS_ENV]
70
+ rescue
71
+ FACEBOOK = {}
72
+ end
73
+
74
+ ActionView::Base.send(:include, RFacebook::Rails::ViewExtensions)
75
+ ActionView::Base.send(:include, RFacebook::Rails::Plugin::ViewExtensions)
76
+
77
+ ActionController::Base.send(:include, RFacebook::Rails::ControllerExtensions)
78
+ ActionController::Base.send(:include, RFacebook::Rails::Plugin::ControllerExtensions)
79
+
80
+ ActiveRecord::Base.send(:include, RFacebook::Rails::ModelExtensions)
81
+ ActiveRecord::Base.send(:include, RFacebook::Rails::Plugin::ModelExtensions)
82
+
@@ -0,0 +1 @@
1
+ # no installation yet
@@ -0,0 +1,144 @@
1
+ # Copyright (c) 2007, Matt Pizzimenti (www.livelearncode.com)
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # Neither the name of the original author nor the names of contributors
15
+ # may be used to endorse or promote products derived from this software
16
+ # without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ #
29
+
30
+ # Rake tasks modified from Evan Weaver's article
31
+ # http://blog.evanweaver.com/articles/2007/07/13/developing-a-facebook-app-locally
32
+
33
+ namespace "facebook" do
34
+
35
+ ######################################################################################
36
+ ######################################################################################
37
+ desc "Sets up the RFacebook Rails Plugin. Right now, this simply copies facebook.yml into your config directory."
38
+ task "setup" => "environment" do
39
+
40
+ filename = "#{RAILS_ROOT}/config/facebook.yml"
41
+ puts "======================================================"
42
+ puts "Setting up RFacebook on Rails Plugin"
43
+
44
+ ###### Install sample facebook.yml
45
+ file = File.new(filename, "w")
46
+ file <<
47
+ "
48
+ development:
49
+ key: YOUR_API_KEY_HERE
50
+ secret: YOUR_API_SECRET_HERE
51
+ canvas_path: /yourAppName/
52
+ callback_path: /path/to/your/callback/
53
+ tunnel:
54
+ username: yourLoginName
55
+ host: www.yourexternaldomain.com
56
+ port: 1234
57
+ local_port: 5678
58
+
59
+ test:
60
+ key: YOUR_API_KEY_HERE
61
+ secret: YOUR_API_SECRET_HERE
62
+ canvas_path: /yourAppName/
63
+ callback_path: /path/to/your/callback/
64
+ tunnel:
65
+ username: yourLoginName
66
+ host: www.yourexternaldomain.com
67
+ port: 1234
68
+ local_port: 5678
69
+
70
+ production:
71
+ key: YOUR_API_KEY_HERE
72
+ secret: YOUR_API_SECRET_HERE
73
+ canvas_path: /yourAppName/
74
+ callback_path: /path/to/your/callback/
75
+ tunnel:
76
+ username: yourLoginName
77
+ host: www.yourexternaldomain.com
78
+ port: 1234
79
+ local_port: 5678
80
+ "
81
+ file.close_write
82
+ puts " [1] Created config/facebook.yml <-- BE SURE TO CHANGE THE API KEY AND SECRET"
83
+
84
+ ###### Finished
85
+ puts "Done."
86
+ puts "======================================================"
87
+ end
88
+
89
+
90
+ namespace "tunnel" do
91
+
92
+ ######################################################################################
93
+ ######################################################################################
94
+ desc "Start a reverse tunnel to develop from localhost. Please ensure that you have a properly configured config/facebook.yml file."
95
+ task "start" => "environment" do
96
+
97
+ remoteHost = FACEBOOK['tunnel']['host']
98
+ remotePort = FACEBOOK['tunnel']['port']
99
+ localPort = FACEBOOK['tunnel']['local_port']
100
+
101
+ puts "======================================================"
102
+ puts "Tunneling #{remoteHost}:#{remotePort} to 0.0.0.0:#{localPort}"
103
+
104
+ # TODO: learn more about autossh
105
+ # if system("autossh -V")
106
+ # cmd = "autossh -M 8888"
107
+ # puts "(autossh found, using port 8888 to monitor it)"
108
+ # else
109
+ # cmd = "ssh"
110
+ # puts "(autossh not found, using ssh instead)"
111
+ # end
112
+ cmd = "ssh"
113
+
114
+ puts
115
+ puts "NOTES:"
116
+ puts "* ensure that you have Rails running on your local machine at port #{localPort}"
117
+ puts "* once logged in to the tunnel, you can visit http://#{remoteHost}:#{remotePort} to view your site"
118
+ puts "* use ctrl-c to quit the tunnel"
119
+ puts "* if you have problems with #{remoteHost} timing out your ssh connection, add the following lines to your '~/.ssh/config' file:"
120
+ puts "
121
+ Host #{remoteHost}
122
+ ServerAliveInterval 120
123
+ "
124
+ puts "======================================================"
125
+ exec "#{cmd} -nNT -g -R *:#{remotePort}:0.0.0.0:#{localPort} #{remoteHost}"
126
+
127
+
128
+ end
129
+
130
+ ######################################################################################
131
+ ######################################################################################
132
+ desc "Check if reverse tunnel is running"
133
+ task "status" => "environment" do
134
+ if `ssh #{FACEBOOK['tunnel']['host']} netstat -an |
135
+ egrep "tcp.*:#{FACEBOOK['tunnel']['port']}.*LISTEN" | wc`.to_i > 0
136
+ puts "Tunnel still running"
137
+ else
138
+ puts "Tunnel is down"
139
+ end
140
+ end
141
+ end
142
+
143
+
144
+ end
@@ -0,0 +1 @@
1
+ # no uninstallation yet
@@ -0,0 +1,309 @@
1
+ # Copyright (c) 2007, Matt Pizzimenti (www.livelearncode.com)
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # Neither the name of the original author nor the names of contributors
15
+ # may be used to endorse or promote products derived from this software
16
+ # without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ #
29
+
30
+ module RFacebook
31
+ module Rails
32
+
33
+ class StatusManager
34
+
35
+ def initialize(checks)
36
+ @checks = checks
37
+ end
38
+
39
+ def all_valid?
40
+ allValid = true
41
+ @checks.each do |check|
42
+ allValid = false if !check.valid?
43
+ end
44
+ return allValid
45
+ end
46
+
47
+ def each_status_check
48
+ @checks.each do |check|
49
+ yield(check)
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ ###########################################
56
+ class StatusCheck
57
+ def valid?
58
+ return @valid
59
+ end
60
+ def message
61
+ if valid?
62
+ return valid_message
63
+ else
64
+ return invalid_message
65
+ end
66
+ end
67
+ end
68
+
69
+ ###########################################
70
+ class SessionStatusCheck < StatusCheck
71
+ def initialize(controller)
72
+ @controller = controller
73
+ @valid = false
74
+ begin
75
+ if controller.fbsession.is_valid?
76
+ @valid = true
77
+ end
78
+ rescue
79
+ end
80
+ end
81
+
82
+ def title
83
+ "fbsession"
84
+ end
85
+
86
+ def valid_message
87
+ "session is ready to make API calls"
88
+ end
89
+
90
+ def invalid_message
91
+ "session is invalid, you will not be able to make API calls (possibly due to a bad API key or secret)"
92
+ end
93
+
94
+ end
95
+ ###########################################
96
+ class FacebookParamsStatusCheck < StatusCheck
97
+ def initialize(controller)
98
+ @controller = controller
99
+ @valid = false
100
+ begin
101
+ if @controller.fbparams.size > 0
102
+ @valid = true
103
+ end
104
+ rescue
105
+ end
106
+ end
107
+
108
+ def title
109
+ "fbparams"
110
+ end
111
+
112
+ def valid_message
113
+ @controller.fbparams
114
+ end
115
+
116
+ def invalid_message
117
+ "fbparams is not populated since we weren't able to validate the signature (possibly due to a bad API key or secret)"
118
+ end
119
+
120
+ end
121
+ ###########################################
122
+ class InCanvasStatusCheck < StatusCheck
123
+ def initialize(controller)
124
+ @controller = controller
125
+ @valid = true
126
+ end
127
+
128
+ def title
129
+ "in_facebook_canvas?"
130
+ end
131
+
132
+ def valid_message
133
+ @controller.in_facebook_canvas? ? "yes" : "no"
134
+ end
135
+
136
+ def invalid_message
137
+ "this should never be invalid"
138
+ end
139
+
140
+ end
141
+ ###########################################
142
+ class InFrameStatusCheck < StatusCheck
143
+ def initialize(controller)
144
+ @controller = controller
145
+ @valid = true
146
+ end
147
+
148
+ def title
149
+ "in_facebook_frame?"
150
+ end
151
+
152
+ def valid_message
153
+ @controller.in_facebook_frame? ? "yes" : "no"
154
+ end
155
+
156
+ def invalid_message
157
+ "this should never be invalid"
158
+ end
159
+
160
+ end
161
+ ###########################################
162
+ class CanvasPathStatusCheck < StatusCheck
163
+ def initialize(controller)
164
+ @controller = controller
165
+ @valid = false
166
+ begin
167
+ @valid = @controller.facebook_canvas_path.size > 0
168
+ rescue
169
+ end
170
+ end
171
+
172
+ def title
173
+ "facebook_canvas_path"
174
+ end
175
+
176
+ def valid_message
177
+ @controller.facebook_canvas_path
178
+ end
179
+
180
+ def invalid_message
181
+ begin
182
+ FACEBOOK[:test]
183
+ return "you need to define <strong>canvas_path</strong> in facebook.yml"
184
+ rescue
185
+ return "you need to define s<strong>facebook_canvas_path</strong> in your controller"
186
+ end
187
+ end
188
+
189
+ end
190
+ ###########################################
191
+ class CallbackPathStatusCheck < StatusCheck
192
+ def initialize(controller)
193
+ @controller = controller
194
+ @valid = false
195
+ begin
196
+ @valid = @controller.facebook_callback_path.size > 0
197
+ rescue
198
+ end
199
+ end
200
+
201
+ def title
202
+ "facebook_callback_path"
203
+ end
204
+
205
+ def valid_message
206
+ @controller.facebook_callback_path
207
+ end
208
+
209
+ def invalid_message
210
+ begin
211
+ FACEBOOK[:test]
212
+ return "you need to define <strong>callback_path</strong> in facebook.yml"
213
+ rescue
214
+ return "you need to define s<strong>facebook_callback_path</strong> in your controller"
215
+ end
216
+ end
217
+
218
+ end
219
+ ###########################################
220
+ class APIKeyStatusCheck < StatusCheck
221
+ def initialize(controller)
222
+ @controller = controller
223
+ @valid = false
224
+ begin
225
+ if @controller.facebook_api_key.size > 0
226
+ @valid = true
227
+ end
228
+ rescue
229
+ end
230
+ end
231
+
232
+ def title
233
+ "facebook_api_key"
234
+ end
235
+
236
+ def valid_message
237
+ @controller.facebook_api_key
238
+ end
239
+
240
+ def invalid_message
241
+ begin
242
+ FACEBOOK[:test]
243
+ return "you need to put your API <strong>key</strong> in facebook.yml"
244
+ rescue
245
+ return "you need to define s<strong>facebook_api_key</strong> in your controller"
246
+ end
247
+ end
248
+
249
+ end
250
+ ###########################################
251
+ class APISecretStatusCheck < StatusCheck
252
+ def initialize(controller)
253
+ @controller = controller
254
+ @valid = false
255
+ begin
256
+ if @controller.facebook_api_secret.size > 0
257
+ @valid = true
258
+ end
259
+ rescue
260
+ end
261
+ end
262
+
263
+ def title
264
+ "facebook_api_secret"
265
+ end
266
+
267
+ def valid_message
268
+ @controller.facebook_api_secret
269
+ end
270
+
271
+ def invalid_message
272
+ begin
273
+ FACEBOOK[:test]
274
+ return "you need to put your API <strong>secret</strong> in facebook.yml"
275
+ rescue
276
+ return "you need to define s<strong>facebook_api_secret</strong> in your controller"
277
+ end
278
+ end
279
+
280
+ end
281
+ ###########################################
282
+ class FinishFacebookLoginStatusCheck < StatusCheck
283
+ def initialize(controller)
284
+ @controller = controller
285
+ @valid = false
286
+ begin
287
+ @controller.finish_facebook_login
288
+ @valid = true
289
+ rescue
290
+ end
291
+ end
292
+
293
+ def title
294
+ "finish_facebook_login"
295
+ end
296
+
297
+ def valid_message
298
+ "finisher method is defined (this is only for external web apps)"
299
+ end
300
+
301
+ def invalid_message
302
+ "you need to define <strong>finish_facebook_login</strong> in your controller (this is only for external web apps)"
303
+ end
304
+
305
+ end
306
+
307
+
308
+ end
309
+ end