yury-facebooker 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/CHANGELOG.txt +0 -0
  2. data/COPYING +19 -0
  3. data/History.txt +16 -0
  4. data/Manifest.txt +77 -0
  5. data/README +46 -0
  6. data/README.txt +81 -0
  7. data/Rakefile +62 -0
  8. data/TODO.txt +10 -0
  9. data/facebooker.yml.tpl +41 -0
  10. data/init.rb +53 -0
  11. data/install.rb +7 -0
  12. data/lib/facebooker.rb +143 -0
  13. data/lib/facebooker/data.rb +40 -0
  14. data/lib/facebooker/feed.rb +78 -0
  15. data/lib/facebooker/model.rb +123 -0
  16. data/lib/facebooker/parser.rb +518 -0
  17. data/lib/facebooker/rails/controller.rb +241 -0
  18. data/lib/facebooker/rails/facebook_asset_path.rb +18 -0
  19. data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
  20. data/lib/facebooker/rails/facebook_request_fix.rb +24 -0
  21. data/lib/facebooker/rails/facebook_session_handling.rb +58 -0
  22. data/lib/facebooker/rails/facebook_url_rewriting.rb +39 -0
  23. data/lib/facebooker/rails/helpers.rb +615 -0
  24. data/lib/facebooker/rails/routing.rb +49 -0
  25. data/lib/facebooker/rails/test_helpers.rb +88 -0
  26. data/lib/facebooker/rails/utilities.rb +22 -0
  27. data/lib/facebooker/server_cache.rb +24 -0
  28. data/lib/facebooker/service.rb +31 -0
  29. data/lib/facebooker/session.rb +550 -0
  30. data/lib/facebooker/version.rb +9 -0
  31. data/lib/net/http_multipart_post.rb +123 -0
  32. data/lib/tasks/facebooker.rake +17 -0
  33. data/lib/tasks/tunnel.rake +43 -0
  34. data/setup.rb +1585 -0
  35. data/test/event_test.rb +15 -0
  36. data/test/facebook_cache_test.rb +43 -0
  37. data/test/facebook_data_test.rb +50 -0
  38. data/test/facebooker_test.rb +855 -0
  39. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  40. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  41. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  42. data/test/http_multipart_post_test.rb +54 -0
  43. data/test/model_test.rb +91 -0
  44. data/test/rails_integration_test.rb +993 -0
  45. data/test/session_test.rb +559 -0
  46. data/test/test_helper.rb +60 -0
  47. data/test/user_test.rb +219 -0
  48. metadata +130 -0
