rfacebook 0.9.7 → 0.9.8

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.
@@ -1 +0,0 @@
1
- # no uninstallation yet
@@ -1,202 +0,0 @@
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 "digest/md5"
31
- require "cgi"
32
-
33
- module RFacebook::Rails::SessionExtensions # :nodoc:
34
-
35
- # :section: New Methods
36
- def force_to_be_new! # :nodoc:
37
- @force_to_be_new = true
38
- end
39
-
40
- def using_facebook_session_id? # :nodoc:
41
- return (@fb_sig_session_id != nil)
42
- end
43
-
44
- # :section: Base Overrides
45
-
46
- def new_session__RFACEBOOK # :nodoc:
47
- if @force_to_be_new
48
- return true
49
- else
50
- return new_session__ALIASED
51
- end
52
- end
53
-
54
- def initialize__RFACEBOOK(request, options = {}) # :nodoc:
55
-
56
- # only try to use the sig when we don't have a cookie (i.e., in the canvas)
57
- if in_facebook_canvas?(request)
58
-
59
- # try a few different ways
60
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Attempting to use fb_sig_session_key as a session key, since we are inside the canvas"
61
- @fb_sig_session_id = lookup_request_parameter(request, "fb_sig_session_key")
62
-
63
- # we only want to change the session_id if we got one from the fb_sig
64
- if @fb_sig_session_id
65
- options["session_id"] = Digest::MD5.hexdigest(@fb_sig_session_id)
66
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using MD5 of fb_sig_session_key [#{options['session_id']}] for the Rails session id"
67
- end
68
- end
69
-
70
- # now call the default Rails session initialization
71
- initialize__ALIASED(request, options)
72
- end
73
-
74
- # :section: Extension Helpers
75
-
76
- def self.included(base) # :nodoc:
77
- base.class_eval'
78
- alias :initialize__ALIASED :initialize
79
- alias :initialize :initialize__RFACEBOOK
80
-
81
- alias :new_session__ALIASED :new_session
82
- alias :new_session :new_session__RFACEBOOK
83
- '
84
- end
85
-
86
- # :section: Private Helpers
87
-
88
- private
89
-
90
- # TODO: it seems that there should be a better way to just get raw parameters
91
- # (not sure why the nil key bug doesn't seem to be fixed in my installation)
92
- # ...also, there seems to be some interaction with Mongrel as well that can
93
- # cause the parameters to fail
94
- def lookup_request_parameter(request, key) # :nodoc:
95
-
96
- # Depending on the user's version of Rails, this may fail due to a bug in Rails parsing of
97
- # nil keys: http://dev.rubyonrails.org/ticket/5137, so we have a backup plan
98
- begin
99
-
100
- # this should work on most Rails installations
101
- return request.parameters[key]
102
-
103
- rescue
104
-
105
- # this saves most other Rails installations
106
- begin
107
-
108
- retval = nil
109
-
110
- # try accessing raw_post (doesn't work in some mongrel installations)
111
- if request.respond_to?(:raw_post)
112
- return CGI::parse(request.send(:raw_post)).fetch(key){[]}.first
113
- end
114
-
115
- # try accessing the raw environment table
116
- if !retval
117
- envTable = nil
118
-
119
- envTable = request.send(:env_table) if request.respond_to?(:env_table)
120
- if !envTable
121
- envTable = request.send(:env) if request.respond_to?(:env)
122
- end
123
-
124
- if envTable
125
- # credit: Blake Carlson and David Troy
126
- ["RAW_POST_DATA", "QUERY_STRING"].each do |tableSource|
127
- if envTable[tableSource]
128
- retval = CGI::parse(envTable[tableSource]).fetch(key){[]}.first
129
- end
130
- break if retval
131
- end
132
- end
133
- end
134
-
135
- # hopefully we got a parameter
136
- return retval
137
-
138
- rescue
139
-
140
- # for some reason, we just can't get the parameters
141
- RAILS_DEFAULT_LOGGER.info "** RFACEBOOK WARNING: failed to access request.parameters"
142
- return nil
143
-
144
- end
145
- end
146
- end
147
-
148
- def in_facebook_canvas?(request) # :nodoc:
149
- # TODO: we should probably be checking the fb_sig for validity here (template method needed)
150
- # ...we can only do this if we can grab the equivalent of a params hash
151
- return lookup_request_parameter(request, "fb_sig_in_canvas")
152
- end
153
-
154
- end
155
-
156
- # Module: SessionStoreExtensions
157
- #
158
- # Special initialize method that attempts to force any session store to use the Facebook session
159
- module RFacebook::Rails::SessionStoreExtensions # :nodoc:all
160
-
161
- # :section: Base Overrides
162
-
163
- def initialize__RFACEBOOK(session, options, *extraParams) # :nodoc:
164
-
165
- if session.using_facebook_session_id?
166
-
167
- # we got the fb_sig_session_key, so alter Rails' behavior to use that key to make a session
168
- begin
169
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using fb_sig_session_key for the #{self.class.to_s} session (session_id=#{session.session_id})"
170
- initialize__ALIASED(session, options, *extraParams)
171
- rescue Exception => e
172
- begin
173
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to initialize session (session_id=#{session.session_id}), trying to force a new session"
174
- if session.session_id
175
- session.force_to_be_new!
176
- end
177
- initialize__ALIASED(session, options, *extraParams)
178
- rescue Exception => e
179
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to force a new session, falling back to default Rails behavior"
180
- raise e
181
- end
182
- end
183
-
184
- else
185
-
186
- # we didn't get the fb_sig_session_key, do not alter Rails' behavior
187
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using default Rails sessions (since we didn't find an fb_sig_session_key in the environment)"
188
- initialize__ALIASED(session, options, *extraParams)
189
-
190
- end
191
- end
192
-
193
- # :section: Extension Helpers
194
-
195
- def self.included(base) # :nodoc:
196
- base.class_eval'
197
- alias :initialize__ALIASED :initialize
198
- alias :initialize :initialize__RFACEBOOK
199
- '
200
- end
201
-
202
- end
@@ -1,309 +0,0 @@
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