cwninja-facebooker 1.0.8

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