@@ -0,0 +1,559 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class SessionTest < Test::Unit::TestCase
4
+
5
+
6
+ def setup
7
+ ENV['FACEBOOK_API_KEY'] = '1234567'
8
+ ENV['FACEBOOK_SECRET_KEY'] = '7654321'
9
+ Facebooker.current_adapter = nil
10
+ @session = Facebooker::Session.create('whatever', 'doesnotmatterintest')
11
+ end
12
+
13
+ def teardown
14
+ Facebooker::Session.configuration_file_path = nil
15
+ super
16
+ end
17
+
18
+ def test_install_url_escapes_optional_next_parameter
19
+ session = Facebooker::CanvasSession.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
20
+ 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"))
21
+ end
22
+
23
+ def test_can_get_api_and_secret_key_from_environment
24
+ assert_equal('1234567', Facebooker::Session.api_key)
25
+ assert_equal('7654321', Facebooker::Session.secret_key)
26
+ end
27
+
28
+ def test_if_keys_are_not_available_via_environment_then_they_are_gotten_from_a_file
29
+ ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'] = nil
30
+ flexmock(File).should_receive(:read).with(File.expand_path("~/.facebookerrc")).once.and_return('{:api => "foo"}')
31
+ assert_equal('foo', Facebooker::Session.api_key)
32
+ end
33
+
34
+ def test_if_environment_and_file_fail_to_match_then_an_exception_is_raised
35
+ ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'] = nil
36
+ flexmock(File).should_receive(:read).with(File.expand_path("~/.facebookerrc")).once.and_return {raise Errno::ENOENT, "No such file"}
37
+ assert_raises(Facebooker::Session::ConfigurationMissing) {
38
+ Facebooker::Session.api_key
39
+ }
40
+ end
41
+
42
+ def test_marshal_stores_api_key
43
+ data = Marshal.dump(@session)
44
+ loaded_session = Marshal.load(data)
45
+ assert_equal 'whatever', loaded_session.instance_variable_get("@api_key")
46
+ end
47
+
48
+ def test_marshal_stores_secret_key
49
+ data = Marshal.dump(@session)
50
+ loaded_session = Marshal.load(data)
51
+ assert_equal 'doesnotmatterintest', loaded_session.instance_variable_get("@secret_key")
52
+ end
53
+
54
+ def test_configuration_file_path_can_be_set_explicitly
55
+ Facebooker::Session.configuration_file_path = '/tmp/foo'
56
+ assert_equal('/tmp/foo', Facebooker::Session.configuration_file_path)
57
+ end
58
+
59
+ def test_session_can_be_secured_with_existing_values
60
+ session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
61
+ session.secure_with!("a session key", "123456", Time.now.to_i + 60)
62
+ assert(session.secured?)
63
+ assert_equal 'a session key', session.session_key
64
+ assert_equal 123456, session.user.to_i
65
+ end
66
+
67
+ def test_session_can_be_secured_with_existing_values_and_a_nil_uid
68
+ flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
69
+ session.should_receive(:post).with('facebook.users.getLoggedInUser', :session_key => 'a session key').returns(321)
70
+ session.secure_with!("a session key", nil, Time.now.to_i + 60)
71
+ assert(session.secured?)
72
+ assert_equal 'a session key', session.session_key
73
+ assert_equal 321, session.user.to_i
74
+ end
75
+
76
+ # The Facebook API for this is hideous. Oh well.
77
+ def test_can_ask_session_to_check_friendship_between_pairs_of_users
78
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
79
+ mock_http = establish_session
80
+ mock_http.should_receive(:post_form).and_return(example_check_friendship_xml).once.ordered(:posts)
81
+ assert_equal({[222332, 222333] => true, [1240077, 1240079] => false}, @session.check_friendship([[222332, 222333], [1240077, 1240079]]))
82
+ end
83
+
84
+ def test_facebook_can_claim_ignorance_as_to_friend_relationships
85
+ mock_http = establish_session
86
+ mock_http.should_receive(:post_form).and_return(example_check_friendship_with_unknown_result).once.ordered(:posts)
87
+ assert_equal({[1240077, 1240079] => nil}, @session.check_friendship([[1240077, 1240079]]))
88
+ end
89
+
90
+ def test_can_query_with_fql
91
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
92
+ expect_http_posts_with_responses(example_fql_for_multiple_photos_xml)
93
+ response = @session.fql_query('Lets be frank. We are not testing the query here')
94
+ assert_kind_of(Facebooker::Photo, response.first)
95
+ end
96
+
97
+ def test_anonymous_fql_results_get_put_in_a_positioned_array_on_the_model
98
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
99
+ expect_http_posts_with_responses(example_fql_for_multiple_photos_with_anon_xml)
100
+ response = @session.fql_query('Lets be frank. We are not testing the query here')
101
+ assert_kind_of(Facebooker::Photo, response.first)
102
+ response.each do |photo|
103
+ assert_equal(['first', 'second'], photo.anonymous_fields)
104
+ end
105
+ end
106
+ def test_no_results_returns_empty_array
107
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
108
+ expect_http_posts_with_responses(no_results_fql)
109
+ response = @session.fql_query('Lets be frank. We are not testing the query here')
110
+ assert_equal [],response
111
+ end
112
+
113
+ def test_can_fql_query_for_event_members
114
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
115
+ expect_http_posts_with_responses(example_fql_query_event_members_xml)
116
+ response = @session.fql_query("DOES NOT REALLY MATTER FOR TEST")
117
+ assert_kind_of(Facebooker::Event::Attendance, response.first)
118
+ assert_equal('attending', response.first.rsvp_status)
119
+ end
120
+
121
+ def test_can_query_for_event_members
122
+ expect_http_posts_with_responses(example_event_members_xml)
123
+ event_attendances = @session.event_members(69)
124
+ assert_equal Facebooker::Event::Attendance, event_attendances.first.class
125
+ assert_equal 'attending', event_attendances.first.rsvp_status
126
+ assert_equal(["1240077", "222332", "222333", "222335", "222336"], event_attendances.map{|ea| ea.uid}.sort)
127
+ assert_equal 5, event_attendances.size
128
+ end
129
+
130
+ def test_can_query_for_events
131
+ expect_http_posts_with_responses(example_events_get_xml)
132
+ events = @session.events
133
+ assert_equal 'Technology Tasting', events.first.name
134
+ end
135
+
136
+ def test_can_query_for_groups
137
+ expect_http_posts_with_responses(example_groups_get_xml)
138
+ groups = @session.user.groups
139
+ assert_equal 'Donald Knuth Is My Homeboy', groups.first.name
140
+ end
141
+
142
+ def test_can_query_for_group_memberships
143
+ expect_http_posts_with_responses(example_group_members_xml)
144
+ example_group = Facebooker::Group.new({:gid => 123, :session => @session})
145
+ group_memberships = example_group.memberships
146
+ assert_equal('officers', group_memberships.last.position)
147
+ assert_equal(123, group_memberships.last.gid)
148
+ assert_equal(1240078, example_group.members.last.id)
149
+ end
150
+
151
+ def test_can_fql_query_for_users_and_pictures
152
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
153
+ mock_http = establish_session
154
+ mock_http.should_receive(:post_form).and_return(example_fql_for_multiple_users_and_pics).once.ordered(:posts)
155
+ response = @session.fql_query('SELECT name, pic FROM user WHERE uid=211031 OR uid=4801660')
156
+ assert_kind_of Array, response
157
+ assert_kind_of Facebooker::User, response.first
158
+ assert_equal "Ari Steinberg", response.first.name
159
+ end
160
+
161
+
162
+ def test_can_send_notification_with_object
163
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
164
+ @session.expects(:post).with('facebook.notifications.send',{:to_ids=>"1",:notification=>"a",:type=>"user_to_user"},true)
165
+ @session.send(:instance_variable_set,"@uid",3)
166
+ user=flexmock("user")
167
+ user.should_receive(:facebook_id).and_return("1").once
168
+ @session.send_notification([user],"a")
169
+ end
170
+ def test_can_send_notification_with_string
171
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
172
+ @session.send(:instance_variable_set,"@uid",3)
173
+ @session.expects(:post).with('facebook.notifications.send',{:to_ids=>"1",:notification=>"a", :type=>"user_to_user"},true)
174
+ @session.send_notification(["1"],"a")
175
+ end
176
+
177
+ def test_can_send_announcement_notification
178
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
179
+ @session.expects(:post).with('facebook.notifications.send',{:to_ids=>"1",:notification=>"a", :type=>"app_to_user"},false)
180
+ @session.send_notification(["1"],"a")
181
+ end
182
+
183
+ def test_can_register_template_bundle
184
+ expect_http_posts_with_responses(example_register_template_bundle_return_xml)
185
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
186
+ assert_equal 17876842716, @session.register_template_bundle("{*actor*} did something")
187
+ end
188
+
189
+
190
+ def test_can_publish_user_action
191
+ expect_http_posts_with_responses(publish_user_action_return_xml)
192
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
193
+ assert @session.publish_user_action(17876842716,{})
194
+ end
195
+
196
+ def test_logs_api_calls
197
+ call_name = 'sample.api.call'
198
+ params = { :param1 => true, :param2 => 'value' }
199
+ flexmock(Facebooker::Logging, :Logging).should_receive(:log_fb_api).once.with(
200
+ call_name, params, Proc)
201
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
202
+ @session.post(call_name, params)
203
+ end
204
+
205
+ def test_requests_inside_batch_are_added_to_batch
206
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
207
+ @session.send(:service).expects(:post).once
208
+ @session.batch do
209
+ @session.send_notification(["1"],"a")
210
+ @session.send_notification(["1"],"a")
211
+ end
212
+
213
+ end
214
+
215
+ def test_parses_batch_response
216
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
217
+ expect_http_posts_with_responses(example_batch_run_xml)
218
+ @session.batch do
219
+ @fql_response = @session.fql_query('SELECT name, pic FROM user WHERE uid=211031 OR uid=4801660')
220
+ end
221
+ assert_kind_of(Facebooker::Event::Attendance, @fql_response.first)
222
+ assert_equal('attending', @fql_response.first.rsvp_status)
223
+ end
224
+ def test_parses_batch_response_sets_exception
225
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
226
+ expect_http_posts_with_responses(example_batch_run_xml)
227
+ Facebooker::FqlQuery.expects(:process).raises(NoMethodError.new)
228
+
229
+ @session.batch do
230
+ @fql_response = @session.fql_query('SELECT name, pic FROM user WHERE uid=211031 OR uid=4801660')
231
+ end
232
+ assert_raises(NoMethodError) {
233
+ @fql_response.first
234
+ }
235
+ end
236
+
237
+ def test_can_set_and_get_current_batch
238
+ Facebooker::BatchRun.current_batch=4
239
+ assert_equal 4,Facebooker::BatchRun.current_batch
240
+ end
241
+
242
+ def test_can_query_for_pages
243
+ expect_http_posts_with_responses(example_pages_xml)
244
+ example_page = Facebooker::Page.new(
245
+ :page_id => 4846711747,
246
+ :name => "Kronos Quartet",
247
+ :website => "http://www.kronosquartet.org",
248
+ :company_overview => "",
249
+ :session => @session)
250
+ pages = @session.pages(:fields => %w[ page_id name website company_overview ])
251
+
252
+ assert_equal 1, pages.size
253
+
254
+ page = pages.first
255
+ assert_equal "4846711747", page.page_id
256
+ assert_equal "Kronos Quartet", page.name
257
+ assert_equal "http://www.kronosquartet.org", page.website
258
+ # TODO we really need a way to differentiate between hash/list and text attributes
259
+ assert_equal({}, page.company_overview)
260
+
261
+ genre = page.genre
262
+ assert_equal false, genre.dance
263
+ assert_equal true, genre.party
264
+ end
265
+
266
+ private
267
+
268
+ def example_groups_get_xml
269
+ <<-XML
270
+ <?xml version="1.0" encoding="UTF-8"?>
271
+ <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">
272
+ <group>
273
+ <gid>2206609142</gid>
274
+ <name>Donald Knuth Is My Homeboy</name>
275
+ <nid>0</nid>
276
+ <description>Donald Ervin Knuth (born January 10, 1938) is a renowned computer scientist and professor emeritus at Stanford University.
277
+
278
+ 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.
279
+
280
+ That's how he ROLLS, y0.</description>
281
+ <group_type>Just for Fun</group_type>
282
+ <group_subtype>Fan Clubs</group_subtype>
283
+ <recent_news/>
284
+ <pic>http://photos-142.facebook.com/ip006/object/543/95/s2206609142_32530.jpg</pic>
285
+ <pic_big>http://photos-142.facebook.com/ip006/object/543/95/n2206609142_32530.jpg</pic_big>
286
+ <pic_small>http://photos-142.facebook.com/ip006/object/543/95/t2206609142_32530.jpg</pic_small>
287
+ <creator>1240077</creator>
288
+ <update_time>1156543965</update_time>
289
+ <office/>
290
+ <website/>
291
+ <venue>
292
+ <street/>
293
+ <city/>
294
+ <state>CA</state>
295
+ <country>United States</country>
296
+ </venue>
297
+ </group>
298
+ </groups_get_response>
299
+ XML
300
+ end
301
+
302
+ def example_events_get_xml
303
+ <<-XML
304
+ <?xml version="1.0" encoding="UTF-8"?>
305
+ <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">
306
+ <event>
307
+ <eid>1037629024</eid>
308
+ <name>Technology Tasting</name>
309
+ <tagline>Who said Engineering can't be delicious?</tagline>
310
+ <nid>12409987</nid>
311
+ <pic>http://photos-628.facebook.com/ip006/object/1345/48/s1037629024_30775.jpg</pic>
312
+ <pic_big>http://photos-628.facebook.com/ip006/object/1345/48/n1037629024_30775.jpg</pic_big>
313
+ <pic_small>http://photos-628.facebook.com/ip006/object/1345/48/t1037629024_30775.jpg</pic_small>
314
+ <host>Facebook</host>
315
+ <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>
316
+ <event_type>Party</event_type>
317
+ <event_subtype>Cocktail Party</event_subtype>
318
+ <start_time>1172107800</start_time>
319
+ <end_time>1172115000</end_time>
320
+ <creator>1078</creator>
321
+ <update_time>1170096157</update_time>
322
+ <location>Facebook's New Office</location>
323
+ <venue>
324
+ <city>Palo Alto</city>
325
+ <state>CA</state>
326
+ <country>United States</country>
327
+ </venue>
328
+ </event>
329
+ </events_get_response>
330
+ XML
331
+ end
332
+
333
+ def example_fql_query_event_members_xml
334
+ <<-XML
335
+ <?xml version="1.0" encoding="UTF-8"?>
336
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
337
+ <event_member>
338
+ <uid>517961878</uid>
339
+ <eid>2454827764</eid>
340
+ <rsvp_status>attending</rsvp_status>
341
+ </event_member>
342
+ <event_member>
343
+ <uid>744961110</uid>
344
+ <eid>2454827764</eid>
345
+ <rsvp_status>declined</rsvp_status>
346
+ </event_member>
347
+ </fql_query_response>
348
+ XML
349
+ end
350
+ def example_check_friendship_xml
351
+ <<-XML
352
+ <?xml version="1.0" encoding="UTF-8"?>
353
+ <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">
354
+ <friend_info>
355
+ <uid1>222332</uid1>
356
+ <uid2>222333</uid2>
357
+ <are_friends>1</are_friends>
358
+ </friend_info>
359
+ <friend_info>
360
+ <uid1>1240077</uid1>
361
+ <uid2>1240079</uid2>
362
+ <are_friends>0</are_friends>
363
+ </friend_info>
364
+ </friends_areFriends_response>
365
+ XML
366
+ end
367
+
368
+ def example_check_friendship_with_unknown_result
369
+ <<-XML
370
+ <?xml version="1.0" encoding="UTF-8"?>
371
+ <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">
372
+ <friend_info>
373
+ <uid1>1240077</uid1>
374
+ <uid2>1240079</uid2>
375
+ <are_friends xsi:nil="true"/>
376
+ </friend_info>
377
+ </friends_areFriends_response>
378
+ XML
379
+ end
380
+
381
+ def example_fql_for_multiple_users_and_pics
382
+ <<-XML
383
+ <?xml version="1.0" encoding="UTF-8"?>
384
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
385
+ <user>
386
+ <name>Ari Steinberg</name>
387
+ <pic>http://profile.ak.facebook.com/profile2/1805/47/s211031_26434.jpg</pic>
388
+ </user>
389
+ <user>
390
+ <name>Ruchi Sanghvi</name>
391
+ <pic>http://profile.ak.facebook.com/v52/870/125/s4801660_2498.jpg</pic>
392
+ </user>
393
+ </fql_query_response>
394
+ XML
395
+ end
396
+
397
+ def example_fql_for_multiple_photos_xml
398
+ <<-XML
399
+ <?xml version="1.0" encoding="UTF-8"?>
400
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
401
+ <photo>
402
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v108/212/118/22700225/s22700225_30345986_2713.jpg</src>
403
+ <caption>Nottttt. get ready for some museumz</caption>
404
+ <caption>Nottttt. get ready for some museumz</caption>
405
+ </photo>
406
+ <photo>
407
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v77/74/112/22701786/s22701786_30324934_7816.jpg</src>
408
+ <caption>Rooftop barbecues make me act funny</caption>
409
+ <caption>Rooftop barbecues make me act funny</caption>
410
+ </photo>
411
+ <photo>
412
+ <src>http://photos-c.ak.facebook.com/photos-ak-sctm/v96/154/56/22700188/s22700188_30321538_17.jpg</src>
413
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
414
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
415
+ </photo>
416
+ </fql_query_response>
417
+ XML
418
+ end
419
+
420
+ def example_fql_for_multiple_photos_with_anon_xml
421
+ <<-XML
422
+ <?xml version="1.0" encoding="UTF-8"?>
423
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
424
+ <photo>
425
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v108/212/118/22700225/s22700225_30345986_2713.jpg</src>
426
+ <caption>Nottttt. get ready for some museumz</caption>
427
+ <caption>Nottttt. get ready for some museumz</caption>
428
+ <anon>first</anon>
429
+ <anon>second</anon>
430
+ </photo>
431
+ <photo>
432
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v77/74/112/22701786/s22701786_30324934_7816.jpg</src>
433
+ <caption>Rooftop barbecues make me act funny</caption>
434
+ <caption>Rooftop barbecues make me act funny</caption>
435
+ <anon>first</anon>
436
+ <anon>second</anon>
437
+ </photo>
438
+ <photo>
439
+ <src>http://photos-c.ak.facebook.com/photos-ak-sctm/v96/154/56/22700188/s22700188_30321538_17.jpg</src>
440
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
441
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
442
+ <anon>first</anon>
443
+ <anon>second</anon>
444
+ </photo>
445
+ </fql_query_response>
446
+ XML
447
+ end
448
+
449
+ def no_results_fql
450
+ <<-XML
451
+ <?xml version="1.0" encoding="UTF-8"?>
452
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
453
+ </fql_query_response>
454
+ XML
455
+
456
+ end
457
+
458
+ def example_group_members_xml
459
+ <<-XML
460
+ <?xml version="1.0" encoding="UTF-8"?>
461
+ <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">
462
+ <members list="true">
463
+ <uid>1240077</uid>
464
+ <uid>1240078</uid>
465
+ <uid>222332</uid>
466
+ <uid>222333</uid>
467
+ </members>
468
+ <admins list="true">
469
+ <uid>1240077</uid>
470
+ <uid>222333</uid>
471
+ </admins>
472
+ <officers list="true">
473
+ <uid>1240078</uid>
474
+ </officers>
475
+ <not_replied list="true"/>
476
+ </groups_getMembers_response>
477
+ XML
478
+ end
479
+
480
+ def example_batch_run_xml
481
+ <<-XML
482
+ <?xml version="1.0" encoding="UTF-8"?>
483
+ <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">
484
+ <batch_run_response_elt>
485
+ #{CGI.escapeHTML(example_fql_query_event_members_xml)}
486
+ </batch_run_response_elt>
487
+ </batch_run_response>
488
+ XML
489
+ end
490
+
491
+ def example_event_members_xml
492
+ <<-XML
493
+ <?xml version="1.0" encoding="UTF-8"?>
494
+ <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">
495
+ <attending list="true">
496
+ <uid>222332</uid>
497
+ <uid>222333</uid>
498
+ </attending>
499
+ <unsure list="true">
500
+ <uid>1240077</uid>
501
+ </unsure>
502
+ <declined list="true"/>
503
+ <not_replied list="true">
504
+ <uid>222335</uid>
505
+ <uid>222336</uid>
506
+ </not_replied>
507
+ </events_getMembers_response>
508
+ XML
509
+ end
510
+
511
+ def example_register_template_bundle_return_xml
512
+ <<-XML
513
+ <?xml version="1.0" encoding="UTF-8"?>
514
+ <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/">
515
+ 17876842716
516
+ </feed_registerTemplateBundle_response>
517
+ XML
518
+ end
519
+
520
+ def example_pages_xml
521
+ <<-XML
522
+ <?xml version="1.0" encoding="UTF-8"?>
523
+ <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">
524
+ <page>
525
+ <page_id>4846711747</page_id>
526
+ <name>Kronos Quartet</name>
527
+ <website>http://www.kronosquartet.org</website>
528
+ <company_overview/>
529
+ <genre>
530
+ <dance>0</dance>
531
+ <party>1</party>
532
+ </genre>
533
+ </page>
534
+ </pages_getInfo_response>
535
+ XML
536
+ end
537
+
538
+ def publish_user_action_return_xml
539
+ <<-XML
540
+ <?xml version="1.0" encoding="UTF-8"?>
541
+ <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">
542
+ <feed_publishUserAction_response_elt>1</feed_publishUserAction_response_elt>
543
+ </feed_publishUserAction_response>
544
+ XML
545
+ end
546
+
547
+ end
548
+
549
+ class CanvasSessionTest < Test::Unit::TestCase
550
+ def setup
551
+ ENV['FACEBOOK_API_KEY'] = '1234567'
552
+ ENV['FACEBOOK_SECRET_KEY'] = '7654321'
553
+ end
554
+
555
+ def test_login_url_will_display_callback_url_in_canvas
556
+ session = Facebooker::CanvasSession.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
557
+ assert_equal("http://www.facebook.com/login.php?api_key=1234567&v=1.0&canvas=true", session.login_url)
558
+ end
559
+ end