netshade-facebooker 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/CHANGELOG.txt +0 -0
  2. data/COPYING +19 -0
  3. data/History.txt +16 -0
  4. data/Manifest.txt +110 -0
  5. data/README +46 -0
  6. data/README.txt +81 -0
  7. data/Rakefile +76 -0
  8. data/TODO.txt +10 -0
  9. data/generators/facebook/facebook_generator.rb +14 -0
  10. data/generators/facebook/templates/config/facebooker.yml +41 -0
  11. data/generators/facebook/templates/public/javascripts/facebooker.js +106 -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/init.rb +70 -0
  41. data/install.rb +12 -0
  42. data/lib/facebooker.rb +143 -0
  43. data/lib/facebooker/adapters/adapter_base.rb +87 -0
  44. data/lib/facebooker/adapters/bebo_adapter.rb +75 -0
  45. data/lib/facebooker/adapters/facebook_adapter.rb +48 -0
  46. data/lib/facebooker/admin.rb +28 -0
  47. data/lib/facebooker/batch_request.rb +44 -0
  48. data/lib/facebooker/data.rb +57 -0
  49. data/lib/facebooker/feed.rb +78 -0
  50. data/lib/facebooker/logging.rb +51 -0
  51. data/lib/facebooker/model.rb +123 -0
  52. data/lib/facebooker/models/affiliation.rb +10 -0
  53. data/lib/facebooker/models/album.rb +11 -0
  54. data/lib/facebooker/models/applicationproperties.rb +39 -0
  55. data/lib/facebooker/models/cookie.rb +10 -0
  56. data/lib/facebooker/models/education_info.rb +11 -0
  57. data/lib/facebooker/models/event.rb +26 -0
  58. data/lib/facebooker/models/friend_list.rb +14 -0
  59. data/lib/facebooker/models/group.rb +35 -0
  60. data/lib/facebooker/models/info_item.rb +10 -0
  61. data/lib/facebooker/models/info_section.rb +10 -0
  62. data/lib/facebooker/models/location.rb +8 -0
  63. data/lib/facebooker/models/notifications.rb +17 -0
  64. data/lib/facebooker/models/page.rb +27 -0
  65. data/lib/facebooker/models/photo.rb +10 -0
  66. data/lib/facebooker/models/tag.rb +12 -0
  67. data/lib/facebooker/models/user.rb +367 -0
  68. data/lib/facebooker/models/work_info.rb +9 -0
  69. data/lib/facebooker/parser.rb +547 -0
  70. data/lib/facebooker/rails/controller.rb +246 -0
  71. data/lib/facebooker/rails/facebook_asset_path.rb +18 -0
  72. data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
  73. data/lib/facebooker/rails/facebook_pretty_errors.rb +14 -0
  74. data/lib/facebooker/rails/facebook_request_fix.rb +24 -0
  75. data/lib/facebooker/rails/facebook_session_handling.rb +69 -0
  76. data/lib/facebooker/rails/facebook_url_rewriting.rb +39 -0
  77. data/lib/facebooker/rails/helpers.rb +615 -0
  78. data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
  79. data/lib/facebooker/rails/publisher.rb +507 -0
  80. data/lib/facebooker/rails/routing.rb +49 -0
  81. data/lib/facebooker/rails/test_helpers.rb +88 -0
  82. data/lib/facebooker/rails/utilities.rb +22 -0
  83. data/lib/facebooker/server_cache.rb +24 -0
  84. data/lib/facebooker/service.rb +31 -0
  85. data/lib/facebooker/session.rb +564 -0
  86. data/lib/facebooker/version.rb +9 -0
  87. data/lib/net/http_multipart_post.rb +123 -0
  88. data/lib/tasks/facebooker.rake +18 -0
  89. data/lib/tasks/tunnel.rake +46 -0
  90. data/rails/init.rb +1 -0
  91. data/setup.rb +1585 -0
  92. data/templates/layout.erb +24 -0
  93. data/test/adapters_test.rb +98 -0
  94. data/test/batch_request_test.rb +82 -0
  95. data/test/event_test.rb +15 -0
  96. data/test/facebook_admin_test.rb +75 -0
  97. data/test/facebook_cache_test.rb +43 -0
  98. data/test/facebook_data_test.rb +84 -0
  99. data/test/facebooker_test.rb +855 -0
  100. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  101. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  102. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  103. data/test/http_multipart_post_test.rb +54 -0
  104. data/test/logging_test.rb +43 -0
  105. data/test/model_test.rb +91 -0
  106. data/test/publisher_test.rb +457 -0
  107. data/test/rails_integration_test.rb +1126 -0
  108. data/test/session_test.rb +587 -0
  109. data/test/test_helper.rb +60 -0
  110. data/test/user_test.rb +270 -0
  111. metadata +181 -0
