facebooker-lite 1.0.67

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/.autotest +15 -0
  2. data/CHANGELOG.rdoc +24 -0
  3. data/COPYING.rdoc +19 -0
  4. data/Manifest.txt +114 -0
  5. data/README.rdoc +120 -0
  6. data/Rakefile +94 -0
  7. data/TODO.rdoc +4 -0
  8. data/facebooker.gemspec +42 -0
  9. data/generators/xd_receiver/templates/xd_receiver.html +10 -0
  10. data/generators/xd_receiver/templates/xd_receiver_ssl.html +10 -0
  11. data/generators/xd_receiver/xd_receiver_generator.rb +10 -0
  12. data/init.rb +25 -0
  13. data/install.rb +12 -0
  14. data/lib/facebooker.rb +261 -0
  15. data/lib/facebooker/adapters/adapter_base.rb +91 -0
  16. data/lib/facebooker/adapters/bebo_adapter.rb +77 -0
  17. data/lib/facebooker/adapters/facebook_adapter.rb +60 -0
  18. data/lib/facebooker/admin.rb +42 -0
  19. data/lib/facebooker/application.rb +37 -0
  20. data/lib/facebooker/attachment.rb +51 -0
  21. data/lib/facebooker/batch_request.rb +45 -0
  22. data/lib/facebooker/data.rb +57 -0
  23. data/lib/facebooker/feed.rb +78 -0
  24. data/lib/facebooker/logging.rb +44 -0
  25. data/lib/facebooker/mobile.rb +20 -0
  26. data/lib/facebooker/mock/service.rb +50 -0
  27. data/lib/facebooker/mock/session.rb +18 -0
  28. data/lib/facebooker/model.rb +139 -0
  29. data/lib/facebooker/models/affiliation.rb +10 -0
  30. data/lib/facebooker/models/album.rb +11 -0
  31. data/lib/facebooker/models/applicationproperties.rb +39 -0
  32. data/lib/facebooker/models/applicationrestrictions.rb +10 -0
  33. data/lib/facebooker/models/comment.rb +9 -0
  34. data/lib/facebooker/models/cookie.rb +10 -0
  35. data/lib/facebooker/models/education_info.rb +11 -0
  36. data/lib/facebooker/models/event.rb +28 -0
  37. data/lib/facebooker/models/family_relative_info.rb +7 -0
  38. data/lib/facebooker/models/friend_list.rb +16 -0
  39. data/lib/facebooker/models/group.rb +36 -0
  40. data/lib/facebooker/models/info_item.rb +10 -0
  41. data/lib/facebooker/models/info_section.rb +10 -0
  42. data/lib/facebooker/models/location.rb +8 -0
  43. data/lib/facebooker/models/message_thread.rb +89 -0
  44. data/lib/facebooker/models/notifications.rb +17 -0
  45. data/lib/facebooker/models/page.rb +46 -0
  46. data/lib/facebooker/models/photo.rb +19 -0
  47. data/lib/facebooker/models/tag.rb +12 -0
  48. data/lib/facebooker/models/user.rb +751 -0
  49. data/lib/facebooker/models/video.rb +9 -0
  50. data/lib/facebooker/models/work_info.rb +10 -0
  51. data/lib/facebooker/parser.rb +970 -0
  52. data/lib/facebooker/rails/backwards_compatible_param_checks.rb +31 -0
  53. data/lib/facebooker/rails/controller.rb +353 -0
  54. data/lib/facebooker/rails/extensions/action_controller.rb +47 -0
  55. data/lib/facebooker/rails/extensions/rack_setup.rb +16 -0
  56. data/lib/facebooker/rails/extensions/routing.rb +15 -0
  57. data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
  58. data/lib/facebooker/rails/facebook_request_fix.rb +28 -0
  59. data/lib/facebooker/rails/facebook_request_fix_2-3.rb +31 -0
  60. data/lib/facebooker/rails/facebook_session_handling.rb +68 -0
  61. data/lib/facebooker/rails/facebook_url_rewriting.rb +60 -0
  62. data/lib/facebooker/rails/helpers/fb_connect.rb +75 -0
  63. data/lib/facebooker/rails/integration_session.rb +38 -0
  64. data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
  65. data/lib/facebooker/rails/publisher.rb +608 -0
  66. data/lib/facebooker/rails/routing.rb +49 -0
  67. data/lib/facebooker/rails/test_helpers.rb +68 -0
  68. data/lib/facebooker/rails/utilities.rb +22 -0
  69. data/lib/facebooker/server_cache.rb +24 -0
  70. data/lib/facebooker/service.rb +103 -0
  71. data/lib/facebooker/service/base_service.rb +19 -0
  72. data/lib/facebooker/service/curl_service.rb +44 -0
  73. data/lib/facebooker/service/net_http_service.rb +12 -0
  74. data/lib/facebooker/service/typhoeus_multi_service.rb +27 -0
  75. data/lib/facebooker/service/typhoeus_service.rb +17 -0
  76. data/lib/facebooker/session.rb +786 -0
  77. data/lib/facebooker/stream_post.rb +19 -0
  78. data/lib/facebooker/version.rb +9 -0
  79. data/lib/net/http_multipart_post.rb +123 -0
  80. data/lib/rack/facebook.rb +89 -0
  81. data/lib/rack/facebook_session.rb +21 -0
  82. data/lib/tasks/facebooker.rake +19 -0
  83. data/lib/tasks/facebooker.rb +2 -0
  84. data/lib/tasks/tunnel.rake +46 -0
  85. data/rails/init.rb +1 -0
  86. data/setup.rb +1585 -0
  87. data/templates/layout.erb +24 -0
  88. data/test/facebooker/adapters_test.rb +191 -0
  89. data/test/facebooker/admin_test.rb +102 -0
  90. data/test/facebooker/application_test.rb +110 -0
  91. data/test/facebooker/attachment_test.rb +72 -0
  92. data/test/facebooker/batch_request_test.rb +83 -0
  93. data/test/facebooker/data_test.rb +86 -0
  94. data/test/facebooker/logging_test.rb +43 -0
  95. data/test/facebooker/mobile_test.rb +45 -0
  96. data/test/facebooker/model_test.rb +133 -0
  97. data/test/facebooker/models/event_test.rb +15 -0
  98. data/test/facebooker/models/page_test.rb +56 -0
  99. data/test/facebooker/models/photo_test.rb +16 -0
  100. data/test/facebooker/models/user_test.rb +1074 -0
  101. data/test/facebooker/rails/facebook_request_fix_2-3_test.rb +25 -0
  102. data/test/facebooker/rails/facebook_url_rewriting_test.rb +76 -0
  103. data/test/facebooker/rails/integration_session_test.rb +13 -0
  104. data/test/facebooker/rails/publisher_test.rb +538 -0
  105. data/test/facebooker/rails_integration_test.rb +1543 -0
  106. data/test/facebooker/server_cache_test.rb +44 -0
  107. data/test/facebooker/service_test.rb +58 -0
  108. data/test/facebooker/session_test.rb +883 -0
  109. data/test/facebooker_test.rb +1263 -0
  110. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  111. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  112. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  113. data/test/net/http_multipart_post_test.rb +52 -0
  114. data/test/rack/facebook_session_test.rb +34 -0
  115. data/test/rack/facebook_test.rb +73 -0
  116. data/test/rails_test_helper.rb +36 -0
  117. data/test/test_helper.rb +74 -0
  118. metadata +278 -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,191 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class Facebooker::AdaptersTest < Test::Unit::TestCase
