twitter 4.0.0

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 (210) hide show
  1. data/CHANGELOG.md +673 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +415 -0
  4. data/Rakefile +11 -0
  5. data/lib/twitter.rb +29 -0
  6. data/lib/twitter/action/favorite.rb +19 -0
  7. data/lib/twitter/action/follow.rb +31 -0
  8. data/lib/twitter/action/list_member_added.rb +41 -0
  9. data/lib/twitter/action/mention.rb +48 -0
  10. data/lib/twitter/action/reply.rb +27 -0
  11. data/lib/twitter/action/retweet.rb +27 -0
  12. data/lib/twitter/action/tweet.rb +22 -0
  13. data/lib/twitter/action_factory.rb +22 -0
  14. data/lib/twitter/api.rb +2442 -0
  15. data/lib/twitter/base.rb +119 -0
  16. data/lib/twitter/basic_user.rb +8 -0
  17. data/lib/twitter/client.rb +96 -0
  18. data/lib/twitter/configurable.rb +67 -0
  19. data/lib/twitter/configuration.rb +20 -0
  20. data/lib/twitter/core_ext/array.rb +7 -0
  21. data/lib/twitter/core_ext/enumerable.rb +11 -0
  22. data/lib/twitter/core_ext/hash.rb +100 -0
  23. data/lib/twitter/core_ext/kernel.rb +15 -0
  24. data/lib/twitter/core_ext/string.rb +10 -0
  25. data/lib/twitter/creatable.rb +20 -0
  26. data/lib/twitter/cursor.rb +87 -0
  27. data/lib/twitter/default.rb +101 -0
  28. data/lib/twitter/direct_message.rb +21 -0
  29. data/lib/twitter/entity.rb +7 -0
  30. data/lib/twitter/entity/hashtag.rb +9 -0
  31. data/lib/twitter/entity/url.rb +9 -0
  32. data/lib/twitter/entity/user_mention.rb +9 -0
  33. data/lib/twitter/error.rb +34 -0
  34. data/lib/twitter/error/bad_gateway.rb +11 -0
  35. data/lib/twitter/error/bad_request.rb +10 -0
  36. data/lib/twitter/error/client_error.rb +35 -0
  37. data/lib/twitter/error/decode_error.rb +9 -0
  38. data/lib/twitter/error/forbidden.rb +10 -0
  39. data/lib/twitter/error/gateway_timeout.rb +11 -0
  40. data/lib/twitter/error/identity_map_key_error.rb +9 -0
  41. data/lib/twitter/error/internal_server_error.rb +11 -0
  42. data/lib/twitter/error/not_acceptable.rb +10 -0
  43. data/lib/twitter/error/not_found.rb +10 -0
  44. data/lib/twitter/error/rate_limited.rb +11 -0
  45. data/lib/twitter/error/server_error.rb +28 -0
  46. data/lib/twitter/error/service_unavailable.rb +11 -0
  47. data/lib/twitter/error/unauthorized.rb +10 -0
  48. data/lib/twitter/factory.rb +21 -0
  49. data/lib/twitter/geo.rb +15 -0
  50. data/lib/twitter/geo/point.rb +22 -0
  51. data/lib/twitter/geo/polygon.rb +8 -0
  52. data/lib/twitter/geo_factory.rb +18 -0
  53. data/lib/twitter/identity.rb +50 -0
  54. data/lib/twitter/identity_map.rb +22 -0
  55. data/lib/twitter/language.rb +7 -0
  56. data/lib/twitter/list.rb +18 -0
  57. data/lib/twitter/media/photo.rb +22 -0
  58. data/lib/twitter/media_factory.rb +17 -0
  59. data/lib/twitter/metadata.rb +7 -0
  60. data/lib/twitter/oembed.rb +8 -0
  61. data/lib/twitter/place.rb +34 -0
  62. data/lib/twitter/rate_limit.rb +45 -0
  63. data/lib/twitter/relationship.rb +36 -0
  64. data/lib/twitter/request/multipart_with_file.rb +41 -0
  65. data/lib/twitter/response/parse_json.rb +25 -0
  66. data/lib/twitter/response/raise_error.rb +30 -0
  67. data/lib/twitter/saved_search.rb +9 -0
  68. data/lib/twitter/search_results.rb +48 -0
  69. data/lib/twitter/settings.rb +17 -0
  70. data/lib/twitter/size.rb +24 -0
  71. data/lib/twitter/source_user.rb +15 -0
  72. data/lib/twitter/suggestion.rb +22 -0
  73. data/lib/twitter/target_user.rb +8 -0
  74. data/lib/twitter/trend.rb +14 -0
  75. data/lib/twitter/tweet.rb +145 -0
  76. data/lib/twitter/user.rb +97 -0
  77. data/lib/twitter/version.rb +18 -0
  78. data/spec/fixtures/about_me.json +1 -0
  79. data/spec/fixtures/activity_summary.json +1 -0
  80. data/spec/fixtures/all.json +1 -0
  81. data/spec/fixtures/bad_gateway.json +1 -0
  82. data/spec/fixtures/bad_request.json +1 -0
  83. data/spec/fixtures/by_friends.json +1 -0
  84. data/spec/fixtures/category.json +1 -0
  85. data/spec/fixtures/configuration.json +1 -0
  86. data/spec/fixtures/contributees.json +1 -0
  87. data/spec/fixtures/contributors.json +1 -0
  88. data/spec/fixtures/direct_message.json +1 -0
  89. data/spec/fixtures/direct_messages.json +1 -0
  90. data/spec/fixtures/end_session.json +1 -0
  91. data/spec/fixtures/enhance_your_calm.text +11 -0
  92. data/spec/fixtures/favorites.json +1 -0
  93. data/spec/fixtures/following.json +1 -0
  94. data/spec/fixtures/forbidden.json +1 -0
  95. data/spec/fixtures/friendships.json +1 -0
  96. data/spec/fixtures/ids.json +1 -0
  97. data/spec/fixtures/ids_list.json +1 -0
  98. data/spec/fixtures/ids_list2.json +1 -0
  99. data/spec/fixtures/image_facets.json +1 -0
  100. data/spec/fixtures/internal_server_error.json +1 -0
  101. data/spec/fixtures/languages.json +1 -0
  102. data/spec/fixtures/list.json +1 -0
  103. data/spec/fixtures/lists.json +1 -0
  104. data/spec/fixtures/locations.json +1 -0
  105. data/spec/fixtures/matching_trends.json +1 -0
  106. data/spec/fixtures/me.jpeg +0 -0
  107. data/spec/fixtures/media_timeline.json +1 -0
  108. data/spec/fixtures/members.json +1 -0
  109. data/spec/fixtures/no_user_matches.json +1 -0
  110. data/spec/fixtures/not_acceptable.json +1 -0
  111. data/spec/fixtures/not_following.json +1 -0
  112. data/spec/fixtures/not_found.json +1 -0
  113. data/spec/fixtures/oembed.json +1 -0
  114. data/spec/fixtures/pbjt.gif +0 -0
  115. data/spec/fixtures/pengwynn.json +1 -0
  116. data/spec/fixtures/phoenix_search.phoenix +1 -0
  117. data/spec/fixtures/place.json +1 -0
  118. data/spec/fixtures/places.json +1 -0
  119. data/spec/fixtures/privacy.json +1 -0
  120. data/spec/fixtures/profile_image.text +24 -0
  121. data/spec/fixtures/rate_limit_status.json +1 -0
  122. data/spec/fixtures/recommendations.json +1 -0
  123. data/spec/fixtures/related_results.json +1 -0
  124. data/spec/fixtures/resolve.json +1 -0
  125. data/spec/fixtures/retweet.json +1 -0
  126. data/spec/fixtures/retweeted_status.json +1 -0
  127. data/spec/fixtures/retweeters_of.json +1 -0
  128. data/spec/fixtures/retweets.json +1 -0
  129. data/spec/fixtures/saved_search.json +1 -0
  130. data/spec/fixtures/saved_searches.json +1 -0
  131. data/spec/fixtures/search.json +1 -0
  132. data/spec/fixtures/search_malformed.json +1 -0
  133. data/spec/fixtures/service_unavailable.json +1 -0
  134. data/spec/fixtures/settings.json +1 -0
  135. data/spec/fixtures/sferik.json +1 -0
  136. data/spec/fixtures/status.json +1 -0
  137. data/spec/fixtures/status_with_media.json +104 -0
  138. data/spec/fixtures/statuses.json +1 -0
  139. data/spec/fixtures/suggestions.json +1 -0
  140. data/spec/fixtures/tos.json +1 -0
  141. data/spec/fixtures/totals.json +1 -0
  142. data/spec/fixtures/trends.json +1 -0
  143. data/spec/fixtures/trends_current.json +1 -0
  144. data/spec/fixtures/trends_daily.json +1 -0
  145. data/spec/fixtures/trends_weekly.json +1 -0
  146. data/spec/fixtures/unauthorized.json +1 -0
  147. data/spec/fixtures/user_search.json +1 -0
  148. data/spec/fixtures/user_timeline.json +1 -0
  149. data/spec/fixtures/users.json +1 -0
  150. data/spec/fixtures/users_list.json +1 -0
  151. data/spec/fixtures/video_facets.json +1 -0
  152. data/spec/fixtures/we_concept_bg2.png +0 -0
  153. data/spec/fixtures/wildcomet2.jpe +0 -0
  154. data/spec/helper.rb +53 -0
  155. data/spec/twitter/action/favorite_spec.rb +29 -0
  156. data/spec/twitter/action/follow_spec.rb +29 -0
  157. data/spec/twitter/action/list_member_added_spec.rb +41 -0
  158. data/spec/twitter/action/mention_spec.rb +52 -0
  159. data/spec/twitter/action/reply_spec.rb +41 -0
  160. data/spec/twitter/action/retweet_spec.rb +41 -0
  161. data/spec/twitter/action_factory_spec.rb +37 -0
  162. data/spec/twitter/action_spec.rb +16 -0
  163. data/spec/twitter/api/account_spec.rb +148 -0
  164. data/spec/twitter/api/activity_spec.rb +41 -0
  165. data/spec/twitter/api/blocks_spec.rb +167 -0
  166. data/spec/twitter/api/direct_messages_spec.rb +142 -0
  167. data/spec/twitter/api/friendships_spec.rb +567 -0
  168. data/spec/twitter/api/geo_spec.rb +100 -0
  169. data/spec/twitter/api/help_spec.rb +76 -0
  170. data/spec/twitter/api/lists_spec.rb +900 -0
  171. data/spec/twitter/api/report_spam_spec.rb +29 -0
  172. data/spec/twitter/api/saved_searches_spec.rb +100 -0
  173. data/spec/twitter/api/search_spec.rb +68 -0
  174. data/spec/twitter/api/statuses_spec.rb +559 -0
  175. data/spec/twitter/api/trends_spec.rb +80 -0
  176. data/spec/twitter/api/users_spec.rb +419 -0
  177. data/spec/twitter/base_spec.rb +113 -0
  178. data/spec/twitter/basic_user_spec.rb +23 -0
  179. data/spec/twitter/client_spec.rb +175 -0
  180. data/spec/twitter/configuration_spec.rb +17 -0
  181. data/spec/twitter/cursor_spec.rb +102 -0
  182. data/spec/twitter/direct_message_spec.rb +56 -0
  183. data/spec/twitter/error/client_error_spec.rb +40 -0
  184. data/spec/twitter/error/server_error_spec.rb +24 -0
  185. data/spec/twitter/error_spec.rb +20 -0
  186. data/spec/twitter/geo/point_spec.rb +41 -0
  187. data/spec/twitter/geo/polygon_spec.rb +29 -0
  188. data/spec/twitter/geo_factory_spec.rb +21 -0
  189. data/spec/twitter/geo_spec.rb +29 -0
  190. data/spec/twitter/identifiable_spec.rb +54 -0
  191. data/spec/twitter/list_spec.rb +45 -0
  192. data/spec/twitter/media/photo_spec.rb +35 -0
  193. data/spec/twitter/media_factory_spec.rb +17 -0
  194. data/spec/twitter/oembed_spec.rb +146 -0
  195. data/spec/twitter/place_spec.rb +75 -0
  196. data/spec/twitter/rate_limit_spec.rb +76 -0
  197. data/spec/twitter/relationship_spec.rb +35 -0
  198. data/spec/twitter/saved_search_spec.rb +34 -0
  199. data/spec/twitter/search_results_spec.rb +89 -0
  200. data/spec/twitter/settings_spec.rb +16 -0
  201. data/spec/twitter/size_spec.rb +38 -0
  202. data/spec/twitter/source_user_spec.rb +23 -0
  203. data/spec/twitter/suggestion_spec.rb +50 -0
  204. data/spec/twitter/target_user_spec.rb +23 -0
  205. data/spec/twitter/trend_spec.rb +38 -0
  206. data/spec/twitter/tweet_spec.rb +307 -0
  207. data/spec/twitter/user_spec.rb +127 -0
  208. data/spec/twitter_spec.rb +93 -0
  209. data/twitter.gemspec +30 -0
  210. metadata +584 -0
