tenderlove-facebooker 1.0.16.20090319151701

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/CHANGELOG.rdoc +17 -0
  2. data/COPYING.rdoc +19 -0
  3. data/Manifest.txt +123 -0
  4. data/README.rdoc +103 -0
  5. data/Rakefile +86 -0
  6. data/TODO.rdoc +4 -0
  7. data/examples/desktop_login.rb +14 -0
  8. data/facebooker.gemspec +38 -0
  9. data/generators/facebook/facebook_generator.rb +14 -0
  10. data/generators/facebook/templates/config/facebooker.yml +46 -0
  11. data/generators/facebook/templates/public/javascripts/facebooker.js +99 -0
  12. data/generators/facebook_controller/USAGE +33 -0
  13. data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
  14. data/generators/facebook_controller/templates/controller.rb +7 -0
  15. data/generators/facebook_controller/templates/functional_test.rb +11 -0
  16. data/generators/facebook_controller/templates/helper.rb +2 -0
  17. data/generators/facebook_controller/templates/view.fbml.erb +2 -0
  18. data/generators/facebook_controller/templates/view.html.erb +2 -0
  19. data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
  20. data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
  21. data/generators/facebook_publisher/templates/publisher.rb +3 -0
  22. data/generators/facebook_scaffold/USAGE +27 -0
  23. data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
  24. data/generators/facebook_scaffold/templates/controller.rb +93 -0
  25. data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
  26. data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
  27. data/generators/facebook_scaffold/templates/helper.rb +2 -0
  28. data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
  29. data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
  30. data/generators/facebook_scaffold/templates/style.css +74 -0
  31. data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
  32. data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
  33. data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
  34. data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
  35. data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
  36. data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
  37. data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
  38. data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
  39. data/generators/publisher/publisher_generator.rb +14 -0
  40. data/generators/xd_receiver/templates/xd_receiver.html +10 -0
  41. data/generators/xd_receiver/xd_receiver_generator.rb +9 -0
  42. data/init.rb +72 -0
  43. data/install.rb +12 -0
  44. data/lib/facebooker/adapters/adapter_base.rb +87 -0
  45. data/lib/facebooker/adapters/bebo_adapter.rb +75 -0
  46. data/lib/facebooker/adapters/facebook_adapter.rb +52 -0
  47. data/lib/facebooker/admin.rb +42 -0
  48. data/lib/facebooker/batch_request.rb +44 -0
  49. data/lib/facebooker/data.rb +57 -0
  50. data/lib/facebooker/feed.rb +78 -0
  51. data/lib/facebooker/logging.rb +51 -0
  52. data/lib/facebooker/mobile.rb +20 -0
  53. data/lib/facebooker/mock/service.rb +50 -0
  54. data/lib/facebooker/mock/session.rb +18 -0
  55. data/lib/facebooker/model.rb +135 -0
  56. data/lib/facebooker/models/affiliation.rb +10 -0
  57. data/lib/facebooker/models/album.rb +11 -0
  58. data/lib/facebooker/models/applicationproperties.rb +39 -0
  59. data/lib/facebooker/models/applicationrestrictions.rb +10 -0
  60. data/lib/facebooker/models/cookie.rb +10 -0
  61. data/lib/facebooker/models/education_info.rb +11 -0
  62. data/lib/facebooker/models/event.rb +28 -0
  63. data/lib/facebooker/models/friend_list.rb +16 -0
  64. data/lib/facebooker/models/group.rb +36 -0
  65. data/lib/facebooker/models/info_item.rb +10 -0
  66. data/lib/facebooker/models/info_section.rb +10 -0
  67. data/lib/facebooker/models/location.rb +8 -0
  68. data/lib/facebooker/models/notifications.rb +17 -0
  69. data/lib/facebooker/models/page.rb +27 -0
  70. data/lib/facebooker/models/photo.rb +12 -0
  71. data/lib/facebooker/models/tag.rb +12 -0
  72. data/lib/facebooker/models/user.rb +426 -0
  73. data/lib/facebooker/models/video.rb +9 -0
  74. data/lib/facebooker/models/work_info.rb +9 -0
  75. data/lib/facebooker/parser.rb +589 -0
  76. data/lib/facebooker/rails/controller.rb +304 -0
  77. data/lib/facebooker/rails/cucumber/world.rb +46 -0
  78. data/lib/facebooker/rails/cucumber.rb +28 -0
  79. data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
  80. data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
  81. data/lib/facebooker/rails/facebook_request_fix.rb +24 -0
  82. data/lib/facebooker/rails/facebook_session_handling.rb +69 -0
  83. data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
  84. data/lib/facebooker/rails/facebook_url_rewriting.rb +39 -0
  85. data/lib/facebooker/rails/helpers/fb_connect.rb +89 -0
  86. data/lib/facebooker/rails/helpers.rb +762 -0
  87. data/lib/facebooker/rails/integration_session.rb +38 -0
  88. data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
  89. data/lib/facebooker/rails/publisher.rb +526 -0
  90. data/lib/facebooker/rails/routing.rb +49 -0
  91. data/lib/facebooker/rails/test_helpers.rb +68 -0
  92. data/lib/facebooker/rails/utilities.rb +22 -0
  93. data/lib/facebooker/server_cache.rb +24 -0
  94. data/lib/facebooker/service.rb +94 -0
  95. data/lib/facebooker/session.rb +584 -0
  96. data/lib/facebooker/version.rb +9 -0
  97. data/lib/facebooker.rb +174 -0
  98. data/lib/net/http_multipart_post.rb +123 -0
  99. data/lib/tasks/facebooker.rake +18 -0
  100. data/lib/tasks/tunnel.rake +46 -0
  101. data/rails/init.rb +1 -0
  102. data/setup.rb +1585 -0
  103. data/templates/layout.erb +24 -0
  104. data/test/facebooker/adapters_test.rb +96 -0
  105. data/test/facebooker/admin_test.rb +102 -0
  106. data/test/facebooker/batch_request_test.rb +83 -0
  107. data/test/facebooker/data_test.rb +86 -0
  108. data/test/facebooker/logging_test.rb +43 -0
  109. data/test/facebooker/mobile_test.rb +45 -0
  110. data/test/facebooker/model_test.rb +123 -0
  111. data/test/facebooker/models/event_test.rb +15 -0
  112. data/test/facebooker/models/user_test.rb +295 -0
  113. data/test/facebooker/rails/publisher_test.rb +452 -0
  114. data/test/facebooker/rails_integration_test.rb +1312 -0
  115. data/test/facebooker/server_cache_test.rb +44 -0
  116. data/test/facebooker/session_test.rb +614 -0
  117. data/test/facebooker_test.rb +925 -0
  118. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  119. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  120. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  121. data/test/net/http_multipart_post_test.rb +52 -0
  122. data/test/rails_test_helper.rb +11 -0
  123. data/test/test_helper.rb +66 -0
  124. metadata +217 -0
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class FacebookCacheTest < 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_store_fbml_in_a_named_reference
10
+ expect_http_posts_with_responses(example_set_ref_handle_xml)
11
+ assert(@session.server_cache.set_ref_handle('a_handle_name', '<h2>Some FBML</h2>'))
12
+ end
13
+
14
+ def test_can_ask_facebook_to_recache_content_stored_from_a_given_url
15
+ expect_http_posts_with_responses(example_refresh_ref_url_xml)
16
+ assert(@session.server_cache.refresh_ref_url('http://localhost/roflmao'))
17
+ end
18
+
19
+ def test_can_ask_facebook_to_recache_an_img
20
+ expect_http_posts_with_responses(example_refresh_img_xml)
21
+ assert(@session.server_cache.refresh_img_src('http://localhost/roflmao.jpg'))
22
+ end
23
+
24
+ private
25
+ def example_set_ref_handle_xml
26
+ <<-XML
27
+ <?xml version="1.0" encoding="UTF-8"?>
28
+ <fbml_setRefHandle_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">1</fbml_setRefHandle_response>
29
+ XML
30
+ end
31
+
32
+ def example_refresh_ref_url_xml
33
+ <<-XML
34
+ <?xml version="1.0" encoding="UTF-8"?>
35
+ <fbml_refreshRefUrl_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">1</fbml_refreshRefUrl_response>
36
+ XML
37
+ end
38
+ def example_refresh_img_xml
39
+ <<-XML
40
+ <?xml version="1.0" encoding="UTF-8"?>
41
+ <fbml_refreshImgSrc_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">1</fbml_refreshImgSrc_response>
42
+ XML
43
+ end
44
+ end
@@ -0,0 +1,614 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ require 'active_support'
3
+
4
+ class Facebooker::SessionTest < Test::Unit::TestCase
5
+
6
+
7
+ def setup
8
+ ENV['FACEBOOK_API_KEY'] = '1234567'
9
+ ENV['FACEBOOK_SECRET_KEY'] = '7654321'
10
+ Facebooker.current_adapter = nil
11
+ @session = Facebooker::Session.create('whatever', 'doesnotmatterintest')
12
+ Facebooker.use_curl=false
13
+ end
14
+
15
+ def teardown
16
+ Facebooker::Session.configuration_file_path = nil
17
+ super
18
+ end
19
+
20
+ def test_install_url_escapes_optional_next_parameter
21
+ session = Facebooker::CanvasSession.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
22
+ assert_equal("http://www.facebook.com/install.php?api_key=1234567&v=1.0&next=next_url%3Fa%3D1%26b%3D2", session.install_url(:next => "next_url?a=1&b=2"))
23
+ end
24
+
25
+ def test_can_get_api_and_secret_key_from_environment
26
+ assert_equal('1234567', Facebooker::Session.api_key)
27
+ assert_equal('7654321', Facebooker::Session.secret_key)
28
+ end
29
+
30
+ def test_if_keys_are_not_available_via_environment_then_they_are_gotten_from_a_file
31
+ ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'] = nil
32
+ flexmock(File).should_receive(:read).with(File.expand_path("~/.facebookerrc")).once.and_return('{:api => "foo"}')
33
+ assert_equal('foo', Facebooker::Session.api_key)
34
+ end
35
+
36
+ def test_if_environment_and_file_fail_to_match_then_an_exception_is_raised
37
+ ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'] = nil
38
+ flexmock(File).should_receive(:read).with(File.expand_path("~/.facebookerrc")).once.and_return {raise Errno::ENOENT, "No such file"}
39
+ assert_raises(Facebooker::Session::ConfigurationMissing) {
40
+ Facebooker::Session.api_key
41
+ }
42
+ end
43
+
44
+ def test_marshal_stores_api_key
45
+ data = Marshal.dump(@session)
46
+ loaded_session = Marshal.load(data)
47
+ assert_equal 'whatever', loaded_session.instance_variable_get("@api_key")
48
+ end
49
+
50
+ def test_marshal_stores_secret_key
51
+ data = Marshal.dump(@session)
52
+ loaded_session = Marshal.load(data)
53
+ assert_equal 'doesnotmatterintest', loaded_session.instance_variable_get("@secret_key")
54
+ end
55
+
56
+ def test_configuration_file_path_can_be_set_explicitly
57
+ Facebooker::Session.configuration_file_path = '/tmp/foo'
58
+ assert_equal('/tmp/foo', Facebooker::Session.configuration_file_path)
59
+ end
60
+
61
+ def test_session_can_be_secured_with_existing_values
62
+ session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
63
+ session.secure_with!("a session key", "123456", Time.now.to_i + 60)
64
+ assert(session.secured?)
65
+ assert_equal 'a session key', session.session_key
66
+ assert_equal 123456, session.user.to_i
67
+ end
68
+
69
+ def test_session_can_be_secured_with_existing_values_and_a_nil_uid
70
+ flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
71
+ session.should_receive(:post).with('facebook.users.getLoggedInUser', :session_key => 'a session key').returns(321)
72
+ session.secure_with!("a session key", nil, Time.now.to_i + 60)
73
+ assert(session.secured?)
74
+ assert_equal 'a session key', session.session_key
75
+ assert_equal 321, session.user.to_i
76
+ end
77
+
78
+ # The Facebook API for this is hideous. Oh well.
79
+ def test_can_ask_session_to_check_friendship_between_pairs_of_users
80
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
81
+ mock_http = establish_session
82
+ mock_http.should_receive(:post_form).and_return(example_check_friendship_xml).once.ordered(:posts)
83
+ assert_equal({[222332, 222333] => true, [1240077, 1240079] => false}, @session.check_friendship([[222332, 222333], [1240077, 1240079]]))
84
+ end
85
+
86
+ def test_facebook_can_claim_ignorance_as_to_friend_relationships
87
+ mock_http = establish_session
88
+ mock_http.should_receive(:post_form).and_return(example_check_friendship_with_unknown_result).once.ordered(:posts)
89
+ assert_equal({[1240077, 1240079] => nil}, @session.check_friendship([[1240077, 1240079]]))
90
+ end
91
+
92
+ def test_can_query_with_fql
93
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
94
+ expect_http_posts_with_responses(example_fql_for_multiple_photos_xml)
95
+ response = @session.fql_query('Lets be frank. We are not testing the query here')
96
+ assert_kind_of(Facebooker::Photo, response.first)
97
+ end
98
+
99
+ def test_anonymous_fql_results_get_put_in_a_positioned_array_on_the_model
100
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
101
+ expect_http_posts_with_responses(example_fql_for_multiple_photos_with_anon_xml)
102
+ response = @session.fql_query('Lets be frank. We are not testing the query here')
103
+ assert_kind_of(Facebooker::Photo, response.first)
104
+ response.each do |photo|
105
+ assert_equal(['first', 'second'], photo.anonymous_fields)
106
+ end
107
+ end
108
+ def test_no_results_returns_empty_array
109
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
110
+ expect_http_posts_with_responses(no_results_fql)
111
+ response = @session.fql_query('Lets be frank. We are not testing the query here')
112
+ assert_equal [],response
113
+ end
114
+
115
+ def test_can_fql_query_for_event_members
116
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
117
+ expect_http_posts_with_responses(example_fql_query_event_members_xml)
118
+ response = @session.fql_query("DOES NOT REALLY MATTER FOR TEST")
119
+ assert_kind_of(Facebooker::Event::Attendance, response.first)
120
+ assert_equal('attending', response.first.rsvp_status)
121
+ end
122
+
123
+ def test_can_query_for_event_members
124
+ expect_http_posts_with_responses(example_event_members_xml)
125
+ event_attendances = @session.event_members(69)
126
+ assert_equal Facebooker::Event::Attendance, event_attendances.first.class
127
+ assert_equal 'attending', event_attendances.first.rsvp_status
128
+ assert_equal(["1240077", "222332", "222333", "222335", "222336"], event_attendances.map{|ea| ea.uid}.sort)
129
+ assert_equal 5, event_attendances.size
130
+ end
131
+
132
+ def test_can_query_for_events
133
+ expect_http_posts_with_responses(example_events_get_xml)
134
+ events = @session.events
135
+ assert_equal 'Technology Tasting', events.first.name
136
+ end
137
+
138
+ def test_can_query_for_groups
139
+ expect_http_posts_with_responses(example_groups_get_xml)
140
+ groups = @session.user.groups
141
+ assert_equal 'Donald Knuth Is My Homeboy', groups.first.name
142
+ end
143
+
144
+ def test_can_query_for_group_memberships
145
+ expect_http_posts_with_responses(example_group_members_xml)
146
+ example_group = Facebooker::Group.new({:gid => 123, :session => @session})
147
+ group_memberships = example_group.memberships
148
+ assert_equal('officers', group_memberships.last.position)
149
+ assert_equal(123, group_memberships.last.gid)
150
+ assert_equal(1240078, example_group.members.last.id)
151
+ end
152
+
153
+ def test_can_fql_query_for_users_and_pictures
154
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
155
+ mock_http = establish_session
156
+ mock_http.should_receive(:post_form).and_return(example_fql_for_multiple_users_and_pics).once.ordered(:posts)
157
+ response = @session.fql_query('SELECT name, pic FROM user WHERE uid=211031 OR uid=4801660')
158
+ assert_kind_of Array, response
159
+ assert_kind_of Facebooker::User, response.first
160
+ assert_equal "Ari Steinberg", response.first.name
161
+ end
162
+
163
+
164
+ def test_can_send_notification_with_object
165
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
166
+ @session.expects(:post).with('facebook.notifications.send',{:to_ids=>"1",:notification=>"a",:type=>"user_to_user"},true)
167
+ @session.send(:instance_variable_set,"@uid",3)
168
+ user=flexmock("user")
169
+ user.should_receive(:facebook_id).and_return("1").once
170
+ @session.send_notification([user],"a")
171
+ end
172
+ def test_can_send_notification_with_string
173
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
174
+ @session.send(:instance_variable_set,"@uid",3)
175
+ @session.expects(:post).with('facebook.notifications.send',{:to_ids=>"1",:notification=>"a", :type=>"user_to_user"},true)
176
+ @session.send_notification(["1"],"a")
177
+ end
178
+
179
+ def test_can_send_announcement_notification
180
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
181
+ @session.expects(:post).with('facebook.notifications.send',{:to_ids=>"1",:notification=>"a", :type=>"app_to_user"},false)
182
+ @session.send_notification(["1"],"a")
183
+ end
184
+
185
+ def test_can_register_template_bundle
186
+ expect_http_posts_with_responses(example_register_template_bundle_return_xml)
187
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
188
+ assert_equal 17876842716, @session.register_template_bundle("{*actor*} did something")
189
+ end
190
+
191
+ def test_can_register_template_bundle_with_action_links
192
+ expect_http_posts_with_responses(example_register_template_bundle_return_xml)
193
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
194
+ assert_equal 17876842716, @session.register_template_bundle("{*actor*} did something",nil,nil,[{:text=>"text",:href=>"href"}])
195
+ end
196
+ def test_can_publish_user_action
197
+ expect_http_posts_with_responses(publish_user_action_return_xml)
198
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
199
+ assert @session.publish_user_action(17876842716,{})
200
+ end
201
+
202
+ def test_logs_api_calls
203
+ call_name = 'sample.api.call'
204
+ params = { :param1 => true, :param2 => 'value' }
205
+ flexmock(Facebooker::Logging, :Logging).should_receive(:log_fb_api).once.with(
206
+ call_name, params, Proc)
207
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
208
+ @session.post(call_name, params)
209
+ end
210
+
211
+ def test_requests_inside_batch_are_added_to_batch
212
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
213
+ @session.send(:service).expects(:post).once
214
+ @session.batch do
215
+ @session.send_notification(["1"],"a")
216
+ @session.send_notification(["1"],"a")
217
+ end
218
+
219
+ end
220
+
221
+ def test_parses_batch_response
222
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
223
+ expect_http_posts_with_responses(example_batch_run_xml)
224
+ @session.batch do
225
+ @fql_response = @session.fql_query('SELECT name, pic FROM user WHERE uid=211031 OR uid=4801660')
226
+ end
227
+ assert_kind_of(Facebooker::Event::Attendance, @fql_response.first)
228
+ assert_equal('attending', @fql_response.first.rsvp_status)
229
+ end
230
+ def test_parses_batch_response_sets_exception
231
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
232
+ expect_http_posts_with_responses(example_batch_run_xml)
233
+ Facebooker::FqlQuery.expects(:process).raises(NoMethodError.new)
234
+
235
+ @session.batch do
236
+ @fql_response = @session.fql_query('SELECT name, pic FROM user WHERE uid=211031 OR uid=4801660')
237
+ end
238
+ assert_raises(NoMethodError) {
239
+ @fql_response.first
240
+ }
241
+ end
242
+
243
+ def test_can_set_and_get_current_batch
244
+ Facebooker::BatchRun.current_batch=4
245
+ assert_equal 4,Facebooker::BatchRun.current_batch
246
+ end
247
+
248
+ def test_can_get_stanard_info
249
+ expect_http_posts_with_responses(standard_info_xml)
250
+ result = @session.users_standard([4])
251
+ assert_equal "Mike Mangino",result.first.name
252
+ end
253
+
254
+ def test_can_query_for_pages
255
+ expect_http_posts_with_responses(example_pages_xml)
256
+ example_page = Facebooker::Page.new(
257
+ :page_id => 4846711747,
258
+ :name => "Kronos Quartet",
259
+ :website => "http://www.kronosquartet.org",
260
+ :company_overview => "",
261
+ :session => @session)
262
+ pages = @session.pages(:fields => %w[ page_id name website company_overview ])
263
+
264
+ assert_equal 1, pages.size
265
+
266
+ page = pages.first
267
+ assert_equal "4846711747", page.page_id
268
+ assert_equal "Kronos Quartet", page.name
269
+ assert_equal "http://www.kronosquartet.org", page.website
270
+
271
+ # TODO we really need a way to differentiate between hash/list and text attributes
272
+ # assert_equal({}, page.company_overview)
273
+
274
+ # sakkaoui : as a fix to the parser, I replace empty text node by "" instead of {}
275
+ # we have child.attributes['list'] == 'true' that let us know that we have a hash/list.
276
+ assert_equal("", page.company_overview)
277
+
278
+ genre = page.genre
279
+ assert_equal false, genre.dance
280
+ assert_equal true, genre.party
281
+ end
282
+
283
+ private
284
+
285
+ def example_groups_get_xml
286
+ <<-XML
287
+ <?xml version="1.0" encoding="UTF-8"?>
288
+ <groups_get_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">
289
+ <group>
290
+ <gid>2206609142</gid>
291
+ <name>Donald Knuth Is My Homeboy</name>
292
+ <nid>0</nid>
293
+ <description>Donald Ervin Knuth (born January 10, 1938) is a renowned computer scientist and professor emeritus at Stanford University.
294
+
295
+ Knuth is best known as the author of the multi-volume The Art of Computer Programming, one of the most highly respected references in the computer science field. He practically created the field of rigorous analysis of algorithms, and made many seminal contributions to several branches of theoretical computer science. He is also the creator of the TeX typesetting system and of the METAFONT font design system, and pioneered the concept of literate programming.
296
+
297
+ That's how he ROLLS, y0.</description>
298
+ <group_type>Just for Fun</group_type>
299
+ <group_subtype>Fan Clubs</group_subtype>
300
+ <recent_news/>
301
+ <pic>http://photos-142.facebook.com/ip006/object/543/95/s2206609142_32530.jpg</pic>
302
+ <pic_big>http://photos-142.facebook.com/ip006/object/543/95/n2206609142_32530.jpg</pic_big>
303
+ <pic_small>http://photos-142.facebook.com/ip006/object/543/95/t2206609142_32530.jpg</pic_small>
304
+ <creator>1240077</creator>
305
+ <update_time>1156543965</update_time>
306
+ <office/>
307
+ <website/>
308
+ <venue>
309
+ <street/>
310
+ <city/>
311
+ <state>CA</state>
312
+ <country>United States</country>
313
+ </venue>
314
+ </group>
315
+ </groups_get_response>
316
+ XML
317
+ end
318
+
319
+ def example_events_get_xml
320
+ <<-XML
321
+ <?xml version="1.0" encoding="UTF-8"?>
322
+ <events_get_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">
323
+ <event>
324
+ <eid>1037629024</eid>
325
+ <name>Technology Tasting</name>
326
+ <tagline>Who said Engineering can't be delicious?</tagline>
327
+ <nid>12409987</nid>
328
+ <pic>http://photos-628.facebook.com/ip006/object/1345/48/s1037629024_30775.jpg</pic>
329
+ <pic_big>http://photos-628.facebook.com/ip006/object/1345/48/n1037629024_30775.jpg</pic_big>
330
+ <pic_small>http://photos-628.facebook.com/ip006/object/1345/48/t1037629024_30775.jpg</pic_small>
331
+ <host>Facebook</host>
332
+ <description>Facebook will be hosting technology thought leaders and avid software engineers for a social evening of technology tasting. We invite you to connect with some of our newest technologies and innovative people over hors d'oeuvres and wine. Come share ideas, ask questions, and challenge existing technology paradigms in the spirit of the open source community.</description>
333
+ <event_type>Party</event_type>
334
+ <event_subtype>Cocktail Party</event_subtype>
335
+ <start_time>1172107800</start_time>
336
+ <end_time>1172115000</end_time>
337
+ <creator>1078</creator>
338
+ <update_time>1170096157</update_time>
339
+ <location>Facebook's New Office</location>
340
+ <venue>
341
+ <city>Palo Alto</city>
342
+ <state>CA</state>
343
+ <country>United States</country>
344
+ </venue>
345
+ </event>
346
+ </events_get_response>
347
+ XML
348
+ end
349
+
350
+ def example_fql_query_event_members_xml
351
+ <<-XML
352
+ <?xml version="1.0" encoding="UTF-8"?>
353
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
354
+ <event_member>
355
+ <uid>517961878</uid>
356
+ <eid>2454827764</eid>
357
+ <rsvp_status>attending</rsvp_status>
358
+ </event_member>
359
+ <event_member>
360
+ <uid>744961110</uid>
361
+ <eid>2454827764</eid>
362
+ <rsvp_status>declined</rsvp_status>
363
+ </event_member>
364
+ </fql_query_response>
365
+ XML
366
+ end
367
+ def example_check_friendship_xml
368
+ <<-XML
369
+ <?xml version="1.0" encoding="UTF-8"?>
370
+ <friends_areFriends_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">
371
+ <friend_info>
372
+ <uid1>222332</uid1>
373
+ <uid2>222333</uid2>
374
+ <are_friends>1</are_friends>
375
+ </friend_info>
376
+ <friend_info>
377
+ <uid1>1240077</uid1>
378
+ <uid2>1240079</uid2>
379
+ <are_friends>0</are_friends>
380
+ </friend_info>
381
+ </friends_areFriends_response>
382
+ XML
383
+ end
384
+
385
+ def example_check_friendship_with_unknown_result
386
+ <<-XML
387
+ <?xml version="1.0" encoding="UTF-8"?>
388
+ <friends_areFriends_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">
389
+ <friend_info>
390
+ <uid1>1240077</uid1>
391
+ <uid2>1240079</uid2>
392
+ <are_friends xsi:nil="true"/>
393
+ </friend_info>
394
+ </friends_areFriends_response>
395
+ XML
396
+ end
397
+
398
+ def example_fql_for_multiple_users_and_pics
399
+ <<-XML
400
+ <?xml version="1.0" encoding="UTF-8"?>
401
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
402
+ <user>
403
+ <name>Ari Steinberg</name>
404
+ <pic>http://profile.ak.facebook.com/profile2/1805/47/s211031_26434.jpg</pic>
405
+ </user>
406
+ <user>
407
+ <name>Ruchi Sanghvi</name>
408
+ <pic>http://profile.ak.facebook.com/v52/870/125/s4801660_2498.jpg</pic>
409
+ </user>
410
+ </fql_query_response>
411
+ XML
412
+ end
413
+
414
+ def example_fql_for_multiple_photos_xml
415
+ <<-XML
416
+ <?xml version="1.0" encoding="UTF-8"?>
417
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
418
+ <photo>
419
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v108/212/118/22700225/s22700225_30345986_2713.jpg</src>
420
+ <caption>Nottttt. get ready for some museumz</caption>
421
+ <caption>Nottttt. get ready for some museumz</caption>
422
+ </photo>
423
+ <photo>
424
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v77/74/112/22701786/s22701786_30324934_7816.jpg</src>
425
+ <caption>Rooftop barbecues make me act funny</caption>
426
+ <caption>Rooftop barbecues make me act funny</caption>
427
+ </photo>
428
+ <photo>
429
+ <src>http://photos-c.ak.facebook.com/photos-ak-sctm/v96/154/56/22700188/s22700188_30321538_17.jpg</src>
430
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
431
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
432
+ </photo>
433
+ </fql_query_response>
434
+ XML
435
+ end
436
+
437
+ def example_fql_for_multiple_photos_with_anon_xml
438
+ <<-XML
439
+ <?xml version="1.0" encoding="UTF-8"?>
440
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
441
+ <photo>
442
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v108/212/118/22700225/s22700225_30345986_2713.jpg</src>
443
+ <caption>Nottttt. get ready for some museumz</caption>
444
+ <caption>Nottttt. get ready for some museumz</caption>
445
+ <anon>first</anon>
446
+ <anon>second</anon>
447
+ </photo>
448
+ <photo>
449
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v77/74/112/22701786/s22701786_30324934_7816.jpg</src>
450
+ <caption>Rooftop barbecues make me act funny</caption>
451
+ <caption>Rooftop barbecues make me act funny</caption>
452
+ <anon>first</anon>
453
+ <anon>second</anon>
454
+ </photo>
455
+ <photo>
456
+ <src>http://photos-c.ak.facebook.com/photos-ak-sctm/v96/154/56/22700188/s22700188_30321538_17.jpg</src>
457
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
458
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
459
+ <anon>first</anon>
460
+ <anon>second</anon>
461
+ </photo>
462
+ </fql_query_response>
463
+ XML
464
+ end
465
+
466
+ def no_results_fql
467
+ <<-XML
468
+ <?xml version="1.0" encoding="UTF-8"?>
469
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
470
+ </fql_query_response>
471
+ XML
472
+
473
+ end
474
+
475
+ def example_group_members_xml
476
+ <<-XML
477
+ <?xml version="1.0" encoding="UTF-8"?>
478
+ <groups_getMembers_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">
479
+ <members list="true">
480
+ <uid>1240077</uid>
481
+ <uid>1240078</uid>
482
+ <uid>222332</uid>
483
+ <uid>222333</uid>
484
+ </members>
485
+ <admins list="true">
486
+ <uid>1240077</uid>
487
+ <uid>222333</uid>
488
+ </admins>
489
+ <officers list="true">
490
+ <uid>1240078</uid>
491
+ </officers>
492
+ <not_replied list="true"/>
493
+ </groups_getMembers_response>
494
+ XML
495
+ end
496
+
497
+ def example_batch_run_xml
498
+ <<-XML
499
+ <?xml version="1.0" encoding="UTF-8"?>
500
+ <batch_run_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">
501
+ <batch_run_response_elt>
502
+ #{CGI.escapeHTML(example_fql_query_event_members_xml)}
503
+ </batch_run_response_elt>
504
+ </batch_run_response>
505
+ XML
506
+ end
507
+
508
+ def example_event_members_xml
509
+ <<-XML
510
+ <?xml version="1.0" encoding="UTF-8"?>
511
+ <events_getMembers_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">
512
+ <attending list="true">
513
+ <uid>222332</uid>
514
+ <uid>222333</uid>
515
+ </attending>
516
+ <unsure list="true">
517
+ <uid>1240077</uid>
518
+ </unsure>
519
+ <declined list="true"/>
520
+ <not_replied list="true">
521
+ <uid>222335</uid>
522
+ <uid>222336</uid>
523
+ </not_replied>
524
+ </events_getMembers_response>
525
+ XML
526
+ end
527
+
528
+ def example_register_template_bundle_return_xml
529
+ <<-XML
530
+ <?xml version="1.0" encoding="UTF-8"?>
531
+ <feed_registerTemplateBundle_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/">
532
+ 17876842716
533
+ </feed_registerTemplateBundle_response>
534
+ XML
535
+ end
536
+
537
+ def example_pages_xml
538
+ <<-XML
539
+ <?xml version="1.0" encoding="UTF-8"?>
540
+ <pages_getInfo_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">
541
+ <page>
542
+ <page_id>4846711747</page_id>
543
+ <name>Kronos Quartet</name>
544
+ <website>http://www.kronosquartet.org</website>
545
+ <company_overview/>
546
+ <genre>
547
+ <dance>0</dance>
548
+ <party>1</party>
549
+ </genre>
550
+ </page>
551
+ </pages_getInfo_response>
552
+ XML
553
+ end
554
+
555
+ def publish_user_action_return_xml
556
+ <<-XML
557
+ <?xml version="1.0" encoding="UTF-8"?>
558
+ <feed_publishUserAction_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">
559
+ <feed_publishUserAction_response_elt>1</feed_publishUserAction_response_elt>
560
+ </feed_publishUserAction_response>
561
+ XML
562
+ end
563
+
564
+ def standard_info_xml
565
+ <<-XML
566
+ <?xml version="1.0" encoding="UTF-8"?>
567
+ <?xml version="1.0" encoding="UTF-8"?>
568
+
569
+ <users_getStandardInfo_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">
570
+ <standard_user_info>
571
+ <uid>12451752</uid>
572
+ <name>Mike Mangino</name>
573
+ </standard_user_info>
574
+ </users_getStandardInfo_response>
575
+ XML
576
+ end
577
+ end
578
+
579
+ class PostMethodTest < Test::Unit::TestCase
580
+
581
+ def setup
582
+ Facebooker.use_curl = true
583
+ Facebooker::Parser.stubs(:parse)
584
+ @uri = URI.parse("http://api.facebook.com/api")
585
+ @service = Facebooker::Service.new("a","b","c")
586
+ @service.stubs("url").returns(@uri)
587
+ end
588
+
589
+ def teardown
590
+ Facebooker.use_curl = false
591
+ end
592
+
593
+ def test_use_curl_makes_post_with_curl
594
+ @service.expects(:post_form_with_curl).with(@uri,{:method=>"a"})
595
+ @service.post(:method=>"a")
596
+ end
597
+
598
+ def test_use_curl_makes_post_file_use_curl_with_multipart
599
+ @service.expects(:post_form_with_curl).with(@uri,{:method=>"a"},true)
600
+ @service.post_file(:method=>"a")
601
+ end
602
+ end
603
+
604
+ class CanvasSessionTest < Test::Unit::TestCase
605
+ def setup
606
+ ENV['FACEBOOK_API_KEY'] = '1234567'
607
+ ENV['FACEBOOK_SECRET_KEY'] = '7654321'
608
+ end
609
+
610
+ def test_login_url_will_display_callback_url_in_canvas
611
+ session = Facebooker::CanvasSession.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
612
+ assert_equal("http://www.facebook.com/login.php?api_key=1234567&v=1.0&canvas=true", session.login_url)
613
+ end
614
+ end