tenderlove-facebooker 1.0.16.20090319151701
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +17 -0
- data/COPYING.rdoc +19 -0
- data/Manifest.txt +123 -0
- data/README.rdoc +103 -0
- data/Rakefile +86 -0
- data/TODO.rdoc +4 -0
- data/examples/desktop_login.rb +14 -0
- data/facebooker.gemspec +38 -0
- data/generators/facebook/facebook_generator.rb +14 -0
- data/generators/facebook/templates/config/facebooker.yml +46 -0
- data/generators/facebook/templates/public/javascripts/facebooker.js +99 -0
- data/generators/facebook_controller/USAGE +33 -0
- data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
- data/generators/facebook_controller/templates/controller.rb +7 -0
- data/generators/facebook_controller/templates/functional_test.rb +11 -0
- data/generators/facebook_controller/templates/helper.rb +2 -0
- data/generators/facebook_controller/templates/view.fbml.erb +2 -0
- data/generators/facebook_controller/templates/view.html.erb +2 -0
- data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
- data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
- data/generators/facebook_publisher/templates/publisher.rb +3 -0
- data/generators/facebook_scaffold/USAGE +27 -0
- data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
- data/generators/facebook_scaffold/templates/controller.rb +93 -0
- data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
- data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
- data/generators/facebook_scaffold/templates/helper.rb +2 -0
- data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
- data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
- data/generators/facebook_scaffold/templates/style.css +74 -0
- data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
- data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
- data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
- data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
- data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
- data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
- data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
- data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
- data/generators/publisher/publisher_generator.rb +14 -0
- data/generators/xd_receiver/templates/xd_receiver.html +10 -0
- data/generators/xd_receiver/xd_receiver_generator.rb +9 -0
- data/init.rb +72 -0
- data/install.rb +12 -0
- data/lib/facebooker/adapters/adapter_base.rb +87 -0
- data/lib/facebooker/adapters/bebo_adapter.rb +75 -0
- data/lib/facebooker/adapters/facebook_adapter.rb +52 -0
- data/lib/facebooker/admin.rb +42 -0
- data/lib/facebooker/batch_request.rb +44 -0
- data/lib/facebooker/data.rb +57 -0
- data/lib/facebooker/feed.rb +78 -0
- data/lib/facebooker/logging.rb +51 -0
- data/lib/facebooker/mobile.rb +20 -0
- data/lib/facebooker/mock/service.rb +50 -0
- data/lib/facebooker/mock/session.rb +18 -0
- data/lib/facebooker/model.rb +135 -0
- data/lib/facebooker/models/affiliation.rb +10 -0
- data/lib/facebooker/models/album.rb +11 -0
- data/lib/facebooker/models/applicationproperties.rb +39 -0
- data/lib/facebooker/models/applicationrestrictions.rb +10 -0
- data/lib/facebooker/models/cookie.rb +10 -0
- data/lib/facebooker/models/education_info.rb +11 -0
- data/lib/facebooker/models/event.rb +28 -0
- data/lib/facebooker/models/friend_list.rb +16 -0
- data/lib/facebooker/models/group.rb +36 -0
- data/lib/facebooker/models/info_item.rb +10 -0
- data/lib/facebooker/models/info_section.rb +10 -0
- data/lib/facebooker/models/location.rb +8 -0
- data/lib/facebooker/models/notifications.rb +17 -0
- data/lib/facebooker/models/page.rb +27 -0
- data/lib/facebooker/models/photo.rb +12 -0
- data/lib/facebooker/models/tag.rb +12 -0
- data/lib/facebooker/models/user.rb +426 -0
- data/lib/facebooker/models/video.rb +9 -0
- data/lib/facebooker/models/work_info.rb +9 -0
- data/lib/facebooker/parser.rb +589 -0
- data/lib/facebooker/rails/controller.rb +304 -0
- data/lib/facebooker/rails/cucumber/world.rb +46 -0
- data/lib/facebooker/rails/cucumber.rb +28 -0
- data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
- data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
- data/lib/facebooker/rails/facebook_request_fix.rb +24 -0
- data/lib/facebooker/rails/facebook_session_handling.rb +69 -0
- data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
- data/lib/facebooker/rails/facebook_url_rewriting.rb +39 -0
- data/lib/facebooker/rails/helpers/fb_connect.rb +89 -0
- data/lib/facebooker/rails/helpers.rb +762 -0
- data/lib/facebooker/rails/integration_session.rb +38 -0
- data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
- data/lib/facebooker/rails/publisher.rb +526 -0
- data/lib/facebooker/rails/routing.rb +49 -0
- data/lib/facebooker/rails/test_helpers.rb +68 -0
- data/lib/facebooker/rails/utilities.rb +22 -0
- data/lib/facebooker/server_cache.rb +24 -0
- data/lib/facebooker/service.rb +94 -0
- data/lib/facebooker/session.rb +584 -0
- data/lib/facebooker/version.rb +9 -0
- data/lib/facebooker.rb +174 -0
- data/lib/net/http_multipart_post.rb +123 -0
- data/lib/tasks/facebooker.rake +18 -0
- data/lib/tasks/tunnel.rake +46 -0
- data/rails/init.rb +1 -0
- data/setup.rb +1585 -0
- data/templates/layout.erb +24 -0
- data/test/facebooker/adapters_test.rb +96 -0
- data/test/facebooker/admin_test.rb +102 -0
- data/test/facebooker/batch_request_test.rb +83 -0
- data/test/facebooker/data_test.rb +86 -0
- data/test/facebooker/logging_test.rb +43 -0
- data/test/facebooker/mobile_test.rb +45 -0
- data/test/facebooker/model_test.rb +123 -0
- data/test/facebooker/models/event_test.rb +15 -0
- data/test/facebooker/models/user_test.rb +295 -0
- data/test/facebooker/rails/publisher_test.rb +452 -0
- data/test/facebooker/rails_integration_test.rb +1312 -0
- data/test/facebooker/server_cache_test.rb +44 -0
- data/test/facebooker/session_test.rb +614 -0
- data/test/facebooker_test.rb +925 -0
- data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
- data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
- data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
- data/test/net/http_multipart_post_test.rb +52 -0
- data/test/rails_test_helper.rb +11 -0
- data/test/test_helper.rb +66 -0
- metadata +217 -0
@@ -0,0 +1,304 @@
|
|
1
|
+
require 'facebooker'
|
2
|
+
require 'facebooker/rails/profile_publisher_extensions'
|
3
|
+
module Facebooker
|
4
|
+
module Rails
|
5
|
+
module Controller
|
6
|
+
include Facebooker::Rails::ProfilePublisherExtensions
|
7
|
+
def self.included(controller)
|
8
|
+
controller.extend(ClassMethods)
|
9
|
+
#controller.before_filter :set_adapter <-- security hole noted by vchu
|
10
|
+
controller.before_filter :set_facebook_request_format
|
11
|
+
controller.helper_attr :facebook_session_parameters
|
12
|
+
controller.helper_method :request_comes_from_facebook?
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def facebook_session
|
17
|
+
@facebook_session
|
18
|
+
end
|
19
|
+
|
20
|
+
def facebook_session_parameters
|
21
|
+
{:fb_sig_session_key=>params[:fb_sig_session_key]}
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_facebook_session
|
25
|
+
secure_with_facebook_params! || secure_with_cookies! || secure_with_token!
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_facebook_session
|
29
|
+
# first, see if we already have a session
|
30
|
+
session_set = session_already_secured?
|
31
|
+
# if not, see if we can load it from the environment
|
32
|
+
unless session_set
|
33
|
+
session_set = create_facebook_session
|
34
|
+
session[:facebook_session] = @facebook_session if session_set
|
35
|
+
end
|
36
|
+
if session_set
|
37
|
+
capture_facebook_friends_if_available!
|
38
|
+
Session.current = facebook_session
|
39
|
+
end
|
40
|
+
return session_set
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def facebook_params
|
45
|
+
@facebook_params ||= verified_facebook_params
|
46
|
+
end
|
47
|
+
|
48
|
+
def redirect_to(*args)
|
49
|
+
if request_is_for_a_facebook_canvas? and !request_is_facebook_tab?
|
50
|
+
render :text => fbml_redirect_tag(*args)
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def session_already_secured?
|
59
|
+
(@facebook_session = session[:facebook_session]) && session[:facebook_session].secured? if valid_session_key_in_session?
|
60
|
+
end
|
61
|
+
|
62
|
+
def user_has_deauthorized_application?
|
63
|
+
# if we're inside the facebook session and there is no session key,
|
64
|
+
# that means the user revoked our access
|
65
|
+
# we don't want to keep using the old expired key from the cookie.
|
66
|
+
request_comes_from_facebook? and params[:fb_sig_session_key].blank?
|
67
|
+
end
|
68
|
+
|
69
|
+
def clear_facebook_session_information
|
70
|
+
session[:facebook_session] = nil
|
71
|
+
@facebook_session=nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def valid_session_key_in_session?
|
75
|
+
#before we access the facebook_params, make sure we have the parameters
|
76
|
+
#otherwise we will blow up trying to access the secure parameters
|
77
|
+
if user_has_deauthorized_application?
|
78
|
+
clear_facebook_session_information
|
79
|
+
false
|
80
|
+
else
|
81
|
+
!session[:facebook_session].blank? && (params[:fb_sig_session_key].blank? || session[:facebook_session].session_key == facebook_params[:session_key])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def clear_fb_cookies!
|
86
|
+
domain_cookie_tag = "base_domain_#{Facebooker.api_key}"
|
87
|
+
cookie_domain = ".#{cookies[domain_cookie_tag]}" if cookies[domain_cookie_tag]
|
88
|
+
fb_cookie_names.each {|name| cookies.delete(name, :domain=>cookie_domain)}
|
89
|
+
cookies.delete Facebooker.api_key
|
90
|
+
end
|
91
|
+
|
92
|
+
def fb_cookie_prefix
|
93
|
+
Facebooker.api_key+"_"
|
94
|
+
end
|
95
|
+
|
96
|
+
def fb_cookie_names
|
97
|
+
fb_cookie_names = cookies.keys.select{|k| k.starts_with?(fb_cookie_prefix)}
|
98
|
+
end
|
99
|
+
|
100
|
+
def secure_with_cookies!
|
101
|
+
parsed = {}
|
102
|
+
|
103
|
+
fb_cookie_names.each { |key| parsed[key[fb_cookie_prefix.size,key.size]] = cookies[key] }
|
104
|
+
|
105
|
+
#returning gracefully if the cookies aren't set or have expired
|
106
|
+
return unless parsed['session_key'] && parsed['user'] && parsed['expires'] && parsed['ss']
|
107
|
+
return unless Time.at(parsed['expires'].to_f) > Time.now || (parsed['expires'] == "0")
|
108
|
+
|
109
|
+
#if we have the unexpired cookies, we'll throw an exception if the sig doesn't verify
|
110
|
+
verify_signature(parsed,cookies[Facebooker.api_key])
|
111
|
+
|
112
|
+
@facebook_session = new_facebook_session
|
113
|
+
@facebook_session.secure_with!(parsed['session_key'],parsed['user'],parsed['expires'],parsed['ss'])
|
114
|
+
@facebook_session
|
115
|
+
end
|
116
|
+
|
117
|
+
def secure_with_token!
|
118
|
+
if params['auth_token']
|
119
|
+
@facebook_session = new_facebook_session
|
120
|
+
@facebook_session.auth_token = params['auth_token']
|
121
|
+
@facebook_session.secure!
|
122
|
+
@facebook_session
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def secure_with_facebook_params!
|
127
|
+
return unless request_comes_from_facebook?
|
128
|
+
|
129
|
+
if ['user', 'session_key'].all? {|element| facebook_params[element]}
|
130
|
+
@facebook_session = new_facebook_session
|
131
|
+
@facebook_session.secure_with!(facebook_params['session_key'], facebook_params['user'], facebook_params['expires'])
|
132
|
+
@facebook_session
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
#override to specify where the user should be sent after logging in
|
137
|
+
def after_facebook_login_url
|
138
|
+
nil
|
139
|
+
end
|
140
|
+
|
141
|
+
def create_new_facebook_session_and_redirect!
|
142
|
+
session[:facebook_session] = new_facebook_session
|
143
|
+
url_params = after_facebook_login_url.nil? ? {} : {:next=>after_facebook_login_url}
|
144
|
+
redirect_to session[:facebook_session].login_url(url_params) unless @installation_required
|
145
|
+
false
|
146
|
+
end
|
147
|
+
|
148
|
+
def new_facebook_session
|
149
|
+
Facebooker::Session.create(Facebooker.api_key, Facebooker.secret_key)
|
150
|
+
end
|
151
|
+
|
152
|
+
def capture_facebook_friends_if_available!
|
153
|
+
return unless request_comes_from_facebook?
|
154
|
+
if friends = facebook_params['friends']
|
155
|
+
facebook_session.user.friends = friends.map do |friend_uid|
|
156
|
+
User.new(friend_uid, facebook_session)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def blank?(value)
|
162
|
+
(value == '0' || value.nil? || value == '')
|
163
|
+
end
|
164
|
+
|
165
|
+
def verified_facebook_params
|
166
|
+
facebook_sig_params = params.inject({}) do |collection, pair|
|
167
|
+
collection[pair.first.sub(/^fb_sig_/, '')] = pair.last if pair.first[0,7] == 'fb_sig_'
|
168
|
+
collection
|
169
|
+
end
|
170
|
+
verify_signature(facebook_sig_params,params['fb_sig'])
|
171
|
+
|
172
|
+
facebook_sig_params.inject(HashWithIndifferentAccess.new) do |collection, pair|
|
173
|
+
collection[pair.first] = facebook_parameter_conversions[pair.first].call(pair.last)
|
174
|
+
collection
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def earliest_valid_session
|
179
|
+
48.hours.ago
|
180
|
+
end
|
181
|
+
|
182
|
+
def verify_signature(facebook_sig_params,expected_signature)
|
183
|
+
raw_string = facebook_sig_params.map{ |*args| args.join('=') }.sort.join
|
184
|
+
actual_sig = Digest::MD5.hexdigest([raw_string, Facebooker::Session.secret_key].join)
|
185
|
+
raise Facebooker::Session::IncorrectSignature if actual_sig != expected_signature
|
186
|
+
raise Facebooker::Session::SignatureTooOld if facebook_sig_params['time'] && Time.at(facebook_sig_params['time'].to_f) < earliest_valid_session
|
187
|
+
true
|
188
|
+
end
|
189
|
+
|
190
|
+
def facebook_parameter_conversions
|
191
|
+
@facebook_parameter_conversions ||= Hash.new do |hash, key|
|
192
|
+
lambda{|value| value}
|
193
|
+
end.merge(
|
194
|
+
'time' => lambda{|value| Time.at(value.to_f)},
|
195
|
+
'in_canvas' => lambda{|value| !blank?(value)},
|
196
|
+
'added' => lambda{|value| !blank?(value)},
|
197
|
+
'expires' => lambda{|value| blank?(value) ? nil : Time.at(value.to_f)},
|
198
|
+
'friends' => lambda{|value| value.split(/,/)}
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
def fbml_redirect_tag(url)
|
203
|
+
"<fb:redirect url=\"#{url_for(url)}\" />"
|
204
|
+
end
|
205
|
+
|
206
|
+
def request_comes_from_facebook?
|
207
|
+
request_is_for_a_facebook_canvas? || request_is_facebook_ajax? || request_is_fb_ping?
|
208
|
+
end
|
209
|
+
|
210
|
+
def request_is_fb_ping?
|
211
|
+
!params['fb_sig'].blank?
|
212
|
+
end
|
213
|
+
|
214
|
+
def request_is_for_a_facebook_canvas?
|
215
|
+
!params['fb_sig_in_canvas'].blank?
|
216
|
+
end
|
217
|
+
|
218
|
+
def request_is_facebook_tab?
|
219
|
+
!params["fb_sig_in_profile_tab"].blank?
|
220
|
+
end
|
221
|
+
|
222
|
+
def request_is_facebook_ajax?
|
223
|
+
params["fb_sig_is_mockajax"]=="1" || params["fb_sig_is_ajax"]=="1"
|
224
|
+
end
|
225
|
+
def xml_http_request?
|
226
|
+
request_is_facebook_ajax? || super
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
def application_is_installed?
|
232
|
+
facebook_params['added']
|
233
|
+
end
|
234
|
+
|
235
|
+
def ensure_has_status_update
|
236
|
+
has_extended_permission?("status_update") || application_needs_permission("status_update")
|
237
|
+
end
|
238
|
+
def ensure_has_photo_upload
|
239
|
+
has_extended_permission?("photo_upload") || application_needs_permission("photo_upload")
|
240
|
+
end
|
241
|
+
def ensure_has_video_upload
|
242
|
+
has_extended_permission?("video_upload") || application_needs_permission("video_upload")
|
243
|
+
end
|
244
|
+
def ensure_has_create_listing
|
245
|
+
has_extended_permission?("create_listing") || application_needs_permission("create_listing")
|
246
|
+
end
|
247
|
+
|
248
|
+
def application_needs_permission(perm)
|
249
|
+
redirect_to(facebook_session.permission_url(perm))
|
250
|
+
end
|
251
|
+
|
252
|
+
def has_extended_permission?(perm)
|
253
|
+
params["fb_sig_ext_perms"] and params["fb_sig_ext_perms"].include?(perm)
|
254
|
+
end
|
255
|
+
|
256
|
+
def ensure_authenticated_to_facebook
|
257
|
+
set_facebook_session || create_new_facebook_session_and_redirect!
|
258
|
+
end
|
259
|
+
|
260
|
+
def ensure_application_is_installed_by_facebook_user
|
261
|
+
@installation_required = true
|
262
|
+
returning ensure_authenticated_to_facebook && application_is_installed? do |authenticated_and_installed|
|
263
|
+
application_is_not_installed_by_facebook_user unless authenticated_and_installed
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def application_is_not_installed_by_facebook_user
|
268
|
+
url_params = after_facebook_login_url.nil? ? {} : { :next => after_facebook_login_url }
|
269
|
+
redirect_to session[:facebook_session].install_url(url_params)
|
270
|
+
end
|
271
|
+
|
272
|
+
def set_facebook_request_format
|
273
|
+
if request_is_facebook_ajax?
|
274
|
+
params[:format] = 'fbjs'
|
275
|
+
elsif request_comes_from_facebook?
|
276
|
+
params[:format] = 'fbml'
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def set_adapter
|
281
|
+
Facebooker.load_adapter(params) if(params[:fb_sig_api_key])
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
module ClassMethods
|
286
|
+
#
|
287
|
+
# Creates a filter which reqires a user to have already authenticated to
|
288
|
+
# Facebook before executing actions. Accepts the same optional options hash which
|
289
|
+
# before_filter and after_filter accept.
|
290
|
+
def ensure_authenticated_to_facebook(options = {})
|
291
|
+
before_filter :ensure_authenticated_to_facebook, options
|
292
|
+
end
|
293
|
+
|
294
|
+
def ensure_application_is_installed_by_facebook_user(options = {})
|
295
|
+
before_filter :ensure_application_is_installed_by_facebook_user, options
|
296
|
+
end
|
297
|
+
|
298
|
+
def request_comes_from_facebook?
|
299
|
+
request_is_for_a_facebook_canvas? || request_is_facebook_ajax?
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'cucumber/rails/world'
|
2
|
+
require 'facebooker/rails/integration_session'
|
3
|
+
|
4
|
+
module Facebooker
|
5
|
+
module Rails
|
6
|
+
module Cucumber
|
7
|
+
class World < ::Cucumber::Rails::World
|
8
|
+
def open_session
|
9
|
+
session = Facebooker::Rails::IntegrationSession.new
|
10
|
+
|
11
|
+
# delegate the fixture accessors back to the test instance
|
12
|
+
extras = Module.new { attr_accessor :delegate, :test_result }
|
13
|
+
if self.class.respond_to?(:fixture_table_names)
|
14
|
+
self.class.fixture_table_names.each do |table_name|
|
15
|
+
name = table_name.tr(".", "_")
|
16
|
+
next unless respond_to?(name)
|
17
|
+
extras.__send__(:define_method, name) { |*args| delegate.send(name, *args) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# delegate add_assertion to the test case
|
22
|
+
extras.__send__(:define_method, :add_assertion) { test_result.add_assertion }
|
23
|
+
session.extend(extras)
|
24
|
+
session.delegate = self
|
25
|
+
session.test_result = @_result
|
26
|
+
|
27
|
+
yield session if block_given?
|
28
|
+
session
|
29
|
+
end
|
30
|
+
|
31
|
+
def without_canvas
|
32
|
+
in_canvas = @integration_session.canvas
|
33
|
+
@integration_session.canvas = false
|
34
|
+
yield
|
35
|
+
@integration_session.canvas = in_canvas
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
World do
|
43
|
+
w = Facebooker::Rails::Cucumber::World.new
|
44
|
+
w.reset!
|
45
|
+
w
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'facebooker/rails/cucumber/world'
|
2
|
+
require 'facebooker/mock/session'
|
3
|
+
require 'facebooker/mock/service'
|
4
|
+
|
5
|
+
Facebooker::MockService.fixture_path = File.join(RAILS_ROOT, 'features', 'support', 'facebook')
|
6
|
+
|
7
|
+
module Facebooker
|
8
|
+
class << self
|
9
|
+
# prevent Facebooker from adding canvas name as prefix to URLs
|
10
|
+
def request_for_canvas(arg)
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Rails
|
16
|
+
module Controller
|
17
|
+
# prevent Facebooker from rendering fb:redirect
|
18
|
+
def redirect_to(*args)
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return the mock session
|
23
|
+
def new_facebook_session
|
24
|
+
Facebooker::MockSession.create
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Facebooker
|
2
|
+
module Rails
|
3
|
+
class FacebookFormBuilder < ActionView::Helpers::FormBuilder
|
4
|
+
|
5
|
+
|
6
|
+
second_param = %w(password_field file_field check_box date_select datetime_select time_select)
|
7
|
+
third_param = %w(radio_button country_select select time_zone_select)
|
8
|
+
fifth_param = %w(collection_select)
|
9
|
+
|
10
|
+
def self.create_with_offset(name,offset)
|
11
|
+
define_method name do |field,*args|
|
12
|
+
options = args[offset] || {}
|
13
|
+
build_shell(field,options) do
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
second_param.each do |name|
|
20
|
+
create_with_offset(name,0)
|
21
|
+
end
|
22
|
+
third_param.each do |name|
|
23
|
+
create_with_offset(name,1)
|
24
|
+
end
|
25
|
+
fifth_param.each do |name|
|
26
|
+
create_with_offset(name,3)
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_shell(field,options)
|
30
|
+
@template.content_tag "fb:editor-custom", :label=>label_for(field,options) do
|
31
|
+
yield
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def label_for(field,options)
|
36
|
+
options[:label] || field.to_s.humanize
|
37
|
+
end
|
38
|
+
|
39
|
+
def text(string,options={})
|
40
|
+
@template.content_tag "fb:editor-custom",string, :label=>label_for("",options)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def text_field(method, options = {})
|
45
|
+
options[:label] ||= label_for(method,options)
|
46
|
+
add_default_name_and_id(options,method)
|
47
|
+
options["value"] ||= value_before_type_cast(object,method)
|
48
|
+
@template.content_tag("fb:editor-text","",options)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def text_area(method, options = {})
|
53
|
+
options[:label] ||= label_for(method,options)
|
54
|
+
add_default_name_and_id(options,method)
|
55
|
+
@template.content_tag("fb:editor-textarea",value_before_type_cast(object,method),options)
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Build a text input area that uses typeahed
|
60
|
+
# options are like collection_select
|
61
|
+
def collection_typeahead(method,collection,value_method,text_method,options={})
|
62
|
+
build_shell(method,options) do
|
63
|
+
collection_typeahead_internal(method,collection,value_method,text_method,options)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def collection_typeahead_internal(method,collection,value_method,text_method,options={})
|
68
|
+
option_values = collection.map do |item|
|
69
|
+
value=item.send(value_method)
|
70
|
+
text=item.send(text_method)
|
71
|
+
@template.content_tag "fb:typeahead-option",text,:value=>value
|
72
|
+
end.join
|
73
|
+
add_default_name_and_id(options,method)
|
74
|
+
options["value"] ||= value_before_type_cast(object,method)
|
75
|
+
@template.content_tag("fb:typeahead-input",option_values,options)
|
76
|
+
end
|
77
|
+
|
78
|
+
def value_before_type_cast(object,method)
|
79
|
+
unless object.nil?
|
80
|
+
method_name = method.to_s
|
81
|
+
object.respond_to?(method_name + "_before_type_cast") ?
|
82
|
+
object.send(method_name + "_before_type_cast") :
|
83
|
+
object.send(method_name)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def multi_friend_input(options={})
|
88
|
+
build_shell(:friends,options) do
|
89
|
+
@template.content_tag("fb:multi-friend-input","",options)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def buttons(*names)
|
94
|
+
buttons=names.map do |name|
|
95
|
+
create_button(name)
|
96
|
+
end.join
|
97
|
+
|
98
|
+
@template.content_tag "fb:editor-buttonset",buttons
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_button(name)
|
102
|
+
@template.content_tag("fb:editor-button","",:value=>name,:name=>"commit")
|
103
|
+
end
|
104
|
+
|
105
|
+
def add_default_name_and_id(options,method)
|
106
|
+
options[:name] ||= "#{object.class.name.underscore}[#{method}]"
|
107
|
+
options[:id] ||= "#{object.class.name.underscore}_#{method}"
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class ActionController::Base
|
2
|
+
def rescues_path_with_facebooker(template_name)
|
3
|
+
t = "#{RAILS_ROOT}/vendor/plugins/facebooker/templates/#{template_name}.erb"
|
4
|
+
if pretty_facebook_errors? && File.exist?(t)
|
5
|
+
t
|
6
|
+
else
|
7
|
+
rescues_path_without_facebooker(template_name)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
alias_method_chain :rescues_path, :facebooker
|
11
|
+
|
12
|
+
def response_code_for_rescue_with_facebooker(exception)
|
13
|
+
pretty_facebook_errors? ? 200 : response_code_for_rescue_without_facebooker(exception)
|
14
|
+
end
|
15
|
+
alias_method_chain :response_code_for_rescue, :facebooker
|
16
|
+
|
17
|
+
|
18
|
+
def pretty_facebook_errors?
|
19
|
+
Facebooker.facebooker_config['pretty_errors'] ||
|
20
|
+
(Facebooker.facebooker_config['pretty_errors'].nil? && RAILS_ENV=="development")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ::ActionController
|
2
|
+
class AbstractRequest
|
3
|
+
def request_method_with_facebooker
|
4
|
+
if parameters[:fb_sig_request_method]=="GET" and parameters[:_method].blank?
|
5
|
+
parameters[:_method]="GET"
|
6
|
+
end
|
7
|
+
request_method_without_facebooker
|
8
|
+
end
|
9
|
+
|
10
|
+
if new.methods.include?("request_method")
|
11
|
+
alias_method_chain :request_method, :facebooker
|
12
|
+
end
|
13
|
+
|
14
|
+
def xml_http_request_with_facebooker?
|
15
|
+
parameters["fb_sig_is_mockajax"] == "1" ||
|
16
|
+
parameters["fb_sig_is_ajax"] == "1" ||
|
17
|
+
xml_http_request_without_facebooker?
|
18
|
+
end
|
19
|
+
alias_method_chain :xml_http_request?, :facebooker
|
20
|
+
# we have to re-alias xhr? since it was pointing to the old method
|
21
|
+
alias xhr? :xml_http_request?
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module ActionController
|
2
|
+
class CgiRequest
|
3
|
+
alias :initialize_aliased_by_facebooker :initialize
|
4
|
+
|
5
|
+
def initialize(cgi, session_options = {})
|
6
|
+
initialize_aliased_by_facebooker(cgi, session_options)
|
7
|
+
@cgi.instance_variable_set("@request_params", request_parameters.merge(query_parameters))
|
8
|
+
end
|
9
|
+
|
10
|
+
DEFAULT_SESSION_OPTIONS[:cookie_only] = false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ActionController
|
15
|
+
class RackRequest < AbstractRequest #:nodoc:
|
16
|
+
alias :initialize_aliased_by_facebooker :initialize
|
17
|
+
|
18
|
+
def initialize(cgi, session_options = {})
|
19
|
+
initialize_aliased_by_facebooker(cgi, session_options)
|
20
|
+
@cgi.instance_variable_set("@request_params", request_parameters.merge(query_parameters))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class CGI
|
26
|
+
class Session
|
27
|
+
private
|
28
|
+
alias :initialize_aliased_by_facebooker :initialize
|
29
|
+
attr_reader :request, :initialization_options
|
30
|
+
|
31
|
+
def initialize(request, option={})
|
32
|
+
@request = request
|
33
|
+
@initialization_options = option
|
34
|
+
option['session_id'] ||= set_session_id
|
35
|
+
initialize_aliased_by_facebooker(request, option)
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_session_id
|
39
|
+
if session_key_should_be_set_with_facebook_session_key?
|
40
|
+
request_parameters[facebook_session_key]
|
41
|
+
else
|
42
|
+
request_parameters[session_key]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def request_parameters
|
47
|
+
request.instance_variable_get("@request_params")
|
48
|
+
end
|
49
|
+
|
50
|
+
def session_key_should_be_set_with_facebook_session_key?
|
51
|
+
request_parameters[session_key].blank? && !request_parameters[facebook_session_key].blank?
|
52
|
+
end
|
53
|
+
|
54
|
+
def session_key
|
55
|
+
initialization_options['session_key'] || '_session_id'
|
56
|
+
end
|
57
|
+
|
58
|
+
def facebook_session_key
|
59
|
+
'fb_sig_session_key'
|
60
|
+
end
|
61
|
+
|
62
|
+
alias :create_new_id_aliased_by_facebooker :create_new_id
|
63
|
+
|
64
|
+
def create_new_id
|
65
|
+
@new_session = true
|
66
|
+
@session_id || create_new_id_aliased_by_facebooker
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|