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,60 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'flexmock/test_unit'
4
+ require 'mocha'
5
+
6
+ require File.dirname(__FILE__)+'/../lib/facebooker/rails/test_helpers'
7
+
8
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
9
+
10
+ rails_root = File.join(File.dirname(__FILE__),'..','..')
11
+ if defined? RAILS_ROOT
12
+ RAILS_ROOT.replace(rails_root)
13
+ else
14
+ RAILS_ROOT = rails_root
15
+ end
16
+
17
+ require 'facebooker'
18
+
19
+ class Test::Unit::TestCase
20
+ include Facebooker::Rails::TestHelpers
21
+
22
+ private
23
+
24
+ def expect_http_posts_with_responses(*responses_xml)
25
+ mock_http = establish_session
26
+ responses_xml.each do |xml_string|
27
+ mock_http.should_receive(:post_form).and_return(xml_string).once.ordered(:posts)
28
+ end
29
+ end
30
+
31
+ def establish_session(session = @session)
32
+ mock = flexmock(Net::HTTP).should_receive(:post_form).and_return(example_auth_token_xml).once.ordered(:posts)
33
+ mock.should_receive(:post_form).and_return(example_get_session_xml).once.ordered(:posts)
34
+ session.secure!
35
+ mock
36
+ end
37
+
38
+ def example_auth_token_xml
39
+ <<-XML
40
+ <?xml version="1.0" encoding="UTF-8"?>
41
+ <auth_createToken_response xmlns="http://api.facebook.com/1.0/"
42
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
43
+ xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
44
+ 3e4a22bb2f5ed75114b0fc9995ea85f1
45
+ </auth_createToken_response>
46
+ XML
47
+ end
48
+
49
+ def example_get_session_xml
50
+ <<-XML
51
+ <?xml version="1.0" encoding="UTF-8"?>
52
+ <auth_getSession_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">
53
+ <session_key>5f34e11bfb97c762e439e6a5-8055</session_key>
54
+ <uid>8055</uid>
55
+ <expires>1173309298</expires>
56
+ <secret>ohairoflamao12345</secret>
57
+ </auth_getSession_response>
58
+ XML
59
+ end
60
+ end
@@ -0,0 +1,219 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'rubygems'
3
+ require 'flexmock/test_unit'
4
+
5
+ class UserTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @session = Facebooker::Session.create('apikey', 'secretkey')
9
+ @user = Facebooker::User.new(1234, @session)
10
+ @other_user = Facebooker::User.new(4321, @session)
11
+ ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
12
+ ENV['FACEBOOK_API_KEY'] = '1234567'
13
+ ENV['FACEBOOK_SECRET_KEY'] = '7654321'
14
+
15
+ @user.friends = [@other_user]
16
+ end
17
+
18
+ def test_can_ask_user_if_he_or_she_is_friends_with_another_user
19
+ assert(@user.friends_with?(@other_user))
20
+ end
21
+
22
+ def test_can_ask_user_if_he_or_she_is_friends_with_another_user_by_user_id
23
+ assert(@user.friends_with?(@other_user.id))
24
+ end
25
+
26
+ def test_cast_to_friend_list_id_with_nil
27
+ assert_nil @user.cast_to_friend_list_id(nil)
28
+ end
29
+ def test_cast_to_friend_list_id_with_integer
30
+ assert_equal 14,@user.cast_to_friend_list_id(14)
31
+ end
32
+ def test_cast_to_friend_list_id_with_string
33
+ @user.expects(:friend_lists).returns([Facebooker::FriendList.new(:flid=>199,:name=>"Work")])
34
+ assert_equal 199,@user.cast_to_friend_list_id("Work")
35
+ end
36
+ def test_cast_to_friend_list_id_with_friend_list
37
+ assert_equal 199,@user.cast_to_friend_list_id(Facebooker::FriendList.new(:flid=>199,:name=>"Work"))
38
+ end
39
+
40
+ def test_cast_to_friend_list_id_with_invalid_string_raises
41
+ @user.expects(:friend_lists).returns([Facebooker::FriendList.new(:flid=>1,:name=>"Not Picked")])
42
+ assert_nil @user.cast_to_friend_list_id("Something")
43
+ fail("No exception raised, Expected Facebooker::Session::InvalidFriendList")
44
+ rescue Facebooker::Session::InvalidFriendList
45
+ nil
46
+ end
47
+
48
+ def test_can_create_from_current_session
49
+ Facebooker::Session.expects(:current).returns("current")
50
+ user=Facebooker::User.new(1)
51
+ assert_equal("current",user.session)
52
+ end
53
+
54
+ def test_can_set_mobile_fbml
55
+ @user.expects(:set_profile_fbml).with(nil,"test",nil)
56
+ @user.mobile_fbml="test"
57
+ end
58
+ def test_can_set_profile_action
59
+ @user.expects(:set_profile_fbml).with(nil,nil,"test")
60
+ @user.profile_action="test"
61
+ end
62
+ def test_can_set_profile_fbml
63
+ @user.expects(:set_profile_fbml).with("test",nil,nil)
64
+ @user.profile_fbml="test"
65
+ end
66
+
67
+ def test_can_set_profile_main
68
+ @user.expects(:set_profile_fbml).with(nil,nil,nil,"test")
69
+ @user.profile_main="test"
70
+ end
71
+
72
+ def test_can_call_set_profile_fbml
73
+ @session.expects(:post).with('facebook.profile.setFBML', {:uid=>1234,:profile=>"profile",:profile_action=>"action",:mobile_profile=>"mobile"},false)
74
+ @user.set_profile_fbml("profile","mobile","action")
75
+ end
76
+
77
+ def test_can_call_set_profile_fbml_with_profile_main
78
+ @session.expects(:post).with('facebook.profile.setFBML', {:uid=>1234,:profile=>"profile",:profile_action=>"action",:mobile_profile=>"mobile", :profile_main => 'profile_main'},false)
79
+ @user.set_profile_fbml("profile","mobile","action",'profile_main')
80
+ end
81
+
82
+ def test_can_get_profile_photos
83
+ @user.expects(:profile_photos)
84
+ @user.profile_photos
85
+ end
86
+
87
+ def test_can_set_cookie
88
+ @user.expects(:set_cookie).with('name', 'value')
89
+ @user.set_cookie('name', 'value')
90
+ end
91
+
92
+ def test_can_get_cookies
93
+ @user.expects(:get_cookies).with('name')
94
+ @user.get_cookies('name')
95
+ end
96
+
97
+ def test_get_profile_photos
98
+ @user = Facebooker::User.new(548871286, @session)
99
+ expect_http_posts_with_responses(example_profile_photos_get_xml)
100
+ photos = @user.profile_photos
101
+ assert_equal "2357384227378429949", photos.first.aid
102
+ end
103
+
104
+ def test_can_send_email
105
+ @user.expects(:send_email).with("subject", "body text")
106
+ @user.send_email("subject", "body text")
107
+
108
+ @user.expects(:send_email).with("subject", nil, "body fbml")
109
+ @user.send_email("subject", nil, "body fbml")
110
+ end
111
+
112
+ def test_can_set_status_with_string
113
+ @session.expects(:post).with('facebook.users.setStatus', :status=>"my status",:status_includes_verb=>1)
114
+ @user.status="my status"
115
+ end
116
+
117
+ def test_get_events
118
+ @user = Facebooker::User.new(9507801, @session)
119
+ expect_http_posts_with_responses(example_events_get_xml)
120
+ events = @user.events
121
+ assert_equal "29511517904", events.first.eid
122
+ end
123
+
124
+ def test_can_get_events
125
+ @user.expects(:events)
126
+ @user.events
127
+ end
128
+
129
+ def test_to_s
130
+ assert_equal("1234",@user.to_s)
131
+ end
132
+
133
+ def test_equality
134
+ assert_equal @user, @user.dup
135
+ end
136
+
137
+ def test_hash_email
138
+ assert_equal "4228600737_c96da02bba97aedfd26136e980ae3761", Facebooker::User.hash_email("mary@example.com")
139
+ end
140
+ def test_hash_email_not_normalized
141
+ assert_equal "4228600737_c96da02bba97aedfd26136e980ae3761", Facebooker::User.hash_email(" MaRy@example.com ")
142
+ end
143
+
144
+ def test_register_with_array
145
+ expect_http_posts_with_responses(["4228600737_c96da02bba97aedfd26136e980ae3761"].to_json)
146
+ assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.register([{:email=>"mary@example.com",:account_id=>1}])
147
+ end
148
+
149
+ def test_failed_registration
150
+ expect_http_posts_with_responses([""].to_json)
151
+ Facebooker::User.register([{:email=>"mary@example.com",:account_id=>1}])
152
+ fail "Expected UserRegistrationFailed to be raised but it wasn't"
153
+ rescue Facebooker::Session::UserRegistrationFailed=>e
154
+ assert_equal({:email=>"mary@example.com",:account_id=>1},e.failed_users.first)
155
+ end
156
+
157
+ private
158
+ def example_profile_photos_get_xml
159
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
160
+ <photos_get_response xmlns=\"http://api.facebook.com/1.0/\"
161
+ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
162
+ xsi:schemaLocation=\"http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd\" list=\"true\">
163
+ <photo>
164
+ <pid>34585991612804</pid>
165
+ <aid>2357384227378429949</aid>
166
+ <owner>1240077</owner>
167
+ <src>http://ip002.facebook.com/v11/135/18/8055/s1240077_30043524_2020.jpg</src>
168
+ <src_big>http://ip002.facebook.com/v11/135/18/8055/n1240077_30043524_2020.jpg</src_big>
169
+ <src_small>http://ip002.facebook.com/v11/135/18/8055/t1240077_30043524_2020.jpg</src_small>
170
+ <link>http://www.facebook.com/photo.php?pid=30043524&id=8055</link>
171
+ <caption>From The Deathmatch (Trailer) (1999)</caption>
172
+ <created>1132553361</created>
173
+ </photo>
174
+ <photo>
175
+ <pid>34585991612805</pid>
176
+ <aid>2357384227378429949</aid>
177
+ <owner>1240077</owner>
178
+ <src>http://ip002.facebook.com/v11/135/18/8055/s1240077_30043525_2184.jpg</src>
179
+ <src_big>http://ip002.facebook.com/v11/135/18/8055/n1240077_30043525_2184.jpg</src_big>
180
+ <src_small>http://ip002.facebook.com/v11/135/18/8055/t1240077_30043525_2184.jpg</src_small>
181
+ <link>http://www.facebook.com/photo.php?pid=30043525&id=8055</link>
182
+ <caption>Mexico City, back cover of the CYHS Student Underground 1999.</caption>
183
+ <created>1132553362</created>
184
+ </photo>
185
+ </photos_get_response>"
186
+ end
187
+
188
+ def example_events_get_xml
189
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
190
+ <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\">
191
+ <event>
192
+ <eid>29511517904</eid>
193
+ <name>PUMA SALE</name>
194
+ <tagline/>
195
+ <nid>0</nid>
196
+ <pic>http://profile.ak.facebook.com/object3/370/66/s29511517904_6952.jpg</pic>
197
+ <pic_big>http://profile.ak.facebook.com/object3/370/66/n29511517904_6952.jpg</pic_big>
198
+ <pic_small>http://profile.ak.facebook.com/object3/370/66/t29511517904_6952.jpg</pic_small>
199
+ <host>PUMA</host>
200
+ <description>PUMA SALE</description>
201
+ <event_type>Education</event_type>
202
+ <event_subtype>Study Group</event_subtype>
203
+ <start_time>1212166800</start_time>
204
+ <end_time>1212364800</end_time>
205
+ <creator>1234261165</creator>
206
+ <update_time>1209768148</update_time>
207
+ <location>PUMA LOT</location>
208
+ <venue>
209
+ <street>5 LYBERTY WAY</street>
210
+ <city>Westford</city>
211
+ <state>Massachusetts</state>
212
+ <country>United States</country>
213
+ <latitude>42.5792</latitude>
214
+ <longitude>-71.4383</longitude>
215
+ </venue>
216
+ </event>
217
+ </events_get_response>"
218
+ end
219
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yury-facebooker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.5
5
+ platform: ruby
6
+ authors:
7
+ - Chad Fowler
8
+ - Patrick Ewing
9
+ - Mike Mangino
10
+ - Shane Vitarana
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2008-02-13 00:00:00 -08:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: hoe
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.5.0
26
+ version:
27
+ description: "== DESCRIPTION: Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://developer.facebook.com]. Its goals are: * Idiomatic Ruby * No dependencies outside of the Ruby standard library * Concrete classes and methods modeling the Facebook data, so it's easy for a Rubyist to understand what's available * Well tested == FEATURES/PROBLEMS:"
28
+ email: mmangino@elevatedrails.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - CHANGELOG.txt
35
+ - History.txt
36
+ - Manifest.txt
37
+ - README.txt
38
+ - TODO.txt
39
+ - test/fixtures/multipart_post_body_with_only_parameters.txt
40
+ - test/fixtures/multipart_post_body_with_single_file.txt
41
+ - test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt
42
+ files:
43
+ - CHANGELOG.txt
44
+ - COPYING
45
+ - History.txt
46
+ - Manifest.txt
47
+ - README
48
+ - README.txt
49
+ - Rakefile
50
+ - TODO.txt
51
+ - facebooker.yml.tpl
52
+ - init.rb
53
+ - install.rb
54
+ - lib/facebooker.rb
55
+ - lib/facebooker/affiliation.rb
56
+ - lib/facebooker/album.rb
57
+ - lib/facebooker/cookie.rb
58
+ - lib/facebooker/data.rb
59
+ - lib/facebooker/education_info.rb
60
+ - lib/facebooker/event.rb
61
+ - lib/facebooker/feed.rb
62
+ - lib/facebooker/group.rb
63
+ - lib/facebooker/location.rb
64
+ - lib/facebooker/model.rb
65
+ - lib/facebooker/notifications.rb
66
+ - lib/facebooker/parser.rb
67
+ - lib/facebooker/photo.rb
68
+ - lib/facebooker/rails/controller.rb
69
+ - lib/facebooker/rails/facebook_asset_path.rb
70
+ - lib/facebooker/rails/facebook_form_builder.rb
71
+ - lib/facebooker/rails/facebook_request_fix.rb
72
+ - lib/facebooker/rails/facebook_session_handling.rb
73
+ - lib/facebooker/rails/facebook_url_rewriting.rb
74
+ - lib/facebooker/rails/helpers.rb
75
+ - lib/facebooker/rails/routing.rb
76
+ - lib/facebooker/rails/test_helpers.rb
77
+ - lib/facebooker/rails/utilities.rb
78
+ - lib/facebooker/server_cache.rb
79
+ - lib/facebooker/service.rb
80
+ - lib/facebooker/session.rb
81
+ - lib/facebooker/tag.rb
82
+ - lib/facebooker/user.rb
83
+ - lib/facebooker/version.rb
84
+ - lib/facebooker/work_info.rb
85
+ - lib/net/http_multipart_post.rb
86
+ - lib/tasks/facebooker.rake
87
+ - lib/tasks/tunnel.rake
88
+ - setup.rb
89
+ - test/event_test.rb
90
+ - test/facebook_cache_test.rb
91
+ - test/facebook_data_test.rb
92
+ - test/facebooker_test.rb
93
+ - test/fixtures/multipart_post_body_with_only_parameters.txt
94
+ - test/fixtures/multipart_post_body_with_single_file.txt
95
+ - test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt
96
+ - test/http_multipart_post_test.rb
97
+ - test/model_test.rb
98
+ - test/rails_integration_test.rb
99
+ - test/session_test.rb
100
+ - test/test_helper.rb
101
+ - test/user_test.rb
102
+ has_rdoc: true
103
+ homepage:
104
+ post_install_message:
105
+ rdoc_options:
106
+ - --main
107
+ - README.txt
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: "0"
115
+ version:
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: "0"
121
+ version:
122
+ requirements: []
123
+
124
+ rubyforge_project: facebooker
125
+ rubygems_version: 1.2.0
126
+ signing_key:
127
+ specification_version: 2
128
+ summary: Pure, idiomatic Ruby wrapper for the Facebook REST API.
129
+ test_files:
130
+ - test/test_helper.rb