mmangino-facebooker 1.0.44 → 1.0.45
Sign up to get free protection for your applications and to get access to all the features.
- data/facebooker.gemspec +2 -2
- data/lib/facebooker.rb +11 -9
- data/lib/facebooker/adapters/adapter_base.rb +1 -1
- data/lib/facebooker/rails/controller.rb +0 -5
- data/lib/facebooker/rails/helpers.rb +14 -4
- data/lib/facebooker/rails/publisher.rb +1 -1
- data/lib/facebooker/service/curl_service.rb +3 -2
- data/lib/facebooker/version.rb +1 -1
- data/test/facebooker/adapters_test.rb +17 -0
- data/test/facebooker/rails/publisher_test.rb +4 -3
- data/test/facebooker/rails_integration_test.rb +45 -29
- data/test/rack/facebook_test.rb +15 -8
- metadata +2 -2
data/facebooker.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{facebooker}
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.45"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Chad Fowler", "Patrick Ewing", "Mike Mangino", "Shane Vitarana", "Corey Innis"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-24}
|
10
10
|
s.description = %q{Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://wiki.developers.facebook.com/index.php/API]. Its goals are:
|
11
11
|
|
12
12
|
* Idiomatic Ruby
|
data/lib/facebooker.rb
CHANGED
@@ -36,14 +36,13 @@ module Facebooker
|
|
36
36
|
class << self
|
37
37
|
|
38
38
|
def load_configuration(facebooker_yaml_file)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
Thread.current[:fb_api_config] = @raw_facebooker_configuration unless Thread.current[:fb_api_config]
|
45
|
-
apply_configuration(@raw_facebooker_configuration)
|
39
|
+
return false unless File.exist?(facebooker_yaml_file)
|
40
|
+
@raw_facebooker_configuration = YAML.load(ERB.new(File.read(facebooker_yaml_file)).result)
|
41
|
+
if defined? RAILS_ENV
|
42
|
+
@raw_facebooker_configuration = @raw_facebooker_configuration[RAILS_ENV]
|
46
43
|
end
|
44
|
+
Thread.current[:fb_api_config] = @raw_facebooker_configuration unless Thread.current[:fb_api_config]
|
45
|
+
apply_configuration(@raw_facebooker_configuration)
|
47
46
|
end
|
48
47
|
|
49
48
|
# Sets the Facebook environment based on a hash of options.
|
@@ -61,7 +60,10 @@ module Facebooker
|
|
61
60
|
ActionController::Base.asset_host = config['callback_url']
|
62
61
|
end
|
63
62
|
Facebooker.timeout = config['timeout']
|
64
|
-
|
63
|
+
|
64
|
+
@facebooker_configuration = config # must be set before adapter loaded
|
65
|
+
load_adapter(:fb_sig_api_key => config['api_key'])
|
66
|
+
facebooker_config
|
65
67
|
end
|
66
68
|
|
67
69
|
def facebooker_config
|
@@ -87,7 +89,7 @@ module Facebooker
|
|
87
89
|
Thread.current[:fb_api_config] = apply_configuration(config)
|
88
90
|
yield
|
89
91
|
ensure
|
90
|
-
Thread.current[:fb_api_config] = old if old
|
92
|
+
Thread.current[:fb_api_config] = old if old && !old.empty?
|
91
93
|
apply_configuration(Thread.current[:fb_api_config])
|
92
94
|
end
|
93
95
|
end
|
@@ -7,7 +7,6 @@ module Facebooker
|
|
7
7
|
include Facebooker::Rails::ProfilePublisherExtensions
|
8
8
|
def self.included(controller)
|
9
9
|
controller.extend(ClassMethods)
|
10
|
-
controller.before_filter :set_adapter
|
11
10
|
controller.before_filter :set_facebook_request_format
|
12
11
|
controller.helper_attr :facebook_session_parameters
|
13
12
|
controller.helper_method :request_comes_from_facebook?
|
@@ -333,10 +332,6 @@ module Facebooker
|
|
333
332
|
end
|
334
333
|
end
|
335
334
|
|
336
|
-
def set_adapter
|
337
|
-
Facebooker.load_adapter(params) if(params[:fb_sig_api_key])
|
338
|
-
end
|
339
|
-
|
340
335
|
|
341
336
|
module ClassMethods
|
342
337
|
#
|
@@ -187,10 +187,10 @@ module Facebooker
|
|
187
187
|
# <fb:editor-button label="Save Poke"
|
188
188
|
# </fb:editor-buttonset>
|
189
189
|
# </fb:editor>
|
190
|
-
|
190
|
+
def facebook_form_for( record_or_name_or_array,*args, &proc)
|
191
191
|
|
192
|
-
|
193
|
-
|
192
|
+
raise ArgumentError, "Missing block" unless block_given?
|
193
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
194
194
|
|
195
195
|
case record_or_name_or_array
|
196
196
|
when String, Symbol
|
@@ -230,8 +230,18 @@ module Facebooker
|
|
230
230
|
fields_for( object_name,*(args << options), &proc)
|
231
231
|
concat("</fb:editor>",proc.binding)
|
232
232
|
end
|
233
|
-
|
233
|
+
end
|
234
234
|
|
235
|
+
# Render an fb:application-name tag
|
236
|
+
#
|
237
|
+
# This renders the current application name via fbml. See
|
238
|
+
# http://wiki.developers.facebook.com/index.php/Fb:application-name
|
239
|
+
# for a full description.
|
240
|
+
#
|
241
|
+
def fb_application_name(options={})
|
242
|
+
tag "fb:application-name", stringify_vals(options)
|
243
|
+
end
|
244
|
+
|
235
245
|
# Render an fb:name tag for the given user
|
236
246
|
# This renders the name of the user specified. You can use this tag as both subject and object of
|
237
247
|
# a sentence. <em> See </em> http://wiki.developers.facebook.com/index.php/Fb:name for full description.
|
@@ -2,11 +2,12 @@ require 'curb'
|
|
2
2
|
Facebooker.use_curl = true
|
3
3
|
class Facebooker::Service::CurlService < Facebooker::Service::BaseService
|
4
4
|
def post_form(url,params,multipart=false)
|
5
|
-
|
5
|
+
curl = Curl::Easy.new(url.to_s) do |c|
|
6
6
|
c.multipart_form_post = multipart
|
7
7
|
c.timeout = Facebooker.timeout
|
8
8
|
end
|
9
|
-
|
9
|
+
curl.http_post(*to_curb_params(params))
|
10
|
+
curl.body_str
|
10
11
|
end
|
11
12
|
|
12
13
|
def post_multipart_form(url,params)
|
data/lib/facebooker/version.rb
CHANGED
@@ -171,4 +171,21 @@ class Facebooker::AdaptersTest < Test::Unit::TestCase
|
|
171
171
|
assert_equal 'my secret key', @secret_in_outer_block
|
172
172
|
end
|
173
173
|
|
174
|
+
def test_adapter_loaded_when_config_applied
|
175
|
+
flexmock( Facebooker ).
|
176
|
+
should_receive( :fetch_config_for ).
|
177
|
+
and_return(
|
178
|
+
{ 'api_key' => 'a_key',
|
179
|
+
'canvas_page_name' => 'default_name' },
|
180
|
+
{ 'api_key' => 'another_key',
|
181
|
+
'canvas_page_name' => 'alternative_name' }
|
182
|
+
)
|
183
|
+
Facebooker.with_application('a_key') do
|
184
|
+
assert_equal 'default_name', Facebooker.current_adapter.facebooker_config['canvas_page_name']
|
185
|
+
Facebooker.with_application('another_key') do
|
186
|
+
assert_equal 'alternative_name', Facebooker.current_adapter.facebooker_config['canvas_page_name']
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
174
191
|
end
|
@@ -145,6 +145,7 @@ class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
|
|
145
145
|
|
146
146
|
def setup
|
147
147
|
super
|
148
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
148
149
|
@template = mock("facebook template")
|
149
150
|
FacebookTemplate.stubs(:register).returns(@template)
|
150
151
|
FacebookTemplate.clear_cache!
|
@@ -167,13 +168,13 @@ class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
|
|
167
168
|
end
|
168
169
|
|
169
170
|
def test_find_in_db_should_run_find
|
170
|
-
FacebookTemplate.expects(:find_by_template_name).with("TestPublisher::simple_user_action").returns(@template)
|
171
|
+
FacebookTemplate.expects(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(@template)
|
171
172
|
@template.stubs(:template_changed?).returns(false)
|
172
173
|
assert_equal FacebookTemplate.find_in_db(TestPublisher,"simple_user_action"), @template
|
173
174
|
end
|
174
175
|
|
175
176
|
def test_find_in_db_should_register_if_not_found
|
176
|
-
FacebookTemplate.expects(:find_by_template_name).with("TestPublisher::simple_user_action").returns(nil)
|
177
|
+
FacebookTemplate.expects(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(nil)
|
177
178
|
FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
|
178
179
|
FacebookTemplate.find_cached(TestPublisher,"simple_user_action")
|
179
180
|
|
@@ -195,7 +196,7 @@ class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
|
|
195
196
|
end
|
196
197
|
|
197
198
|
def test_find_in_db_should_re_register_if_changed
|
198
|
-
FacebookTemplate.stubs(:find_by_template_name).with("TestPublisher::simple_user_action").returns(@template)
|
199
|
+
FacebookTemplate.stubs(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(@template)
|
199
200
|
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
200
201
|
@template.stubs(:template_changed?).returns(true)
|
201
202
|
@template.stubs(:destroy)
|
@@ -160,9 +160,10 @@ class RailsIntegrationTestForFBConnect < Test::Unit::TestCase
|
|
160
160
|
include FBConnectTestHelpers
|
161
161
|
|
162
162
|
def setup
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
Facebooker.apply_configuration({
|
164
|
+
'api_key' => '1234567',
|
165
|
+
'canvas_page_name' => 'facebook_app_name',
|
166
|
+
'secret_key' => '7654321' })
|
166
167
|
@controller = FBConnectController.new
|
167
168
|
@request = ActionController::TestRequest.new
|
168
169
|
@response = ActionController::TestResponse.new
|
@@ -181,9 +182,10 @@ end
|
|
181
182
|
|
182
183
|
class RailsIntegrationTestForNonFacebookControllers < Test::Unit::TestCase
|
183
184
|
def setup
|
184
|
-
|
185
|
-
|
186
|
-
|
185
|
+
Facebooker.apply_configuration({
|
186
|
+
'api_key' => '1234567',
|
187
|
+
'canvas_page_name' => 'facebook_app_name',
|
188
|
+
'secret_key' => '7654321' })
|
187
189
|
@controller = PlainOldRailsController.new
|
188
190
|
@request = ActionController::TestRequest.new
|
189
191
|
@response = ActionController::TestResponse.new
|
@@ -216,8 +218,9 @@ end
|
|
216
218
|
|
217
219
|
class RailsIntegrationTestForExtendedPermissions < Test::Unit::TestCase
|
218
220
|
def setup
|
219
|
-
|
220
|
-
|
221
|
+
Facebooker.apply_configuration({
|
222
|
+
'api_key' => '1234567',
|
223
|
+
'secret_key' => '7654321' })
|
221
224
|
@controller = ControllerWhichRequiresExtendedPermissions.new
|
222
225
|
@request = ActionController::TestRequest.new
|
223
226
|
@response = ActionController::TestResponse.new
|
@@ -255,8 +258,9 @@ end
|
|
255
258
|
|
256
259
|
class RailsIntegrationTestForApplicationInstallation < Test::Unit::TestCase
|
257
260
|
def setup
|
258
|
-
|
259
|
-
|
261
|
+
Facebooker.apply_configuration({
|
262
|
+
'api_key' => '1234567',
|
263
|
+
'secret_key' => '7654321' })
|
260
264
|
@controller = ControllerWhichRequiresApplicationInstallation.new
|
261
265
|
@request = ActionController::TestRequest.new
|
262
266
|
@response = ActionController::TestResponse.new
|
@@ -285,10 +289,12 @@ end
|
|
285
289
|
class RailsIntegrationTest < Test::Unit::TestCase
|
286
290
|
include FBConnectTestHelpers
|
287
291
|
def setup
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
+
Facebooker.apply_configuration({
|
293
|
+
'api_key' => '1234567',
|
294
|
+
'canvas_page_name' => 'root',
|
295
|
+
'secret_key' => '7654321',
|
296
|
+
'set_asset_host_to_callback_url' => true,
|
297
|
+
'callback_url' => "http://root.example.com" })
|
292
298
|
@controller = ControllerWhichRequiresFacebookAuthentication.new
|
293
299
|
@request = ActionController::TestRequest.new
|
294
300
|
@response = ActionController::TestResponse.new
|
@@ -296,10 +302,10 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
296
302
|
|
297
303
|
end
|
298
304
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
305
|
+
def test_named_route_includes_new_canvas_path_when_in_new_canvas
|
306
|
+
get :named_route_test, facebook_params("fb_sig_in_new_facebook"=>"1")
|
307
|
+
assert_equal "http://apps.facebook.com/root/comments",@response.body
|
308
|
+
end
|
303
309
|
|
304
310
|
def test_if_controller_requires_facebook_authentication_unauthenticated_requests_will_redirect
|
305
311
|
get :index
|
@@ -532,9 +538,10 @@ end
|
|
532
538
|
|
533
539
|
class RailsSignatureTest < Test::Unit::TestCase
|
534
540
|
def setup
|
535
|
-
|
536
|
-
|
537
|
-
|
541
|
+
Facebooker.apply_configuration({
|
542
|
+
'api_key' => '1234567',
|
543
|
+
'canvas_page_name' => 'root',
|
544
|
+
'secret_key' => '7654321' })
|
538
545
|
@controller = ControllerWhichRequiresFacebookAuthentication.new
|
539
546
|
@request = ActionController::TestRequest.new
|
540
547
|
@response = ActionController::TestResponse.new
|
@@ -597,10 +604,10 @@ class RailsHelperTest < Test::Unit::TestCase
|
|
597
604
|
attr_accessor :_erbout
|
598
605
|
|
599
606
|
def setup
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
607
|
+
Facebooker.apply_configuration({
|
608
|
+
'api_key' => '1234567',
|
609
|
+
'canvas_page_name' => 'facebook',
|
610
|
+
'secret_key' => '7654321' })
|
604
611
|
@_erbout = ""
|
605
612
|
@h = HelperClass.new
|
606
613
|
#use an asset path where the canvas path equals the hostname to make sure we handle that case right
|
@@ -692,7 +699,15 @@ class RailsHelperTest < Test::Unit::TestCase
|
|
692
699
|
assert_equal "<fb:add-section-button section=\"info\" />",@h.fb_add_info_section
|
693
700
|
end
|
694
701
|
|
695
|
-
def
|
702
|
+
def test_fb_application_name
|
703
|
+
assert_equal "<fb:application-name />", @h.fb_application_name
|
704
|
+
end
|
705
|
+
|
706
|
+
def test_fb_application_name_with_linked_false
|
707
|
+
assert_equal '<fb:application-name linked="false" />', @h.fb_application_name( :linked => false )
|
708
|
+
end
|
709
|
+
|
710
|
+
def test_fb_name_with_invalid_key_size
|
696
711
|
assert_raises(ArgumentError) {@h.fb_name(1234, :sizee => false)}
|
697
712
|
end
|
698
713
|
|
@@ -1411,9 +1426,10 @@ class RailsRequestFormatTest < Test::Unit::TestCase
|
|
1411
1426
|
end
|
1412
1427
|
|
1413
1428
|
def setup
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1429
|
+
Facebooker.apply_configuration({
|
1430
|
+
'api_key' => '1234567',
|
1431
|
+
'canvas_page_name' => 'facebook_app_name',
|
1432
|
+
'secret_key' => '7654321' })
|
1417
1433
|
@controller = FacebookController.new
|
1418
1434
|
@request = ActionController::TestRequest.new
|
1419
1435
|
@response = ActionController::TestResponse.new
|
data/test/rack/facebook_test.rb
CHANGED
@@ -7,11 +7,20 @@ class Rack::FacebookTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
def setup
|
9
9
|
flexmock(Facebooker).should_receive(:secret_key).and_return('secret')
|
10
|
+
flexmock(Facebooker).should_receive(:load_adapter)
|
10
11
|
@app = lambda do |env|
|
11
12
|
@env = env
|
12
13
|
Rack::Response.new().to_a
|
13
14
|
end
|
14
15
|
@facebook = Rack::Facebook.new(@app)
|
16
|
+
@valid_params = {
|
17
|
+
:fb_sig_user => '1',
|
18
|
+
:fb_sig => 'ignored'
|
19
|
+
}
|
20
|
+
@page = Proc.new {|options|
|
21
|
+
options ||= @valid_params
|
22
|
+
app.post "/", :input => params(options)
|
23
|
+
}
|
15
24
|
end
|
16
25
|
|
17
26
|
def params(p)
|
@@ -28,39 +37,37 @@ class Rack::FacebookTest < Test::Unit::TestCase
|
|
28
37
|
end
|
29
38
|
|
30
39
|
def test_converts_request_method
|
31
|
-
response =
|
32
|
-
:input => params(:fb_sig_request_method => 'GET', :fb_sig => '4d2a700e90b0bcbe54b9e627d2cc1417'))
|
40
|
+
response = @page.call(:fb_sig_request_method => 'GET', :fb_sig => '4d2a700e90b0bcbe54b9e627d2cc1417')
|
33
41
|
assert_equal 200, response.status
|
34
42
|
assert_equal 'GET', @env['REQUEST_METHOD']
|
35
43
|
end
|
36
44
|
|
37
45
|
def test_only_sets_request_method_if_provided
|
38
|
-
response =
|
46
|
+
response = @page.call(:fb_sig_user => '1', :fb_sig => '313dd5caed3d0902d83225ff3ae9a950')
|
39
47
|
assert_equal 200, response.status
|
40
48
|
assert_equal 'POST', @env['REQUEST_METHOD']
|
41
49
|
end
|
42
50
|
|
43
51
|
def test_renders_400_with_invalid_signature
|
44
|
-
response =
|
45
|
-
:input => params(:fb_sig => 'wrong', :fb_sig_user => 1))
|
52
|
+
response = @page.call(:fb_sig => 'wrong', :fb_sig_user => 1)
|
46
53
|
assert_equal 400, response.status
|
47
54
|
end
|
48
55
|
|
49
56
|
def test_skips_with_false_condition
|
50
57
|
@facebook = Rack::Facebook.new(@app) { false }
|
51
|
-
response =
|
58
|
+
response = @page.call({})
|
52
59
|
assert_equal 200, response.status
|
53
60
|
end
|
54
61
|
|
55
62
|
def test_skips_with_true_condition_without_fb_sig
|
56
63
|
@facebook = Rack::Facebook.new(@app) { true }
|
57
|
-
response =
|
64
|
+
response = @page.call(:fb_sig_user => 'ignored')
|
58
65
|
assert_equal 200, response.status
|
59
66
|
end
|
60
67
|
|
61
68
|
def test_verifies_with_true_condition_with_fb_sig
|
62
69
|
@facebook = Rack::Facebook.new(@app) { true }
|
63
|
-
response =
|
70
|
+
response = @page.call(:fb_sig => 'wrong', :fb_sig_user => 'ignored')
|
64
71
|
assert_equal 400, response.status
|
65
72
|
end
|
66
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mmangino-facebooker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.45
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Fowler
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2009-07-
|
16
|
+
date: 2009-07-24 00:00:00 -07:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|