@@ -0,0 +1,100 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::API do
4
+
5
+ before do
6
+ @client = Twitter::Client.new
7
+ end
8
+
9
+ describe "#places_nearby" do
10
+ before do
11
+ stub_get("/1.1/geo/search.json").
12
+ with(:query => {:ip => "74.125.19.104"}).
13
+ to_return(:body => fixture("places.json"), :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+ it "requests the correct resource" do
16
+ @client.places_nearby(:ip => "74.125.19.104")
17
+ a_get("/1.1/geo/search.json").
18
+ with(:query => {:ip => "74.125.19.104"}).
19
+ should have_been_made
20
+ end
21
+ it "returns nearby places" do
22
+ places = @client.places_nearby(:ip => "74.125.19.104")
23
+ places.should be_an Array
24
+ places.first.name.should eq "Bernal Heights"
25
+ end
26
+ end
27
+
28
+ describe "#places_similar" do
29
+ before do
30
+ stub_get("/1.1/geo/similar_places.json").
31
+ with(:query => {:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ"}).
32
+ to_return(:body => fixture("places.json"), :headers => {:content_type => "application/json; charset=utf-8"})
33
+ end
34
+ it "requests the correct resource" do
35
+ @client.places_similar(:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ")
36
+ a_get("/1.1/geo/similar_places.json").
37
+ with(:query => {:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ"}).
38
+ should have_been_made
39
+ end
40
+ it "returns similar places" do
41
+ places = @client.places_similar(:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ")
42
+ places.should be_an Array
43
+ places.first.name.should eq "Bernal Heights"
44
+ end
45
+ end
46
+
47
+ describe "#reverse_geocode" do
48
+ before do
49
+ stub_get("/1.1/geo/reverse_geocode.json").
50
+ with(:query => {:lat => "37.7821120598956", :long => "-122.400612831116"}).
51
+ to_return(:body => fixture("places.json"), :headers => {:content_type => "application/json; charset=utf-8"})
52
+ end
53
+ it "requests the correct resource" do
54
+ @client.reverse_geocode(:lat => "37.7821120598956", :long => "-122.400612831116")
55
+ a_get("/1.1/geo/reverse_geocode.json").
56
+ with(:query => {:lat => "37.7821120598956", :long => "-122.400612831116"}).
57
+ should have_been_made
58
+ end
59
+ it "returns places" do
60
+ places = @client.reverse_geocode(:lat => "37.7821120598956", :long => "-122.400612831116")
61
+ places.should be_an Array
62
+ places.first.name.should eq "Bernal Heights"
63
+ end
64
+ end
65
+
66
+ describe "#place" do
67
+ before do
68
+ stub_get("/1.1/geo/id/247f43d441defc03.json").
69
+ to_return(:body => fixture("place.json"), :headers => {:content_type => "application/json; charset=utf-8"})
70
+ end
71
+ it "requests the correct resource" do
72
+ @client.place("247f43d441defc03")
73
+ a_get("/1.1/geo/id/247f43d441defc03.json").
74
+ should have_been_made
75
+ end
76
+ it "returns a place" do
77
+ place = @client.place("247f43d441defc03")
78
+ place.name.should eq "Twitter HQ"
79
+ end
80
+ end
81
+
82
+ describe "#place_create" do
83
+ before do
84
+ stub_post("/1.1/geo/place.json").
85
+ with(:body => {:name => "@sferik's Apartment", :token => "22ff5b1f7159032cf69218c4d8bb78bc", :contained_within => "41bcb736f84a799e", :lat => "37.783699", :long => "-122.393581"}).
86
+ to_return(:body => fixture("place.json"), :headers => {:content_type => "application/json; charset=utf-8"})
87
+ end
88
+ it "requests the correct resource" do
89
+ @client.place_create(:name => "@sferik's Apartment", :token => "22ff5b1f7159032cf69218c4d8bb78bc", :contained_within => "41bcb736f84a799e", :lat => "37.783699", :long => "-122.393581")
90
+ a_post("/1.1/geo/place.json").
91
+ with(:body => {:name => "@sferik's Apartment", :token => "22ff5b1f7159032cf69218c4d8bb78bc", :contained_within => "41bcb736f84a799e", :lat => "37.783699", :long => "-122.393581"}).
92
+ should have_been_made
93
+ end
94
+ it "returns a place" do
95
+ place = @client.place_create(:name => "@sferik's Apartment", :token => "22ff5b1f7159032cf69218c4d8bb78bc", :contained_within => "41bcb736f84a799e", :lat => "37.783699", :long => "-122.393581")
96
+ place.name.should eq "Twitter HQ"
97
+ end
98
+ end
99
+
100
+ end
@@ -0,0 +1,76 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::API do
4
+
5
+ before do
6
+ @client = Twitter::Client.new
7
+ end
8
+
9
+ describe "#configuration" do
10
+ before do
11
+ stub_get("/1.1/help/configuration.json").
12
+ to_return(:body => fixture("configuration.json"), :headers => {:content_type => "application/json; charset=utf-8"})
13
+ end
14
+ it "requests the correct resource" do
15
+ @client.configuration
16
+ a_get("/1.1/help/configuration.json").
17
+ should have_been_made
18
+ end
19
+ it "returns Twitter's current configuration" do
20
+ configuration = @client.configuration
21
+ configuration.should be_a Twitter::Configuration
22
+ configuration.characters_reserved_per_media.should eq 20
23
+ end
24
+ end
25
+
26
+ describe "#languages" do
27
+ before do
28
+ stub_get("/1.1/help/languages.json").
29
+ to_return(:body => fixture("languages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
30
+ end
31
+ it "requests the correct resource" do
32
+ @client.languages
33
+ a_get("/1.1/help/languages.json").
34
+ should have_been_made
35
+ end
36
+ it "returns the list of languages supported by Twitter" do
37
+ languages = @client.languages
38
+ languages.should be_an Array
39
+ languages.first.should be_a Twitter::Language
40
+ languages.first.name.should eq "Portuguese"
41
+ end
42
+ end
43
+
44
+ describe "#privacy" do
45
+ before do
46
+ stub_get("/1.1/help/privacy.json").
47
+ to_return(:body => fixture("privacy.json"), :headers => {:content_type => "application/json; charset=utf-8"})
48
+ end
49
+ it "requests the correct resource" do
50
+ @client.privacy
51
+ a_get("/1.1/help/privacy.json").
52
+ should have_been_made
53
+ end
54
+ it "returns Twitter's Privacy Policy" do
55
+ privacy = @client.privacy
56
+ privacy.split.first.should eq "Twitter"
57
+ end
58
+ end
59
+
60
+ describe "#tos" do
61
+ before do
62
+ stub_get("/1.1/help/tos.json").
63
+ to_return(:body => fixture("tos.json"), :headers => {:content_type => "application/json; charset=utf-8"})
64
+ end
65
+ it "requests the correct resource" do
66
+ @client.tos
67
+ a_get("/1.1/help/tos.json").
68
+ should have_been_made
69
+ end
70
+ it "returns Twitter's Terms of Service" do
71
+ tos = @client.tos
72
+ tos.split.first.should eq "Terms"
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,900 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::API do
4
+
5
+ before do
6
+ @client = Twitter::Client.new
7
+ end
8
+
9
+ describe "#list_timeline" do
10
+ context "with a screen name passed" do
11
+ before do
12
+ stub_get("/1.1/lists/statuses.json").
13
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
14
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
15
+ end
16
+ it "requests the correct resource" do
17
+ @client.list_timeline("sferik", "presidents")
18
+ a_get("/1.1/lists/statuses.json").
19
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
20
+ should have_been_made
21
+ end
22
+ it "returns the timeline for members of the specified list" do
23
+ tweets = @client.list_timeline("sferik", "presidents")
24
+ tweets.should be_an Array
25
+ tweets.first.should be_a Twitter::Tweet
26
+ tweets.first.text.should eq "Happy Birthday @imdane. Watch out for those @rally pranksters!"
27
+ end
28
+ end
29
+ context "without a screen name passed" do
30
+ before do
31
+ stub_get("/1.1/account/verify_credentials.json").
32
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
33
+ stub_get("/1.1/lists/statuses.json").
34
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
35
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
36
+ end
37
+ it "requests the correct resource" do
38
+ @client.list_timeline("presidents")
39
+ a_get("/1.1/lists/statuses.json").
40
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
41
+ should have_been_made
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#list_remove_member" do
47
+ context "with a screen name passed" do
48
+ before do
49
+ stub_post("/1.1/lists/members/destroy.json").
50
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
51
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
52
+ end
53
+ it "requests the correct resource" do
54
+ @client.list_remove_member("sferik", "presidents", 813286)
55
+ a_post("/1.1/lists/members/destroy.json").
56
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
57
+ should have_been_made
58
+ end
59
+ it "returns the list" do
60
+ list = @client.list_remove_member("sferik", "presidents", 813286)
61
+ list.should be_a Twitter::List
62
+ list.name.should eq "presidents"
63
+ end
64
+ end
65
+ context "without a screen name passed" do
66
+ before do
67
+ stub_get("/1.1/account/verify_credentials.json").
68
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
69
+ stub_post("/1.1/lists/members/destroy.json").
70
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
71
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
72
+ end
73
+ it "requests the correct resource" do
74
+ @client.list_remove_member("presidents", 813286)
75
+ a_post("/1.1/lists/members/destroy.json").
76
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
77
+ should have_been_made
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#memberships" do
83
+ context "with a screen name passed" do
84
+ before do
85
+ stub_get("/1.1/lists/memberships.json").
86
+ with(:query => {:screen_name => 'pengwynn', :cursor => "-1"}).
87
+ to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
88
+ end
89
+ it "requests the correct resource" do
90
+ @client.memberships("pengwynn")
91
+ a_get("/1.1/lists/memberships.json").
92
+ with(:query => {:screen_name => 'pengwynn', :cursor => "-1"}).
93
+ should have_been_made
94
+ end
95
+ it "returns the lists the specified user has been added to" do
96
+ memberships = @client.memberships("pengwynn")
97
+ memberships.should be_a Twitter::Cursor
98
+ memberships.lists.should be_an Array
99
+ memberships.lists.first.should be_a Twitter::List
100
+ memberships.lists.first.name.should eq "Rubyists"
101
+ end
102
+ end
103
+ context "without a screen name passed" do
104
+ before do
105
+ stub_get("/1.1/account/verify_credentials.json").
106
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
107
+ stub_get("/1.1/lists/memberships.json").
108
+ with(:query => {:cursor => "-1"}).
109
+ to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
110
+ end
111
+ it "requests the correct resource" do
112
+ @client.memberships
113
+ a_get("/1.1/lists/memberships.json").
114
+ with(:query => {:cursor => "-1"}).
115
+ should have_been_made
116
+ end
117
+ end
118
+ end
119
+
120
+ describe "#list_subscribers" do
121
+ context "with a screen name passed" do
122
+ before do
123
+ stub_get("/1.1/lists/subscribers.json").
124
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
125
+ to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
126
+ end
127
+ it "requests the correct resource" do
128
+ @client.list_subscribers("sferik", "presidents")
129
+ a_get("/1.1/lists/subscribers.json").
130
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
131
+ should have_been_made
132
+ end
133
+ it "returns the subscribers of the specified list" do
134
+ list_subscribers = @client.list_subscribers("sferik", "presidents")
135
+ list_subscribers.should be_a Twitter::Cursor
136
+ list_subscribers.users.should be_an Array
137
+ list_subscribers.users.first.should be_a Twitter::User
138
+ list_subscribers.users.first.id.should eq 7505382
139
+ end
140
+ end
141
+ context "without a screen name passed" do
142
+ before do
143
+ stub_get("/1.1/account/verify_credentials.json").
144
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
145
+ stub_get("/1.1/lists/subscribers.json").
146
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
147
+ to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
148
+ end
149
+ it "requests the correct resource" do
150
+ @client.list_subscribers("presidents")
151
+ a_get("/1.1/lists/subscribers.json").
152
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
153
+ should have_been_made
154
+ end
155
+ end
156
+ end
157
+
158
+ describe "#subscriptions" do
159
+ context "with a screen name passed" do
160
+ before do
161
+ stub_get("/1.1/lists/subscriptions.json").
162
+ with(:query => {:screen_name => 'pengwynn', :cursor => "-1"}).
163
+ to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
164
+ end
165
+ it "requests the correct resource" do
166
+ @client.subscriptions("pengwynn")
167
+ a_get("/1.1/lists/subscriptions.json").
168
+ with(:query => {:screen_name => 'pengwynn', :cursor => "-1"}).
169
+ should have_been_made
170
+ end
171
+ it "returns the lists the specified user follows" do
172
+ subscriptions = @client.subscriptions("pengwynn")
173
+ subscriptions.should be_a Twitter::Cursor
174
+ subscriptions.lists.should be_an Array
175
+ subscriptions.lists.first.should be_a Twitter::List
176
+ subscriptions.lists.first.name.should eq "Rubyists"
177
+ end
178
+ end
179
+ context "without a screen name passed" do
180
+ before do
181
+ stub_get("/1.1/account/verify_credentials.json").
182
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
183
+ stub_get("/1.1/lists/subscriptions.json").
184
+ with(:query => {:cursor => "-1"}).
185
+ to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
186
+ end
187
+ it "requests the correct resource" do
188
+ @client.subscriptions
189
+ a_get("/1.1/lists/subscriptions.json").
190
+ with(:query => {:cursor => "-1"}).
191
+ should have_been_made
192
+ end
193
+ end
194
+ end
195
+
196
+ describe "#list_subscribe" do
197
+ context "with a screen name passed" do
198
+ before do
199
+ stub_post("/1.1/lists/subscribers/create.json").
200
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
201
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
202
+ end
203
+ it "requests the correct resource" do
204
+ @client.list_subscribe("sferik", "presidents")
205
+ a_post("/1.1/lists/subscribers/create.json").
206
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
207
+ should have_been_made
208
+ end
209
+ it "returns the specified list" do
210
+ list = @client.list_subscribe("sferik", "presidents")
211
+ list.should be_a Twitter::List
212
+ list.name.should eq "presidents"
213
+ end
214
+ end
215
+ context "without a screen name passed" do
216
+ before do
217
+ stub_get("/1.1/account/verify_credentials.json").
218
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
219
+ stub_post("/1.1/lists/subscribers/create.json").
220
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
221
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
222
+ end
223
+ it "requests the correct resource" do
224
+ @client.list_subscribe("presidents")
225
+ a_post("/1.1/lists/subscribers/create.json").
226
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
227
+ should have_been_made
228
+ end
229
+ end
230
+ end
231
+
232
+ describe "#list_subscriber?" do
233
+ context "with a screen name passed" do
234
+ before do
235
+ stub_get("/1.1/lists/subscribers/show.json").
236
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
237
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
238
+ stub_get("/1.1/lists/subscribers/show.json").
239
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '18755393'}).
240
+ to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
241
+ stub_get("/1.1/lists/subscribers/show.json").
242
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '12345678'}).
243
+ to_return(:body => fixture("not_found.json"), :status => 403, :headers => {:content_type => "application/json; charset=utf-8"})
244
+ end
245
+ it "requests the correct resource" do
246
+ @client.list_subscriber?("sferik", "presidents", 813286)
247
+ a_get("/1.1/lists/subscribers/show.json").
248
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
249
+ should have_been_made
250
+ end
251
+ it "returns true if the specified user subscribes to the specified list" do
252
+ list_subscriber = @client.list_subscriber?("sferik", "presidents", 813286)
253
+ list_subscriber.should be_true
254
+ end
255
+ it "returns false if the specified user does not subscribe to the specified list" do
256
+ list_subscriber = @client.list_subscriber?("sferik", "presidents", 18755393)
257
+ list_subscriber.should be_false
258
+ end
259
+ it "returns false if user does not exist" do
260
+ list_subscriber = @client.list_subscriber?("sferik", "presidents", 12345678)
261
+ list_subscriber.should be_false
262
+ end
263
+ end
264
+ context "with a owner ID passed" do
265
+ before do
266
+ stub_get("/1.1/lists/subscribers/show.json").
267
+ with(:query => {:owner_id => '12345678', :slug => 'presidents', :user_id => '813286'}).
268
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
269
+ end
270
+ it "requests the correct resource" do
271
+ @client.list_subscriber?(12345678, "presidents", 813286)
272
+ a_get("/1.1/lists/subscribers/show.json").
273
+ with(:query => {:owner_id => '12345678', :slug => 'presidents', :user_id => '813286'}).
274
+ should have_been_made
275
+ end
276
+ end
277
+ context "with a list ID passed" do
278
+ before do
279
+ stub_get("/1.1/lists/subscribers/show.json").
280
+ with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'}).
281
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
282
+ end
283
+ it "requests the correct resource" do
284
+ @client.list_subscriber?('sferik', 12345678, 813286)
285
+ a_get("/1.1/lists/subscribers/show.json").
286
+ with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'}).
287
+ should have_been_made
288
+ end
289
+ end
290
+ context "with a list object passed" do
291
+ before do
292
+ stub_get("/1.1/lists/subscribers/show.json").
293
+ with(:query => {:owner_id => '7505382', :list_id => '12345678', :user_id => '813286'}).
294
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
295
+ end
296
+ it "requests the correct resource" do
297
+ list = Twitter::List.new(:id => 12345678, :user => {:id => 7505382, :screen_name => 'sferik'})
298
+ @client.list_subscriber?(list, 813286)
299
+ a_get("/1.1/lists/subscribers/show.json").
300
+ with(:query => {:owner_id => '7505382', :list_id => '12345678', :user_id => '813286'}).
301
+ should have_been_made
302
+ end
303
+ end
304
+ context "with a screen name passed for user_to_check" do
305
+ before do
306
+ stub_get("/1.1/lists/subscribers/show.json").
307
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :screen_name => 'erebor'}).
308
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
309
+ end
310
+ it "requests the correct resource" do
311
+ @client.list_subscriber?("sferik", "presidents", 'erebor')
312
+ a_get("/1.1/lists/subscribers/show.json").
313
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :screen_name => 'erebor'}).
314
+ should have_been_made
315
+ end
316
+ end
317
+ context "without a screen name passed" do
318
+ before do
319
+ stub_get("/1.1/account/verify_credentials.json").
320
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
321
+ stub_get("/1.1/lists/subscribers/show.json").
322
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
323
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
324
+ end
325
+ it "requests the correct resource" do
326
+ @client.list_subscriber?("presidents", 813286)
327
+ a_get("/1.1/lists/subscribers/show.json").
328
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
329
+ should have_been_made
330
+ end
331
+ end
332
+ end
333
+
334
+ describe "#list_unsubscribe" do
335
+ context "with a screen name passed" do
336
+ before do
337
+ stub_post("/1.1/lists/subscribers/destroy.json").
338
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
339
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
340
+ end
341
+ it "requests the correct resource" do
342
+ @client.list_unsubscribe("sferik", "presidents")
343
+ a_post("/1.1/lists/subscribers/destroy.json").
344
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
345
+ should have_been_made
346
+ end
347
+ it "returns the specified list" do
348
+ list = @client.list_unsubscribe("sferik", "presidents")
349
+ list.should be_a Twitter::List
350
+ list.name.should eq "presidents"
351
+ end
352
+ end
353
+ context "without a screen name passed" do
354
+ before do
355
+ stub_get("/1.1/account/verify_credentials.json").
356
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
357
+ stub_post("/1.1/lists/subscribers/destroy.json").
358
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
359
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
360
+ end
361
+ it "requests the correct resource" do
362
+ @client.list_unsubscribe("presidents")
363
+ a_post("/1.1/lists/subscribers/destroy.json").
364
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
365
+ should have_been_made
366
+ end
367
+ end
368
+ end
369
+
370
+ describe "#list_add_members" do
371
+ context "with a screen name passed" do
372
+ before do
373
+ stub_post("/1.1/lists/members/create_all.json").
374
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
375
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
376
+ end
377
+ it "requests the correct resource" do
378
+ @client.list_add_members("sferik", "presidents", [813286, 18755393])
379
+ a_post("/1.1/lists/members/create_all.json").
380
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
381
+ should have_been_made
382
+ end
383
+ it "returns the list" do
384
+ list = @client.list_add_members("sferik", "presidents", [813286, 18755393])
385
+ list.should be_a Twitter::List
386
+ list.name.should eq "presidents"
387
+ end
388
+ end
389
+ context "with a combination of member IDs and member screen names to add" do
390
+ before do
391
+ stub_post("/1.1/lists/members/create_all.json").
392
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).
393
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
394
+ end
395
+ it "requests the correct resource" do
396
+ @client.list_add_members('sferik', 'presidents', [813286, 'pengwynn', 18755393, 'erebor'])
397
+ a_post("/1.1/lists/members/create_all.json").
398
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).
399
+ should have_been_made
400
+ end
401
+ end
402
+ context "without a screen name passed" do
403
+ before do
404
+ stub_get("/1.1/account/verify_credentials.json").
405
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
406
+ stub_post("/1.1/lists/members/create_all.json").
407
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
408
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
409
+ end
410
+ it "requests the correct resource" do
411
+ @client.list_add_members("presidents", [813286, 18755393])
412
+ a_post("/1.1/lists/members/create_all.json").
413
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
414
+ should have_been_made
415
+ end
416
+ end
417
+ end
418
+
419
+ describe "#list_remove_members" do
420
+ context "with a screen name passed" do
421
+ before do
422
+ stub_post("/1.1/lists/members/destroy_all.json").
423
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
424
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
425
+ end
426
+ it "requests the correct resource" do
427
+ @client.list_remove_members("sferik", "presidents", [813286, 18755393])
428
+ a_post("/1.1/lists/members/destroy_all.json").
429
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
430
+ should have_been_made
431
+ end
432
+ it "returns the list" do
433
+ list = @client.list_remove_members("sferik", "presidents", [813286, 18755393])
434
+ list.should be_a Twitter::List
435
+ list.name.should eq "presidents"
436
+ end
437
+ end
438
+ context "with a combination of member IDs and member screen names to add" do
439
+ before do
440
+ stub_post("/1.1/lists/members/destroy_all.json").
441
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).
442
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
443
+ end
444
+ it "requests the correct resource" do
445
+ @client.list_remove_members('sferik', 'presidents', [813286, 'pengwynn', 18755393, 'erebor'])
446
+ a_post("/1.1/lists/members/destroy_all.json").
447
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).
448
+ should have_been_made
449
+ end
450
+ end
451
+ context "without a screen name passed" do
452
+ before do
453
+ stub_get("/1.1/account/verify_credentials.json").
454
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
455
+ stub_post("/1.1/lists/members/destroy_all.json").
456
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
457
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
458
+ end
459
+ it "requests the correct resource" do
460
+ @client.list_remove_members("presidents", [813286, 18755393])
461
+ a_post("/1.1/lists/members/destroy_all.json").
462
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
463
+ should have_been_made
464
+ end
465
+ end
466
+ end
467
+
468
+ describe "#list_member?" do
469
+ context "with a screen name passed" do
470
+ before do
471
+ stub_get("/1.1/lists/members/show.json").
472
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
473
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
474
+ stub_get("/1.1/lists/members/show.json").
475
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '65493023'}).
476
+ to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
477
+ stub_get("/1.1/lists/members/show.json").
478
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '12345678'}).
479
+ to_return(:body => fixture("not_found.json"), :status => 403, :headers => {:content_type => "application/json; charset=utf-8"})
480
+ end
481
+ it "requests the correct resource" do
482
+ @client.list_member?("sferik", "presidents", 813286)
483
+ a_get("/1.1/lists/members/show.json").
484
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
485
+ should have_been_made
486
+ end
487
+ it "returns true if user is a list member" do
488
+ list_member = @client.list_member?("sferik", "presidents", 813286)
489
+ list_member.should be_true
490
+ end
491
+ it "returns false if user is not a list member" do
492
+ list_member = @client.list_member?("sferik", "presidents", 65493023)
493
+ list_member.should be_false
494
+ end
495
+ it "returns false if user does not exist" do
496
+ list_member = @client.list_member?("sferik", "presidents", 12345678)
497
+ list_member.should be_false
498
+ end
499
+ end
500
+ context "with an owner ID passed" do
501
+ before do
502
+ stub_get("/1.1/lists/members/show.json").
503
+ with(:query => {:owner_id => '12345678', :slug => 'presidents', :user_id => '813286'}).
504
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
505
+ end
506
+ it "requests the correct resource" do
507
+ @client.list_member?(12345678, "presidents", 813286)
508
+ a_get("/1.1/lists/members/show.json").
509
+ with(:query => {:owner_id => '12345678', :slug => 'presidents', :user_id => '813286'}).
510
+ should have_been_made
511
+ end
512
+ end
513
+ context "with a list ID passed" do
514
+ before do
515
+ stub_get("/1.1/lists/members/show.json").
516
+ with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'}).
517
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
518
+ end
519
+ it "requests the correct resource" do
520
+ @client.list_member?('sferik', 12345678, 813286)
521
+ a_get("/1.1/lists/members/show.json").
522
+ with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'}).
523
+ should have_been_made
524
+ end
525
+ end
526
+ context "with a list object passed" do
527
+ before do
528
+ stub_get("/1.1/lists/members/show.json").
529
+ with(:query => {:owner_id => '7505382', :list_id => '12345678', :user_id => '813286'}).
530
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
531
+ end
532
+ it "requests the correct resource" do
533
+ list = Twitter::List.new(:id => 12345678, :user => {:id => 7505382, :screen_name => 'sferik'})
534
+ @client.list_member?(list, 813286)
535
+ a_get("/1.1/lists/members/show.json").
536
+ with(:query => {:owner_id => '7505382', :list_id => '12345678', :user_id => '813286'}).
537
+ should have_been_made
538
+ end
539
+ end
540
+ context "with a screen name passed for user_to_check" do
541
+ before do
542
+ stub_get("/1.1/lists/members/show.json").
543
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :screen_name => 'erebor'}).
544
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/.json; charset=utf-8"})
545
+ end
546
+ it "requests the correct resource" do
547
+ @client.list_member?("sferik", "presidents", 'erebor')
548
+ a_get("/1.1/lists/members/show.json").
549
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :screen_name => 'erebor'}).
550
+ should have_been_made
551
+ end
552
+ end
553
+ context "without a screen name passed" do
554
+ before do
555
+ stub_get("/1.1/account/verify_credentials.json").
556
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
557
+ stub_get("/1.1/lists/members/show.json").
558
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
559
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/.json; charset=utf-8"})
560
+ end
561
+ it "requests the correct resource" do
562
+ @client.list_member?("presidents", 813286)
563
+ a_get("/1.1/lists/members/show.json").
564
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
565
+ should have_been_made
566
+ end
567
+ end
568
+ end
569
+
570
+ describe "#list_members" do
571
+ context "with a screen name passed" do
572
+ before do
573
+ stub_get("/1.1/lists/members.json").
574
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
575
+ to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
576
+ end
577
+ it "requests the correct resource" do
578
+ @client.list_members("sferik", "presidents")
579
+ a_get("/1.1/lists/members.json").
580
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
581
+ should have_been_made
582
+ end
583
+ it "returns the members of the specified list" do
584
+ list_members = @client.list_members("sferik", "presidents")
585
+ list_members.should be_a Twitter::Cursor
586
+ list_members.users.should be_an Array
587
+ list_members.users.first.should be_a Twitter::User
588
+ list_members.users.first.id.should eq 7505382
589
+ end
590
+ end
591
+ context "without a screen name passed" do
592
+ before do
593
+ stub_get("/1.1/account/verify_credentials.json").
594
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
595
+ stub_get("/1.1/lists/members.json").
596
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
597
+ to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
598
+ end
599
+ it "requests the correct resource" do
600
+ @client.list_members("presidents")
601
+ a_get("/1.1/lists/members.json").
602
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
603
+ should have_been_made
604
+ end
605
+ end
606
+ end
607
+
608
+ describe "#list_add_member" do
609
+ context "with a screen name passed" do
610
+ before do
611
+ stub_post("/1.1/lists/members/create.json").
612
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
613
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
614
+ end
615
+ it "requests the correct resource" do
616
+ @client.list_add_member("sferik", "presidents", 813286)
617
+ a_post("/1.1/lists/members/create.json").
618
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
619
+ should have_been_made
620
+ end
621
+ it "returns the list" do
622
+ list = @client.list_add_member("sferik", "presidents", 813286)
623
+ list.should be_a Twitter::List
624
+ list.name.should eq "presidents"
625
+ end
626
+ end
627
+ context "without a screen name passed" do
628
+ before do
629
+ stub_get("/1.1/account/verify_credentials.json").
630
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
631
+ stub_post("/1.1/lists/members/create.json").
632
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
633
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
634
+ end
635
+ it "requests the correct resource" do
636
+ @client.list_add_member("presidents", 813286)
637
+ a_post("/1.1/lists/members/create.json").
638
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
639
+ should have_been_made
640
+ end
641
+ end
642
+ end
643
+
644
+ describe "#list_destroy" do
645
+ context "with a screen name passed" do
646
+ before do
647
+ stub_post("/1.1/lists/destroy.json").
648
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
649
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
650
+ end
651
+ it "requests the correct resource" do
652
+ @client.list_destroy("sferik", "presidents")
653
+ a_post("/1.1/lists/destroy.json").
654
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
655
+ should have_been_made
656
+ end
657
+ it "returns the deleted list" do
658
+ list = @client.list_destroy("sferik", "presidents")
659
+ list.should be_a Twitter::List
660
+ list.name.should eq "presidents"
661
+ end
662
+ end
663
+ context "without a screen name passed" do
664
+ before do
665
+ stub_get("/1.1/account/verify_credentials.json").
666
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
667
+ stub_post("/1.1/lists/destroy.json").
668
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
669
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
670
+ end
671
+ it "requests the correct resource" do
672
+ @client.list_destroy("presidents")
673
+ a_post("/1.1/lists/destroy.json").
674
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
675
+ should have_been_made
676
+ end
677
+ end
678
+ context "with a list ID passed" do
679
+ before do
680
+ stub_post("/1.1/lists/destroy.json").
681
+ with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678'}).
682
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
683
+ end
684
+ it "requests the correct resource" do
685
+ @client.list_destroy("sferik", 12345678)
686
+ a_post("/1.1/lists/destroy.json").
687
+ with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678'}).
688
+ should have_been_made
689
+ end
690
+ end
691
+ context "with a list object passed" do
692
+ before do
693
+ stub_post("/1.1/lists/destroy.json").
694
+ with(:body => {:owner_id => '7505382', :list_id => '12345678'}).
695
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
696
+ end
697
+ it "requests the correct resource" do
698
+ list = Twitter::List.new(:id => '12345678', :user => {:id => 7505382, :screen_name => 'sferik'})
699
+ @client.list_destroy(list)
700
+ a_post("/1.1/lists/destroy.json").
701
+ with(:body => {:owner_id => '7505382', :list_id => '12345678'}).
702
+ should have_been_made
703
+ end
704
+ end
705
+ end
706
+
707
+ describe "#list_update" do
708
+ context "with a screen name passed" do
709
+ before do
710
+ stub_post("/1.1/lists/update.json").
711
+ with(:body => {:owner_screen_name => 'sferik', :slug => "presidents", :description => "Presidents of the United States of America"}).
712
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
713
+ end
714
+ it "requests the correct resource" do
715
+ @client.list_update("sferik", "presidents", :description => "Presidents of the United States of America")
716
+ a_post("/1.1/lists/update.json").
717
+ with(:body => {:owner_screen_name => 'sferik', :slug => "presidents", :description => "Presidents of the United States of America"}).
718
+ should have_been_made
719
+ end
720
+ it "returns the updated list" do
721
+ list = @client.list_update("sferik", "presidents", :description => "Presidents of the United States of America")
722
+ list.should be_a Twitter::List
723
+ list.name.should eq "presidents"
724
+ end
725
+ end
726
+ context "without a screen name passed" do
727
+ before do
728
+ stub_get("/1.1/account/verify_credentials.json").
729
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
730
+ stub_post("/1.1/lists/update.json").
731
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :description => "Presidents of the United States of America"}).
732
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
733
+ end
734
+ it "requests the correct resource" do
735
+ @client.list_update("presidents", :description => "Presidents of the United States of America")
736
+ a_post("/1.1/lists/update.json").
737
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :description => "Presidents of the United States of America"}).
738
+ should have_been_made
739
+ end
740
+ end
741
+ context "with a list ID passed" do
742
+ before do
743
+ stub_post("/1.1/lists/update.json").
744
+ with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678', :description => "Presidents of the United States of America"}).
745
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
746
+ end
747
+ it "requests the correct resource" do
748
+ @client.list_update("sferik", 12345678, :description => "Presidents of the United States of America")
749
+ a_post("/1.1/lists/update.json").
750
+ with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678', :description => "Presidents of the United States of America"}).
751
+ should have_been_made
752
+ end
753
+ end
754
+ context "with a list object passed" do
755
+ before do
756
+ stub_post("/1.1/lists/update.json").
757
+ with(:body => {:owner_id => '7505382', :list_id => '12345678', :description => "Presidents of the United States of America"}).
758
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
759
+ end
760
+ it "requests the correct resource" do
761
+ list = Twitter::List.new(:id => '12345678', :user => {:id => 7505382, :screen_name => 'sferik'})
762
+ @client.list_update(list, :description => "Presidents of the United States of America")
763
+ a_post("/1.1/lists/update.json").
764
+ with(:body => {:owner_id => '7505382', :list_id => '12345678', :description => "Presidents of the United States of America"}).
765
+ should have_been_made
766
+ end
767
+ end
768
+ end
769
+
770
+ describe "#list_create" do
771
+ before do
772
+ stub_post("/1.1/lists/create.json").
773
+ with(:body => {:name => "presidents"}).
774
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
775
+ end
776
+ it "requests the correct resource" do
777
+ @client.list_create("presidents")
778
+ a_post("/1.1/lists/create.json").
779
+ with(:body => {:name => "presidents"}).
780
+ should have_been_made
781
+ end
782
+ it "returns the created list" do
783
+ list = @client.list_create("presidents")
784
+ list.should be_a Twitter::List
785
+ list.name.should eq "presidents"
786
+ end
787
+ end
788
+
789
+ describe "#lists" do
790
+ before do
791
+ stub_get("/1.1/lists/list.json").
792
+ with(:query => {:cursor => "-1"}).
793
+ to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
794
+ end
795
+ it "requests the correct resource" do
796
+ @client.lists
797
+ a_get("/1.1/lists/list.json").
798
+ with(:query => {:cursor => "-1"}).
799
+ should have_been_made
800
+ end
801
+ it "returns the requested list" do
802
+ lists = @client.lists
803
+ lists.should be_a Twitter::Cursor
804
+ lists.lists.should be_an Array
805
+ lists.lists.first.should be_a Twitter::List
806
+ lists.lists.first.name.should eq "Rubyists"
807
+ end
808
+ end
809
+
810
+ describe "#list" do
811
+ context "with a screen name passed" do
812
+ before do
813
+ stub_get("/1.1/lists/show.json").
814
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
815
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
816
+ end
817
+ it "requests the correct resource" do
818
+ @client.list("sferik", "presidents")
819
+ a_get("/1.1/lists/show.json").
820
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
821
+ should have_been_made
822
+ end
823
+ it "returns the updated list" do
824
+ list = @client.list("sferik", "presidents")
825
+ list.should be_a Twitter::List
826
+ list.name.should eq "presidents"
827
+ end
828
+ end
829
+ context "with a user ID passed" do
830
+ before do
831
+ stub_get("/1.1/lists/show.json").
832
+ with(:query => {:owner_id => '12345678', :slug => 'presidents'}).
833
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
834
+ end
835
+ it "requests the correct resource" do
836
+ @client.list(12345678, 'presidents')
837
+ a_get("/1.1/lists/show.json").
838
+ with(:query => {:owner_id => '12345678', :slug => 'presidents'}).
839
+ should have_been_made
840
+ end
841
+ end
842
+ context "with a user object passed" do
843
+ before do
844
+ stub_get("/1.1/lists/show.json").
845
+ with(:query => {:owner_id => '12345678', :slug => 'presidents'}).
846
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
847
+ end
848
+ it "requests the correct resource" do
849
+ user = Twitter::User.new(:id => '12345678')
850
+ @client.list(user, 'presidents')
851
+ a_get("/1.1/lists/show.json").
852
+ with(:query => {:owner_id => '12345678', :slug => 'presidents'}).
853
+ should have_been_made
854
+ end
855
+ end
856
+ context "without a screen name passed" do
857
+ before do
858
+ stub_get("/1.1/account/verify_credentials.json").
859
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
860
+ stub_get("/1.1/lists/show.json").
861
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
862
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
863
+ end
864
+ it "requests the correct resource" do
865
+ @client.list("presidents")
866
+ a_get("/1.1/lists/show.json").
867
+ with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
868
+ should have_been_made
869
+ end
870
+ end
871
+ context "with a list ID passed" do
872
+ before do
873
+ stub_get("/1.1/lists/show.json").
874
+ with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678'}).
875
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
876
+ end
877
+ it "requests the correct resource" do
878
+ @client.list("sferik", 12345678)
879
+ a_get("/1.1/lists/show.json").
880
+ with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678'}).
881
+ should have_been_made
882
+ end
883
+ end
884
+ context "with a list object passed" do
885
+ before do
886
+ stub_get("/1.1/lists/show.json").
887
+ with(:query => {:owner_id => '7505382', :list_id => '12345678'}).
888
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
889
+ end
890
+ it "requests the correct resource" do
891
+ list = Twitter::List.new(:id => '12345678', :user => {:id => 7505382, :screen_name => 'sferik'})
892
+ @client.list(list)
893
+ a_get("/1.1/lists/show.json").
894
+ with(:query => {:owner_id => '7505382', :list_id => '12345678'}).
895
+ should have_been_made
896
+ end
897
+ end
898
+ end
899
+
900
+ end