@@ -0,0 +1,587 @@
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
+ def test_can_register_template_bundle_with_action_links
190
+ expect_http_posts_with_responses(example_register_template_bundle_return_xml)
191
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
192
+ assert_equal 17876842716, @session.register_template_bundle("{*actor*} did something",nil,nil,[{:text=>"text",:href=>"href"}])
193
+ end
194
+ def test_can_publish_user_action
195
+ expect_http_posts_with_responses(publish_user_action_return_xml)
196
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
197
+ assert @session.publish_user_action(17876842716,{})
198
+ end
199
+
200
+ def test_logs_api_calls
201
+ call_name = 'sample.api.call'
202
+ params = { :param1 => true, :param2 => 'value' }
203
+ flexmock(Facebooker::Logging, :Logging).should_receive(:log_fb_api).once.with(
204
+ call_name, params, Proc)
205
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
206
+ @session.post(call_name, params)
207
+ end
208
+
209
+ def test_requests_inside_batch_are_added_to_batch
210
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
211
+ @session.send(:service).expects(:post).once
212
+ @session.batch do
213
+ @session.send_notification(["1"],"a")
214
+ @session.send_notification(["1"],"a")
215
+ end
216
+
217
+ end
218
+
219
+ def test_parses_batch_response
220
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
221
+ expect_http_posts_with_responses(example_batch_run_xml)
222
+ @session.batch do
223
+ @fql_response = @session.fql_query('SELECT name, pic FROM user WHERE uid=211031 OR uid=4801660')
224
+ end
225
+ assert_kind_of(Facebooker::Event::Attendance, @fql_response.first)
226
+ assert_equal('attending', @fql_response.first.rsvp_status)
227
+ end
228
+ def test_parses_batch_response_sets_exception
229
+ @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
230
+ expect_http_posts_with_responses(example_batch_run_xml)
231
+ Facebooker::FqlQuery.expects(:process).raises(NoMethodError.new)
232
+
233
+ @session.batch do
234
+ @fql_response = @session.fql_query('SELECT name, pic FROM user WHERE uid=211031 OR uid=4801660')
235
+ end
236
+ assert_raises(NoMethodError) {
237
+ @fql_response.first
238
+ }
239
+ end
240
+
241
+ def test_can_set_and_get_current_batch
242
+ Facebooker::BatchRun.current_batch=4
243
+ assert_equal 4,Facebooker::BatchRun.current_batch
244
+ end
245
+
246
+ def test_can_get_stanard_info
247
+ expect_http_posts_with_responses(standard_info_xml)
248
+ result = @session.users_standard([4])
249
+ assert_equal "Mike Mangino",result.first.name
250
+ end
251
+
252
+ def test_can_query_for_pages
253
+ expect_http_posts_with_responses(example_pages_xml)
254
+ example_page = Facebooker::Page.new(
255
+ :page_id => 4846711747,
256
+ :name => "Kronos Quartet",
257
+ :website => "http://www.kronosquartet.org",
258
+ :company_overview => "",
259
+ :session => @session)
260
+ pages = @session.pages(:fields => %w[ page_id name website company_overview ])
261
+
262
+ assert_equal 1, pages.size
263
+
264
+ page = pages.first
265
+ assert_equal "4846711747", page.page_id
266
+ assert_equal "Kronos Quartet", page.name
267
+ assert_equal "http://www.kronosquartet.org", page.website
268
+
269
+ # TODO we really need a way to differentiate between hash/list and text attributes
270
+ # assert_equal({}, page.company_overview)
271
+
272
+ # sakkaoui : as a fix to the parser, I replace empty text node by "" instead of {}
273
+ # we have child.attributes['list'] == 'true' that let us know that we have a hash/list.
274
+ assert_equal("", page.company_overview)
275
+
276
+ genre = page.genre
277
+ assert_equal false, genre.dance
278
+ assert_equal true, genre.party
279
+ end
280
+
281
+ private
282
+
283
+ def example_groups_get_xml
284
+ <<-XML
285
+ <?xml version="1.0" encoding="UTF-8"?>
286
+ <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">
287
+ <group>
288
+ <gid>2206609142</gid>
289
+ <name>Donald Knuth Is My Homeboy</name>
290
+ <nid>0</nid>
291
+ <description>Donald Ervin Knuth (born January 10, 1938) is a renowned computer scientist and professor emeritus at Stanford University.
292
+
293
+ 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.
294
+
295
+ That's how he ROLLS, y0.</description>
296
+ <group_type>Just for Fun</group_type>
297
+ <group_subtype>Fan Clubs</group_subtype>
298
+ <recent_news/>
299
+ <pic>http://photos-142.facebook.com/ip006/object/543/95/s2206609142_32530.jpg</pic>
300
+ <pic_big>http://photos-142.facebook.com/ip006/object/543/95/n2206609142_32530.jpg</pic_big>
301
+ <pic_small>http://photos-142.facebook.com/ip006/object/543/95/t2206609142_32530.jpg</pic_small>
302
+ <creator>1240077</creator>
303
+ <update_time>1156543965</update_time>
304
+ <office/>
305
+ <website/>
306
+ <venue>
307
+ <street/>
308
+ <city/>
309
+ <state>CA</state>
310
+ <country>United States</country>
311
+ </venue>
312
+ </group>
313
+ </groups_get_response>
314
+ XML
315
+ end
316
+
317
+ def example_events_get_xml
318
+ <<-XML
319
+ <?xml version="1.0" encoding="UTF-8"?>
320
+ <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">
321
+ <event>
322
+ <eid>1037629024</eid>
323
+ <name>Technology Tasting</name>
324
+ <tagline>Who said Engineering can't be delicious?</tagline>
325
+ <nid>12409987</nid>
326
+ <pic>http://photos-628.facebook.com/ip006/object/1345/48/s1037629024_30775.jpg</pic>
327
+ <pic_big>http://photos-628.facebook.com/ip006/object/1345/48/n1037629024_30775.jpg</pic_big>
328
+ <pic_small>http://photos-628.facebook.com/ip006/object/1345/48/t1037629024_30775.jpg</pic_small>
329
+ <host>Facebook</host>
330
+ <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>
331
+ <event_type>Party</event_type>
332
+ <event_subtype>Cocktail Party</event_subtype>
333
+ <start_time>1172107800</start_time>
334
+ <end_time>1172115000</end_time>
335
+ <creator>1078</creator>
336
+ <update_time>1170096157</update_time>
337
+ <location>Facebook's New Office</location>
338
+ <venue>
339
+ <city>Palo Alto</city>
340
+ <state>CA</state>
341
+ <country>United States</country>
342
+ </venue>
343
+ </event>
344
+ </events_get_response>
345
+ XML
346
+ end
347
+
348
+ def example_fql_query_event_members_xml
349
+ <<-XML
350
+ <?xml version="1.0" encoding="UTF-8"?>
351
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
352
+ <event_member>
353
+ <uid>517961878</uid>
354
+ <eid>2454827764</eid>
355
+ <rsvp_status>attending</rsvp_status>
356
+ </event_member>
357
+ <event_member>
358
+ <uid>744961110</uid>
359
+ <eid>2454827764</eid>
360
+ <rsvp_status>declined</rsvp_status>
361
+ </event_member>
362
+ </fql_query_response>
363
+ XML
364
+ end
365
+ def example_check_friendship_xml
366
+ <<-XML
367
+ <?xml version="1.0" encoding="UTF-8"?>
368
+ <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">
369
+ <friend_info>
370
+ <uid1>222332</uid1>
371
+ <uid2>222333</uid2>
372
+ <are_friends>1</are_friends>
373
+ </friend_info>
374
+ <friend_info>
375
+ <uid1>1240077</uid1>
376
+ <uid2>1240079</uid2>
377
+ <are_friends>0</are_friends>
378
+ </friend_info>
379
+ </friends_areFriends_response>
380
+ XML
381
+ end
382
+
383
+ def example_check_friendship_with_unknown_result
384
+ <<-XML
385
+ <?xml version="1.0" encoding="UTF-8"?>
386
+ <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">
387
+ <friend_info>
388
+ <uid1>1240077</uid1>
389
+ <uid2>1240079</uid2>
390
+ <are_friends xsi:nil="true"/>
391
+ </friend_info>
392
+ </friends_areFriends_response>
393
+ XML
394
+ end
395
+
396
+ def example_fql_for_multiple_users_and_pics
397
+ <<-XML
398
+ <?xml version="1.0" encoding="UTF-8"?>
399
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
400
+ <user>
401
+ <name>Ari Steinberg</name>
402
+ <pic>http://profile.ak.facebook.com/profile2/1805/47/s211031_26434.jpg</pic>
403
+ </user>
404
+ <user>
405
+ <name>Ruchi Sanghvi</name>
406
+ <pic>http://profile.ak.facebook.com/v52/870/125/s4801660_2498.jpg</pic>
407
+ </user>
408
+ </fql_query_response>
409
+ XML
410
+ end
411
+
412
+ def example_fql_for_multiple_photos_xml
413
+ <<-XML
414
+ <?xml version="1.0" encoding="UTF-8"?>
415
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
416
+ <photo>
417
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v108/212/118/22700225/s22700225_30345986_2713.jpg</src>
418
+ <caption>Nottttt. get ready for some museumz</caption>
419
+ <caption>Nottttt. get ready for some museumz</caption>
420
+ </photo>
421
+ <photo>
422
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v77/74/112/22701786/s22701786_30324934_7816.jpg</src>
423
+ <caption>Rooftop barbecues make me act funny</caption>
424
+ <caption>Rooftop barbecues make me act funny</caption>
425
+ </photo>
426
+ <photo>
427
+ <src>http://photos-c.ak.facebook.com/photos-ak-sctm/v96/154/56/22700188/s22700188_30321538_17.jpg</src>
428
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
429
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
430
+ </photo>
431
+ </fql_query_response>
432
+ XML
433
+ end
434
+
435
+ def example_fql_for_multiple_photos_with_anon_xml
436
+ <<-XML
437
+ <?xml version="1.0" encoding="UTF-8"?>
438
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
439
+ <photo>
440
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v108/212/118/22700225/s22700225_30345986_2713.jpg</src>
441
+ <caption>Nottttt. get ready for some museumz</caption>
442
+ <caption>Nottttt. get ready for some museumz</caption>
443
+ <anon>first</anon>
444
+ <anon>second</anon>
445
+ </photo>
446
+ <photo>
447
+ <src>http://photos-c.ak.facebook.com/photos-ak-sf2p/v77/74/112/22701786/s22701786_30324934_7816.jpg</src>
448
+ <caption>Rooftop barbecues make me act funny</caption>
449
+ <caption>Rooftop barbecues make me act funny</caption>
450
+ <anon>first</anon>
451
+ <anon>second</anon>
452
+ </photo>
453
+ <photo>
454
+ <src>http://photos-c.ak.facebook.com/photos-ak-sctm/v96/154/56/22700188/s22700188_30321538_17.jpg</src>
455
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
456
+ <caption>An epic shot of Patrick getting ready for a run to second.</caption>
457
+ <anon>first</anon>
458
+ <anon>second</anon>
459
+ </photo>
460
+ </fql_query_response>
461
+ XML
462
+ end
463
+
464
+ def no_results_fql
465
+ <<-XML
466
+ <?xml version="1.0" encoding="UTF-8"?>
467
+ <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
468
+ </fql_query_response>
469
+ XML
470
+
471
+ end
472
+
473
+ def example_group_members_xml
474
+ <<-XML
475
+ <?xml version="1.0" encoding="UTF-8"?>
476
+ <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">
477
+ <members list="true">
478
+ <uid>1240077</uid>
479
+ <uid>1240078</uid>
480
+ <uid>222332</uid>
481
+ <uid>222333</uid>
482
+ </members>
483
+ <admins list="true">
484
+ <uid>1240077</uid>
485
+ <uid>222333</uid>
486
+ </admins>
487
+ <officers list="true">
488
+ <uid>1240078</uid>
489
+ </officers>
490
+ <not_replied list="true"/>
491
+ </groups_getMembers_response>
492
+ XML
493
+ end
494
+
495
+ def example_batch_run_xml
496
+ <<-XML
497
+ <?xml version="1.0" encoding="UTF-8"?>
498
+ <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">
499
+ <batch_run_response_elt>
500
+ #{CGI.escapeHTML(example_fql_query_event_members_xml)}
501
+ </batch_run_response_elt>
502
+ </batch_run_response>
503
+ XML
504
+ end
505
+
506
+ def example_event_members_xml
507
+ <<-XML
508
+ <?xml version="1.0" encoding="UTF-8"?>
509
+ <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">
510
+ <attending list="true">
511
+ <uid>222332</uid>
512
+ <uid>222333</uid>
513
+ </attending>
514
+ <unsure list="true">
515
+ <uid>1240077</uid>
516
+ </unsure>
517
+ <declined list="true"/>
518
+ <not_replied list="true">
519
+ <uid>222335</uid>
520
+ <uid>222336</uid>
521
+ </not_replied>
522
+ </events_getMembers_response>
523
+ XML
524
+ end
525
+
526
+ def example_register_template_bundle_return_xml
527
+ <<-XML
528
+ <?xml version="1.0" encoding="UTF-8"?>
529
+ <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/">
530
+ 17876842716
531
+ </feed_registerTemplateBundle_response>
532
+ XML
533
+ end
534
+
535
+ def example_pages_xml
536
+ <<-XML
537
+ <?xml version="1.0" encoding="UTF-8"?>
538
+ <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">
539
+ <page>
540
+ <page_id>4846711747</page_id>
541
+ <name>Kronos Quartet</name>
542
+ <website>http://www.kronosquartet.org</website>
543
+ <company_overview/>
544
+ <genre>
545
+ <dance>0</dance>
546
+ <party>1</party>
547
+ </genre>
548
+ </page>
549
+ </pages_getInfo_response>
550
+ XML
551
+ end
552
+
553
+ def publish_user_action_return_xml
554
+ <<-XML
555
+ <?xml version="1.0" encoding="UTF-8"?>
556
+ <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">
557
+ <feed_publishUserAction_response_elt>1</feed_publishUserAction_response_elt>
558
+ </feed_publishUserAction_response>
559
+ XML
560
+ end
561
+
562
+ def standard_info_xml
563
+ <<-XML
564
+ <?xml version="1.0" encoding="UTF-8"?>
565
+ <?xml version="1.0" encoding="UTF-8"?>
566
+
567
+ <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">
568
+ <standard_user_info>
569
+ <uid>12451752</uid>
570
+ <name>Mike Mangino</name>
571
+ </standard_user_info>
572
+ </users_getStandardInfo_response>
573
+ XML
574
+ end
575
+ end
576
+
577
+ class CanvasSessionTest < Test::Unit::TestCase
578
+ def setup
579
+ ENV['FACEBOOK_API_KEY'] = '1234567'
580
+ ENV['FACEBOOK_SECRET_KEY'] = '7654321'
581
+ end
582
+
583
+ def test_login_url_will_display_callback_url_in_canvas
584
+ session = Facebooker::CanvasSession.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
585
+ assert_equal("http://www.facebook.com/login.php?api_key=1234567&v=1.0&canvas=true", session.login_url)
586
+ end
587
+ end