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,24 @@
|
|
1
|
+
<fb:fbml>
|
2
|
+
<style>
|
3
|
+
body { background-color: #fff; color: #333; }
|
4
|
+
|
5
|
+
body, p, ol, ul, td {
|
6
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
7
|
+
font-size: 13px;
|
8
|
+
line-height: 18px;
|
9
|
+
}
|
10
|
+
|
11
|
+
pre {
|
12
|
+
background-color: #eee;
|
13
|
+
padding: 10px;
|
14
|
+
font-size: 11px;
|
15
|
+
}
|
16
|
+
|
17
|
+
a { color: #000; }
|
18
|
+
a:visited { color: #666; }
|
19
|
+
a:hover { color: #fff; background-color:#000; }
|
20
|
+
</style>
|
21
|
+
|
22
|
+
<%= @contents %>
|
23
|
+
|
24
|
+
</fb:fbml>
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::SessionTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
6
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
7
|
+
Facebooker.current_adapter = nil
|
8
|
+
@bebo_api_key = "bebo_api_key"; @bebo_secret_key = "bebo_secret_key"
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
flexmock_close
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_load_default_adapter
|
16
|
+
session = Facebooker::CanvasSession.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
|
17
|
+
assert_equal(ENV['FACEBOOK_API_KEY'], Facebooker::Session.api_key)
|
18
|
+
assert( Facebooker::FacebookAdapter === Facebooker.current_adapter)
|
19
|
+
|
20
|
+
ENV['FACEBOOK_API_KEY'] = nil
|
21
|
+
ENV['FACEBOOK_SECRET_KEY'] = nil
|
22
|
+
Facebooker.current_adapter = nil
|
23
|
+
Facebooker::AdapterBase.stubs(:facebooker_config).returns({"api_key" => "facebook_key", "secret_key" => "facebook_secret" })
|
24
|
+
assert( Facebooker::FacebookAdapter === Facebooker.current_adapter)
|
25
|
+
assert_equal("facebook_key", Facebooker::Session.api_key)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_load_bebo_adapter
|
29
|
+
|
30
|
+
load_bebo_adapter
|
31
|
+
assert_equal(@bebo_api_key, Facebooker::Session.api_key)
|
32
|
+
assert_equal(@bebo_secret_key, Facebooker::Session.secret_key)
|
33
|
+
assert(Facebooker::BeboAdapter === Facebooker.current_adapter, " Bebo adapter not loaded correctly.")
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_bebo_adapter
|
37
|
+
@bebo_api_key = "bebo_api_key"; @bebo_secret_key = "bebo_secret_key"
|
38
|
+
|
39
|
+
Facebooker::AdapterBase.stubs(:facebooker_config).returns({"bebo_api_key" => @bebo_api_key, "bebo_adapter" => "BeboAdapter", "bebo_secret_key" => @bebo_secret_key, "foo" => "bar"})
|
40
|
+
Facebooker.load_adapter(:config_key_base => "bebo")
|
41
|
+
@session = Facebooker::CanvasSession.create(@bebo_api_key, @bebo_secret_key)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_adapter_details
|
45
|
+
test_load_default_adapter
|
46
|
+
|
47
|
+
assert_equal("apps.facebook.com", Facebooker.canvas_server_base)
|
48
|
+
assert_equal("api.facebook.com", Facebooker.api_server_base)
|
49
|
+
assert_equal("www.facebook.com", Facebooker.www_server_base_url)
|
50
|
+
assert_equal("http://api.facebook.com", Facebooker.api_server_base_url)
|
51
|
+
assert(Facebooker.is_for?(:facebook))
|
52
|
+
load_bebo_adapter
|
53
|
+
|
54
|
+
assert_equal("apps.bebo.com", Facebooker.canvas_server_base)
|
55
|
+
assert_equal("apps.bebo.com", Facebooker.api_server_base)
|
56
|
+
assert_equal("www.bebo.com", Facebooker.www_server_base_url)
|
57
|
+
assert_equal("http://apps.bebo.com", Facebooker.api_server_base_url)
|
58
|
+
assert_equal("http://www.bebo.com/SignIn.jsp?ApiKey=bebo_api_key&v=1.0&canvas=true", @session.login_url)
|
59
|
+
assert_equal("http://www.bebo.com/c/apps/add?ApiKey=bebo_api_key&v=1.0", @session.install_url)
|
60
|
+
assert(Facebooker.is_for?(:bebo))
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_adapter_failures
|
65
|
+
Facebooker::AdapterBase.stubs(:facebooker_config).returns({})
|
66
|
+
|
67
|
+
assert_raises(Facebooker::AdapterBase::UnableToLoadAdapter){
|
68
|
+
Facebooker.load_adapter(:config_key_base => "bebo")
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_bebo_specific_issues
|
73
|
+
load_bebo_adapter
|
74
|
+
|
75
|
+
# @session.send(:service).stubs(:post).returns([{:name => "foo"}])
|
76
|
+
Net::HTTP.stubs(:post_form).returns("<profile_setFBML_response></profile_setFBML_response>")
|
77
|
+
user = Facebooker::User.new(:uid => "123456")
|
78
|
+
user.session = @session
|
79
|
+
user.set_profile_fbml("foo","bar","foo")
|
80
|
+
assert(true)
|
81
|
+
Net::HTTP.stubs(:post_form).returns("<users_getInfo_response> <user><uid>123456</uid><name>foo</name></user></users_getInfo_response>")
|
82
|
+
user.populate(:name)
|
83
|
+
assert(true)
|
84
|
+
assert_equal("foo", user.name)
|
85
|
+
action = Facebooker::Feed::TemplatizedAction.new()
|
86
|
+
action.title_template = "foo"
|
87
|
+
Net::HTTP.stubs(:post_form).returns("<feed_publishTemplatizedAction_response>1</feed_publishTemplatizedAction_response>")
|
88
|
+
user.publish_templatized_action(action)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_bebo_process_data
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::AdminTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@session = Facebooker::Session.create('apikey', 'secretkey')
|
6
|
+
Facebooker.use_curl=false
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_can_ask_facebook_to_set_app_properties
|
10
|
+
expect_http_posts_with_responses(example_set_properties_xml)
|
11
|
+
properties = { :application_name => "Video Jukebox", :dev_mode => 0 }
|
12
|
+
assert(@session.admin.set_app_properties(properties))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_set_app_properties_json_conversion
|
16
|
+
properties = { :application_name => "Video Jukebox", :dev_mode => 0 }
|
17
|
+
flexmock(@session).should_receive(:post).with('facebook.admin.setAppProperties', :properties => properties.to_json).and_return('1').once
|
18
|
+
assert(@session.admin.set_app_properties(properties))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_can_ask_facebook_to_get_app_properties
|
22
|
+
expect_http_posts_with_responses(example_get_properties_xml)
|
23
|
+
properties = [ :application_name, :dev_mode ]
|
24
|
+
assert(@session.admin.get_app_properties(properties))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_can_get_properties
|
28
|
+
mock_http = establish_session
|
29
|
+
mock_http.should_receive(:post_form).and_return(example_get_properties_xml).once.ordered(:posts)
|
30
|
+
p = @session.admin.get_app_properties(:application_name, :dev_mode, :canvas_name)
|
31
|
+
assert_equal 'Video Jukebox', p.application_name
|
32
|
+
assert_equal 0, p.dev_mode
|
33
|
+
assert_equal 'my_canvas', p.canvas_name
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_can_set_restriction_info
|
37
|
+
restrictions = {:age => '21', :type => 'alcohol'}
|
38
|
+
flexmock(@session).should_receive(:post).with('facebook.admin.setRestrictionInfo', :restriction_str => restrictions.to_json).and_return('1').once
|
39
|
+
assert(@session.admin.set_restriction_info(restrictions))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_can_get_restriction_info
|
43
|
+
mock_http = establish_session
|
44
|
+
mock_http.should_receive(:post_form).and_return(example_get_restriction_info_xml).once.ordered(:posts)
|
45
|
+
r = @session.admin.get_restriction_info
|
46
|
+
assert_equal 'alcohol', r.type
|
47
|
+
assert_equal '21', r.age
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_can_get_allocation
|
51
|
+
mock_http = establish_session
|
52
|
+
mock_http.should_receive(:post_form).and_return(example_get_allocation_xml).once.ordered(:posts)
|
53
|
+
alloc = @session.admin.get_allocation(:notifications_per_day)
|
54
|
+
assert_equal 40, alloc
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def example_set_properties_xml
|
59
|
+
<<-XML
|
60
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
61
|
+
<admin_setAppProperties_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
62
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</admin_setAppProperties_response>
|
63
|
+
XML
|
64
|
+
end
|
65
|
+
|
66
|
+
def example_get_properties_xml
|
67
|
+
<<-XML
|
68
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
69
|
+
<admin_getAppProperties_response
|
70
|
+
xmlns="http://api.facebook.com/1.0/"
|
71
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
72
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
73
|
+
{"application_name":"Video Jukebox","callback_url":"http:\/\/67.207.144.245\/","dev_mode":0,"canvas_name":"my_canvas"}
|
74
|
+
</admin_getAppProperties_response>
|
75
|
+
XML
|
76
|
+
end
|
77
|
+
|
78
|
+
def example_get_restriction_info_xml
|
79
|
+
<<-XML
|
80
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
81
|
+
<admin_getRestrictionInfo_response
|
82
|
+
xmlns="http://api.facebook.com/1.0/"
|
83
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
84
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
85
|
+
{"age":"21","location":"","age_distribution":"","type":"alcohol"}
|
86
|
+
</admin_getRestrictionInfo_response>
|
87
|
+
XML
|
88
|
+
end
|
89
|
+
|
90
|
+
def example_get_allocation_xml
|
91
|
+
<<-XML
|
92
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
93
|
+
<admin_getAllocation_response
|
94
|
+
xmlns="http://api.facebook.com/1.0/"
|
95
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
96
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
97
|
+
40
|
98
|
+
</admin_getAllocation_response>
|
99
|
+
XML
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::BatchRequestTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@proc_called=false
|
7
|
+
@batch_request=Facebooker::BatchRequest.new({:params=>true},nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_can_set_result
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_can_set_result_with_proc_and_have_proc_called
|
15
|
+
p=Proc.new {@proc_called=true}
|
16
|
+
|
17
|
+
@batch_request=Facebooker::BatchRequest.new({:params=>true},p)
|
18
|
+
@batch_request.result="Mike"
|
19
|
+
assert @proc_called
|
20
|
+
end
|
21
|
+
def test_can_set_result_with_proc_and_use_proc_result
|
22
|
+
p=Proc.new {@proc_called=true}
|
23
|
+
|
24
|
+
@batch_request=Facebooker::BatchRequest.new({:params=>true},p)
|
25
|
+
@batch_request.result="Mike"
|
26
|
+
assert @batch_request
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_proxies_methods
|
30
|
+
@batch_request.result="Mike"
|
31
|
+
assert @batch_request == "Mike"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_threequal_works
|
35
|
+
@batch_request.result="Mike"
|
36
|
+
assert @batch_request === String
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_can_set_exception_and_check_it
|
40
|
+
@batch_request.exception_raised=ArgumentError.new
|
41
|
+
assert_raises(ArgumentError) {
|
42
|
+
@batch_request.exception_raised?
|
43
|
+
}
|
44
|
+
end
|
45
|
+
def test_can_set_exception_and_have_it_raised_on_access
|
46
|
+
@batch_request.exception_raised=ArgumentError.new
|
47
|
+
assert_raises(ArgumentError) {
|
48
|
+
@batch_request == true
|
49
|
+
}
|
50
|
+
end
|
51
|
+
def test_exception_raised_false_when_no_exception
|
52
|
+
@batch_request.result="Mike"
|
53
|
+
assert ! @batch_request.exception_raised?
|
54
|
+
end
|
55
|
+
|
56
|
+
# def test_case_works
|
57
|
+
# @batch_request.result="Mike"
|
58
|
+
# case @batch_request
|
59
|
+
# when String
|
60
|
+
# else
|
61
|
+
# fail("case failed")
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# end
|
65
|
+
|
66
|
+
def test_calling_method_without_result_raises_exception
|
67
|
+
assert_raises(Facebooker::BatchRequest::UnexecutedRequest) {
|
68
|
+
@batch_request.to_s
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_respond_to
|
73
|
+
@batch_request.result=[]
|
74
|
+
assert @batch_request.respond_to?(:empty?)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_calling_method_after_exception_re_raises_exception
|
78
|
+
@batch_request.result="String"
|
79
|
+
assert_raises(NoMethodError) {
|
80
|
+
@batch_request.fake
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::DataTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@session = Facebooker::Session.create('apikey', 'secretkey')
|
6
|
+
#make sure we use net::http since that's what the tests expect
|
7
|
+
Facebooker.use_curl=false
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_can_ask_facebook_to_set_a_cookies
|
11
|
+
expect_http_posts_with_responses(example_set_cookie_xml)
|
12
|
+
assert(@session.data.set_cookie(12345, 'name', 'value'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_can_ask_facebook_to_get_cookies
|
16
|
+
expect_http_posts_with_responses(example_get_cookies_xml)
|
17
|
+
assert(@session.data.get_cookies(12345))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_can_get_cookies_for_user
|
21
|
+
mock_http = establish_session
|
22
|
+
mock_http.should_receive(:post_form).and_return(example_get_cookies_xml).once.ordered(:posts)
|
23
|
+
cookies = @session.data.get_cookies(508508326)
|
24
|
+
assert_equal 'Foo', cookies.first.name
|
25
|
+
assert_equal 'Bar', cookies.first.value
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_can_ask_facebook_to_set_a_preference
|
29
|
+
expect_http_posts_with_responses(example_set_preference_xml)
|
30
|
+
assert(@session.data.set_preference(0, 'hello'))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_can_ask_facebook_to_get_preference
|
34
|
+
expect_http_posts_with_responses(example_get_preference_xml)
|
35
|
+
assert(@session.data.get_preference(0))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_can_get_preference
|
39
|
+
mock_http = establish_session
|
40
|
+
mock_http.should_receive(:post_form).and_return(example_get_preference_xml).once.ordered(:posts)
|
41
|
+
assert_equal 'hello', @session.data.get_preference(0)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def example_set_cookie_xml
|
46
|
+
<<-XML
|
47
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
48
|
+
<data_setCookie_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
49
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</data_setCookie_response>
|
50
|
+
XML
|
51
|
+
end
|
52
|
+
|
53
|
+
def example_get_cookies_xml
|
54
|
+
<<-XML
|
55
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
56
|
+
<data_getCookie_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
57
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
|
58
|
+
<cookies>
|
59
|
+
<uid>508508326</uid>
|
60
|
+
<name>Foo</name>
|
61
|
+
<value>Bar</value>
|
62
|
+
<expires>0</expires>
|
63
|
+
<path>/tmp/</path>
|
64
|
+
</cookies>
|
65
|
+
</data_getCookie_response>
|
66
|
+
XML
|
67
|
+
end
|
68
|
+
|
69
|
+
def example_set_preference_xml
|
70
|
+
<<-XML
|
71
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
72
|
+
<data_setUserPreference_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
73
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd"/>
|
74
|
+
XML
|
75
|
+
end
|
76
|
+
|
77
|
+
def example_get_preference_xml
|
78
|
+
<<-XML
|
79
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
80
|
+
<data_getUserPreference_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
81
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
|
82
|
+
hello
|
83
|
+
</data_getUserPreference_response>
|
84
|
+
XML
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
class Facebooker::LoggingTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
Facebooker.logger = Logger.new(STDERR)
|
8
|
+
Facebooker::Logging.skip_api_logging=false
|
9
|
+
end
|
10
|
+
def teardown
|
11
|
+
Facebooker.logger = nil
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_does_not_crash_with_nil_logger
|
16
|
+
Facebooker.logger = nil
|
17
|
+
Facebooker::Logging.log_fb_api('sample.api.call',
|
18
|
+
{'param1' => true, 'param2' => 'value2'})
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_does_not_crash_outside_rails
|
22
|
+
flexmock(Facebooker.logger, :logger).should_receive(:debug).once.with(String)
|
23
|
+
Facebooker::Logging.log_fb_api('sample.api.call',
|
24
|
+
{'param1' => true, 'param2' => 'value2'})
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_can_disable_logging
|
28
|
+
Facebooker::Logging.skip_api_logging = true
|
29
|
+
flexmock(Facebooker::Logging).should_receive(:log_info).never
|
30
|
+
Facebooker::Logging.log_fb_api('sample.api.call',
|
31
|
+
{'param1' => true, 'param2' => 'value2'})
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_plain_format
|
35
|
+
flexmock(Facebooker.logger, :logger).should_receive(:debug).once.with(
|
36
|
+
'sample.api.call (0) param1 = true')
|
37
|
+
Facebooker::Logging.log_fb_api('sample.api.call',
|
38
|
+
{'param1' => true})
|
39
|
+
ensure
|
40
|
+
Facebooker.logger = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::MobileTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@session = Facebooker::Session.create('apikey', 'secretkey')
|
6
|
+
@user = Facebooker::User.new(1234, @session)
|
7
|
+
Facebooker.use_curl=false
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_can_send
|
11
|
+
expect_http_posts_with_responses(example_can_send_xml)
|
12
|
+
assert(@session.mobile.can_send(@user))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_send
|
16
|
+
expect_http_posts_with_responses(example_send_xml)
|
17
|
+
assert(@session.mobile.send(@user, "Some sort of message"))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def example_can_send_xml
|
22
|
+
<<-XML
|
23
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
24
|
+
<sms_canSend_response
|
25
|
+
xmlns="http://api.facebook.com/1.0/"
|
26
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
27
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
28
|
+
0
|
29
|
+
</sms_canSend_response>
|
30
|
+
XML
|
31
|
+
end
|
32
|
+
|
33
|
+
def example_send_xml
|
34
|
+
<<-XML
|
35
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
36
|
+
<sms_send_response
|
37
|
+
xmlns="http://api.facebook.com/1.0/"
|
38
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
39
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
40
|
+
0
|
41
|
+
</sms_send_response>
|
42
|
+
XML
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::ModelTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ComplexThing
|
6
|
+
include Facebooker::Model
|
7
|
+
attr_accessor :weight, :height
|
8
|
+
end
|
9
|
+
|
10
|
+
class Thing
|
11
|
+
include Facebooker::Model
|
12
|
+
attr_accessor :name, :job
|
13
|
+
hash_settable_accessor :complex_thing, ComplexThing
|
14
|
+
hash_settable_list_accessor :list_of_complex_things, ComplexThing
|
15
|
+
end
|
16
|
+
|
17
|
+
class PopulatingThing
|
18
|
+
include Facebooker::Model
|
19
|
+
populating_attr_accessor :first_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_can_instantiate_an_object_with_a_hash
|
23
|
+
h = {:name => "Blob", :job => "Monster"}
|
24
|
+
assert_equal("Blob", Thing.from_hash(h).name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_ignores_non_model_keys
|
28
|
+
h = {:name => "Blob", :job => "Monster", :not_there=>true}
|
29
|
+
assert_equal("Blob", Thing.from_hash(h).name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_logs_non_model_keys
|
33
|
+
flexmock(Facebooker::Logging).should_receive(:log_info)
|
34
|
+
h = {:name => "Blob", :job => "Monster", :not_there=>true}
|
35
|
+
Thing.from_hash(h)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def test_if_no_hash_is_given_to_model_constructor_no_attributes_are_set
|
40
|
+
assert_nothing_raised {
|
41
|
+
t = Thing.new
|
42
|
+
assert_nil(t.name)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_can_declare_hash_settable_attributes
|
47
|
+
t = Thing.new({})
|
48
|
+
t.complex_thing = {:weight => 123, :height => 5.4}
|
49
|
+
assert_equal(123, t.complex_thing.weight)
|
50
|
+
t.complex_thing = ComplexThing.new(:weight => 321)
|
51
|
+
assert_equal(321, t.complex_thing.weight)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_can_declare_attributes_which_are_settable_via_a_list_of_hashes
|
55
|
+
t = Thing.new
|
56
|
+
t.list_of_complex_things = [{:weight => 444, :height => 123.0}, {:weight => 222, :height => 321.1}]
|
57
|
+
assert_equal("123.0, 321.1", t.list_of_complex_things.map{|ct| ct.height.to_s}.sort.join(', '))
|
58
|
+
t.list_of_complex_things = [ComplexThing.new(:weight => 555), ComplexThing.new(:weight => 111)]
|
59
|
+
assert_equal("111, 555", t.list_of_complex_things.map{|ct| ct.weight.to_s}.sort.join(', '))
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_if_you_try_to_use_a_models_session_without_initializing_it_first_you_get_a_descriptive_error
|
63
|
+
t = Thing.new
|
64
|
+
assert_raises(Facebooker::Model::UnboundSessionException) {
|
65
|
+
t.session
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_populating_reader_will_call_populate_if_model_was_not_previously_populated
|
70
|
+
t = PopulatingThing.new
|
71
|
+
flexmock(t).should_receive(:populate).once
|
72
|
+
t.first_name
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_populating_reader_will_not_call_populate_if_model_was_previously_populated
|
76
|
+
t = PopulatingThing.new
|
77
|
+
flexmock(t).should_receive(:populated?).and_return(true)
|
78
|
+
flexmock(t).should_receive(:populate).never
|
79
|
+
t.first_name
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_attempting_to_access_a_populating_reader_will_raise_an_exception_if_populate_was_not_defined
|
83
|
+
t = PopulatingThing.new
|
84
|
+
assert_raises(NotImplementedError) {
|
85
|
+
t.first_name
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_populate_from_hash_e_should_call_a_setter_for_a_key
|
90
|
+
t = PopulatingThing.new
|
91
|
+
flexmock(t).should_receive('mykey=').with('a value')
|
92
|
+
t.populate_from_hash!({ :mykey => 'a value' })
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_populate_from_hash_e_should_call_a_setter_for_a_key_if_the_value_is_false
|
96
|
+
t = PopulatingThing.new
|
97
|
+
flexmock(t).should_receive('mykey=').with(false)
|
98
|
+
t.populate_from_hash!({ :mykey => false })
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_populate_from_hash_e_should_call_not_a_setter_for_a_key_if_the_value_is_nil
|
102
|
+
t = PopulatingThing.new
|
103
|
+
flexmock(t).should_receive('mykey=').never
|
104
|
+
t.populate_from_hash!({ :mykey => nil })
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_populate_from_hash_should_check_for_an_empty_hash
|
108
|
+
t = PopulatingThing.new
|
109
|
+
hash = {}
|
110
|
+
flexmock(hash).should_receive('empty?')
|
111
|
+
t.populate_from_hash!(hash)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_populate_from_hash_should_check_for_a_nil_param
|
115
|
+
t = PopulatingThing.new
|
116
|
+
hash = nil
|
117
|
+
assert_nothing_raised do
|
118
|
+
t.populate_from_hash!(hash)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::EventTest < Test::Unit::TestCase
|
4
|
+
def test_attendance_will_query_for_event_when_asked_for_full_event_object
|
5
|
+
session = flexmock("a session object")
|
6
|
+
eid = 123
|
7
|
+
attendance = Facebooker::Event::Attendance.new
|
8
|
+
attendance.eid = eid
|
9
|
+
attendance.session = session
|
10
|
+
event = Facebooker::Event.new
|
11
|
+
event.eid = eid
|
12
|
+
session.should_receive(:post).once.with('facebook.events.get', :eids => [eid]).and_return([{:eid => eid}])
|
13
|
+
assert_equal(123, attendance.event.eid)
|
14
|
+
end
|
15
|
+
end
|