4
+ def setup
5
+ ENV['FACEBOOK_API_KEY'] = '1234567'
6
+ ENV['FACEBOOK_SECRET_KEY'] = '7654321'
7
+ @current_adapter = Facebooker.current_adapter
8
+ Facebooker.current_adapter = nil
9
+ @bebo_api_key = "bebo_api_key"; @bebo_secret_key = "bebo_secret_key"
10
+ end
11
+
12
+ def teardown
13
+ flexmock_close
14
+ Facebooker.current_adapter = @current_adapter
15
+ end
16
+
17
+ def test_load_default_adapter
18
+ session = Facebooker::CanvasSession.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
19
+ assert_equal(ENV['FACEBOOK_API_KEY'], Facebooker::Session.api_key)
20
+ assert( Facebooker::FacebookAdapter === Facebooker.current_adapter)
21
+
22
+ ENV['FACEBOOK_API_KEY'] = nil
23
+ ENV['FACEBOOK_SECRET_KEY'] = nil
24
+ Facebooker.current_adapter = nil
25
+ Facebooker::AdapterBase.stubs(:facebooker_config).returns({"api_key" => "facebook_key", "secret_key" => "facebook_secret" })
26
+ assert( Facebooker::FacebookAdapter === Facebooker.current_adapter)
27
+ assert_equal("facebook_key", Facebooker::Session.api_key)
28
+ end
29
+
30
+ def test_load_bebo_adapter
31
+
32
+ load_bebo_adapter
33
+ assert_equal(@bebo_api_key, Facebooker::Session.api_key)
34
+ assert_equal(@bebo_secret_key, Facebooker::Session.secret_key)
35
+ assert(Facebooker::BeboAdapter === Facebooker.current_adapter, " Bebo adapter not loaded correctly.")
36
+ end
37
+
38
+ def load_bebo_adapter
39
+ @bebo_api_key = "bebo_api_key"; @bebo_secret_key = "bebo_secret_key"
40
+
41
+ Facebooker::AdapterBase.stubs(:facebooker_config).returns({"bebo_api_key" => @bebo_api_key, "bebo_adapter" => "BeboAdapter", "bebo_secret_key" => @bebo_secret_key, "foo" => "bar"})
42
+ Facebooker.load_adapter(:config_key_base => "bebo")
43
+ @session = Facebooker::CanvasSession.create(@bebo_api_key, @bebo_secret_key)
44
+ end
45
+
46
+ def test_adapter_details
47
+ test_load_default_adapter
48
+
49
+ assert_equal("apps.facebook.com", Facebooker.canvas_server_base)
50
+ assert_equal("api.facebook.com", Facebooker.api_server_base)
51
+ assert_equal("www.facebook.com", Facebooker.www_server_base_url)
52
+ assert_equal("http://api.facebook.com", Facebooker.api_server_base_url)
53
+ assert(Facebooker.is_for?(:facebook))
54
+ load_bebo_adapter
55
+
56
+ assert_equal("apps.bebo.com", Facebooker.canvas_server_base)
57
+ assert_equal("apps.bebo.com", Facebooker.api_server_base)
58
+ assert_equal("www.bebo.com", Facebooker.www_server_base_url)
59
+ assert_equal("http://apps.bebo.com", Facebooker.api_server_base_url)
60
+ assert_equal("http://www.bebo.com/SignIn.jsp?ApiKey=bebo_api_key&v=1.0&canvas=true", @session.login_url)
61
+ assert_equal("http://www.bebo.com/c/apps/add?ApiKey=bebo_api_key&v=1.0", @session.install_url)
62
+ assert(Facebooker.is_for?(:bebo))
63
+
64
+ end
65
+
66
+ def test_adapter_failures
67
+ Facebooker::AdapterBase.stubs(:facebooker_config).returns({})
68
+
69
+ assert_raises(Facebooker::AdapterBase::UnableToLoadAdapter){
70
+ Facebooker.load_adapter(:config_key_base => "bebo")
71
+ }
72
+ end
73
+
74
+ def test_bebo_specific_issues
75
+ load_bebo_adapter
76
+
77
+ # @session.send(:service).stubs(:post).returns([{:name => "foo"}])
78
+ Net::HTTP.stubs(:post_form).returns("<profile_setFBML_response></profile_setFBML_response>")
79
+ user = Facebooker::User.new(:uid => "123456")
80
+ user.session = @session
81
+ user.set_profile_fbml("foo","bar","foo")
82
+ assert(true)
83
+ Net::HTTP.stubs(:post_form).returns("<users_getInfo_response> <user><uid>123456</uid><name>foo</name></user></users_getInfo_response>")
84
+ user.populate(:name)
85
+ assert(true)
86
+ assert_equal("foo", user.name)
87
+ action = Facebooker::Feed::TemplatizedAction.new()
88
+ action.title_template = "foo"
89
+ Net::HTTP.stubs(:post_form).returns("<feed_publishTemplatizedAction_response>1</feed_publishTemplatizedAction_response>")
90
+ user.publish_templatized_action(action)
91
+ end
92
+
93
+ def test_bebo_process_data
94
+
95
+ end
96
+
97
+ def test_fetch_config_for_can_find_top_level_api_key
98
+ old = Facebooker.instance_variable_get('@raw_facebooker_configuration')
99
+ # Now that we've backed up the old value...
100
+ raw_fb_config = { 'api_key' => 'a key' }
101
+ Facebooker.instance_variable_set('@raw_facebooker_configuration', raw_fb_config)
102
+ assert_equal Facebooker.fetch_config_for( 'a key' ), raw_fb_config
103
+ ensure
104
+ # Put the old value back
105
+ Facebooker.instance_variable_set('@raw_facebooker_configuration', old)
106
+ end
107
+
108
+ def test_fetch_config_for_can_find_deep_api_key
109
+ old = Facebooker.instance_variable_get('@raw_facebooker_configuration')
110
+ # Now that we've backed up the old value...
111
+ raw_fb_config = { 'api_key' => 'a key',
112
+ 'alternative_keys' => {
113
+ 'another key' => { 'secret_key' => 'sdfsd' },
114
+ 'yet another key' => { 'secret_key' => '9ho2h' } } }
115
+ Facebooker.instance_variable_set('@raw_facebooker_configuration', raw_fb_config)
116
+ assert_equal raw_fb_config['alternative_keys']['another key'].merge( 'api_key' => 'another key' ),
117
+ Facebooker.fetch_config_for( 'another key' )
118
+ ensure
119
+ # Put the old value back
120
+ Facebooker.instance_variable_set('@raw_facebooker_configuration', old)
121
+ end
122
+
123
+ def test_fetch_config_for_returns_false_if_no_apikey_found
124
+ old = Facebooker.instance_variable_get('@raw_facebooker_configuration')
125
+ # Now that we've backed up the old value...
126
+ raw_fb_config = { 'api_key' => 'a key' }
127
+ Facebooker.instance_variable_set('@raw_facebooker_configuration', raw_fb_config)
128
+ assert ! Facebooker.fetch_config_for( 'another key' )
129
+ ensure
130
+ # Put the old value back
131
+ Facebooker.instance_variable_set('@raw_facebooker_configuration', old)
132
+ end
133
+
134
+ def test_with_application_yields_if_no_config_is_found
135
+ flexmock( Facebooker ).
136
+ should_receive( :fetch_config_for ).
137
+ and_return( false )
138
+ # Is there a better way to assert the block is yielded?
139
+ @changes_to_true = false
140
+ Facebooker.with_application('somekey not found') do
141
+ @changes_to_true = true
142
+ end
143
+ assert @changes_to_true
144
+ end
145
+
146
+ def test_with_application_changes_config_inside_block
147
+ flexmock( Facebooker ).
148
+ should_receive( :fetch_config_for ).
149
+ and_return({ 'api_key' => 'a key',
150
+ 'secret_key' => 'my secret key' })
151
+ Facebooker.with_application('a key') do
152
+ @secret_in_block = Facebooker.secret_key
153
+ end
154
+ # Check outside the block, assures the assertion gets run
155
+ assert_equal 'my secret key', @secret_in_block
156
+ end
157
+
158
+ def test_with_application_restores_last_config_outside_block
159
+ flexmock( Facebooker ).
160
+ should_receive( :fetch_config_for ).
161
+ and_return( { 'api_key' => 'a key',
162
+ 'secret_key' => 'my secret key' },
163
+ { 'api_key' => 'another key',
164
+ 'secret_key' => 'my other secret key' } )
165
+ Facebooker.with_application('a key') do
166
+ Facebooker.with_application('another key') do
167
+ end
168
+ @secret_in_outer_block = Facebooker.secret_key
169
+ end
170
+ # Check outside the block, assures the assertion gets run
171
+ assert_equal 'my secret key', @secret_in_outer_block
172
+ end
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
+
191
+ 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
+ {&quot;application_name&quot;:&quot;Video Jukebox&quot;,&quot;callback_url&quot;:&quot;http:\/\/67.207.144.245\/&quot;,&quot;dev_mode&quot;:0,&quot;canvas_name&quot;:&quot;my_canvas&quot;}
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
+ {&quot;age&quot;:&quot;21&quot;,&quot;location&quot;:&quot;&quot;,&quot;age_distribution&quot;:&quot;&quot;,&quot;type&quot;:&quot;alcohol&quot;}
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,110 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class Facebooker::ApplicationTest < 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_get_public_info
10
+ mock_http = establish_session
11
+ mock_http.should_receive(:post_form).and_return(example_get_public_info_xml).once.ordered(:posts)
12
+ info = @session.application.get_public_info(:app_id => 2413267546)
13
+ assert_equal '2413267546', info["app_id"]
14
+ assert_equal 'ilike', info["canvas_name"]
15
+ end
16
+
17
+ def test_can_add_global_news
18
+ @session.expects(:post).with('facebook.dashboard.addGlobalNews', {:news => [{:message => 'Hi all users', :action_link => {:text => 'Hi application', :href => 'http://facebook.er/'}}], :image => 'http://facebook.er/icon.png'})
19
+ @session.application.add_global_news [{ :message => 'Hi all users', :action_link => { :text => "Hi application", :href => 'http://facebook.er/' }}], 'http://facebook.er/icon.png'
20
+ end
21
+
22
+ def test_parse_add_global_news
23
+ expect_http_posts_with_responses(add_global_news_xml)
24
+ assert_equal("342345290762", @session.application.add_global_news([{ :message => 'Hi user', :action_link => { :text => "Uh hey there app", :href => 'http://facebook.er/' }}], 'http://facebook.er/icon.png'))
25
+ end
26
+
27
+ def test_can_get_global_news
28
+ @session.expects(:post).with('facebook.dashboard.getGlobalNews', { :news_ids => ['310354202543'] })
29
+ @session.application.get_global_news '310354202543'
30
+ end
31
+
32
+ def test_parse_get_global_news
33
+ expect_http_posts_with_responses(get_global_news_xml)
34
+ assert_equal({"342345290762"=>{"fbid"=>"342345290762", "time"=>"1266609698761", "news"=>[{"action_link"=>{"href"=>"http://facebook.er/", "text"=>"Hi application"}, "message"=>"Hi all users"}], "image"=>"http://facebook.er/icon.png"}}, @session.application.get_global_news('342345290762'))
35
+ end
36
+
37
+ def test_can_clear_global_news
38
+ @session.expects(:post).with('facebook.dashboard.clearGlobalNews', { :news_ids => ['310354202543'] })
39
+ @session.application.clear_global_news '310354202543'
40
+ end
41
+
42
+ def test_can_parse_global_news
43
+ expect_http_posts_with_responses(clear_global_news_xml)
44
+ assert_equal({"342345290762"=>true}, @session.application.clear_global_news('342345290762'))
45
+ end
46
+
47
+ private
48
+
49
+ def example_get_public_info_xml
50
+ <<-XML
51
+ <?xml version="1.0" encoding="UTF-8"?>
52
+ <application_getPublicInfo_response
53
+ xmlns="http://api.facebook.com/1.0/"
54
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
+ xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
56
+ <app_id>2413267546</app_id>
57
+ <api_key>c756401cb800e295f21d723b7842ea83</api_key>
58
+ <canvas_name>ilike</canvas_name>
59
+ <display_name>iLike</display_name>
60
+ <icon_url>http://photos-c.ak.facebook.com/photos-ak-sctm/v43/130/2413267546/app_2_2413267546_6706.gif</icon_url>
61
+ <logo_url>http://photos-c.ak.facebook.com/photos-ak-sctm/v43/130/2413267546/app_1_2413267546_2324.gif</logo_url>
62
+ <developers list="true"/>
63
+ <company_name>iLike, inc</company_name>
64
+ <description>iLike lets you add music to your profile and find your favorite concerts (not to mention see who else is going!). Bonus: Use it to get free mp3's that match your tastes and try to beat your friends at the Music Challenge.</description>
65
+ <daily_active_users>392008</daily_active_users>
66
+ <weekly_active_users>1341749</weekly_active_users>
67
+ <monthly_active_users>3922784</monthly_active_users>
68
+ </application_getPublicInfo_response>
69
+ XML
70
+ end
71
+
72
+ def add_global_news_xml
73
+ <<-XML
74
+ <?xml version="1.0" encoding="UTF-8"?>
75
+ <dashboard_addGlobalNews_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">342345290762</dashboard_addGlobalNews_response>
76
+ XML
77
+ end
78
+
79
+ def get_global_news_xml
80
+ <<-XML
81
+ <?xml version="1.0" encoding="UTF-8"?>
82
+ <dashboard_getGlobalNews_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
83
+ <dashboard_getGlobalNews_response_elt key="342345290762" list="true">
84
+ <dashboard_getGlobalNews_response_elt_elt key="image">http://facebook.er/icon.png</dashboard_getGlobalNews_response_elt_elt>
85
+ <dashboard_getGlobalNews_response_elt_elt key="news" list="true">
86
+ <dashboard_getGlobalNews_response_elt_elt_elt list="true">
87
+ <dashboard_getGlobalNews_response_elt_elt_elt_elt key="message">Hi all users</dashboard_getGlobalNews_response_elt_elt_elt_elt>
88
+ <dashboard_getGlobalNews_response_elt_elt_elt_elt key="action_link" list="true">
89
+ <dashboard_getGlobalNews_response_elt_elt_elt_elt_elt key="href">http://facebook.er/</dashboard_getGlobalNews_response_elt_elt_elt_elt_elt>
90
+ <dashboard_getGlobalNews_response_elt_elt_elt_elt_elt key="text">Hi application</dashboard_getGlobalNews_response_elt_elt_elt_elt_elt>
91
+ </dashboard_getGlobalNews_response_elt_elt_elt_elt>
92
+ </dashboard_getGlobalNews_response_elt_elt_elt>
93
+ </dashboard_getGlobalNews_response_elt_elt>
94
+ <dashboard_getGlobalNews_response_elt_elt key="time">1266609698761</dashboard_getGlobalNews_response_elt_elt>
95
+ <dashboard_getGlobalNews_response_elt_elt key="fbid">342345290762</dashboard_getGlobalNews_response_elt_elt>
96
+ </dashboard_getGlobalNews_response_elt>
97
+ </dashboard_getGlobalNews_response>
98
+ XML
99
+ end
100
+
101
+ def clear_global_news_xml
102
+ <<-XML
103
+ <?xml version="1.0" encoding="UTF-8"?>
104
+ <dashboard_clearGlobalNews_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
105
+ <dashboard_clearGlobalNews_response_elt key="342345290762">1</dashboard_clearGlobalNews_response_elt>
106
+ </dashboard_clearGlobalNews_response>
107
+ XML
108
+ end
109
+
110
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class Facebooker::AttachmentTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ @attachment = Facebooker::Attachment.new
8
+ end
9
+
10
+ def test_can_create_attachment
11
+ attachment = Facebooker::Attachment.new
12
+ end
13
+
14
+ def test_can_set_name
15
+ @attachment.name = "my name"
16
+ assert_equal({:name=>"my name"},@attachment.to_hash)
17
+ end
18
+
19
+ def test_can_set_href
20
+ @attachment.href="my href"
21
+ assert_equal({:href=>"my href"},@attachment.to_hash)
22
+ end
23
+
24
+ def test_can_set_caption
25
+ @attachment.caption="my caption"
26
+ assert_equal({:caption=>"my caption"},@attachment.to_hash)
27
+ end
28
+
29
+ def test_can_set_description
30
+ @attachment.description="my description"
31
+ assert_equal({:description=>"my description"},@attachment.to_hash)
32
+ end
33
+
34
+ def test_can_set_comments_xid
35
+ @attachment.comments_xid="my xid"
36
+ assert_equal({:comments_xid=>"my xid"},@attachment.to_hash)
37
+ end
38
+
39
+ def test_can_add_media
40
+ @attachment.add_media(:type=>"image",:src=>"http://www.google.com",:href=>"http://www.bing.com")
41
+ assert_equal({:media=>[{:type=>"image",:src=>"http://www.google.com",:href=>"http://www.bing.com"}]},@attachment.to_hash)
42
+ end
43
+
44
+ def test_can_add_image
45
+ @attachment.add_image("image_source","image_url")
46
+ assert_equal({:media=>[{:type=>"image",:src=>"image_source",:href=>"image_url"}]},@attachment.to_hash)
47
+ end
48
+
49
+ def test_can_add_mp3_with_only_required_params
50
+ @attachment.add_mp3("required_source")
51
+ assert_equal({:media=>[{:type=>"mp3",:src=>"required_source"}]},@attachment.to_hash)
52
+ end
53
+
54
+ def test_only_includes_mp3_optional_params_that_are_provided
55
+ @attachment.add_mp3("required_source","seven nation army","white stripes")
56
+ assert_equal({:media=>[{:type=>"mp3",:src=>"required_source",:title=>"seven nation army",:artist=>"white stripes"}]},@attachment.to_hash)
57
+ end
58
+
59
+ def test_can_add_flash_with_only_required_params
60
+ @attachment.add_flash("swf_source","img_source")
61
+ assert_equal({:media=>[{:type=>"flash",:swfsrc=>"swf_source",:imgsrc=>"img_source"}]},@attachment.to_hash)
62
+ end
63
+ def test_can_add_flash_with_optional_params
64
+ @attachment.add_flash("swf_source","img_source",100,80,160)
65
+ assert_equal({:media=>[{:type=>"flash",
66
+ :swfsrc=>"swf_source",
67
+ :imgsrc=>"img_source",
68
+ :width=>100,
69
+ :height=>80,
70
+ :expanded_width=>160}]},@attachment.to_hash)
71
+ end
72
+ end