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,80 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::API do
4
+
5
+ before do
6
+ @client = Twitter::Client.new
7
+ end
8
+
9
+ describe "#trends" do
10
+ context "with woeid passed" do
11
+ before do
12
+ stub_get("/1.1/trends/place.json").
13
+ with(:query => {:id => "2487956"}).
14
+ to_return(:body => fixture("matching_trends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
15
+ end
16
+ it "requests the correct resource" do
17
+ @client.trends(2487956)
18
+ a_get("/1.1/trends/place.json").
19
+ with(:query => {:id => "2487956"}).
20
+ should have_been_made
21
+ end
22
+ it "returns the top 10 trending topics for a specific WOEID" do
23
+ matching_trends = @client.trends(2487956)
24
+ matching_trends.should be_an Array
25
+ matching_trends.first.should be_a Twitter::Trend
26
+ matching_trends.first.name.should eq "#sevenwordsaftersex"
27
+ end
28
+ end
29
+ context "without arguments passed" do
30
+ before do
31
+ stub_get("/1.1/trends/place.json").
32
+ with(:query => {:id => "1"}).
33
+ to_return(:body => fixture("matching_trends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
34
+ end
35
+ it "requests the correct resource" do
36
+ @client.trends
37
+ a_get("/1.1/trends/place.json").
38
+ with(:query => {:id => "1"}).
39
+ should have_been_made
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#trends_available" do
45
+ before do
46
+ stub_get("/1.1/trends/available.json").
47
+ to_return(:body => fixture("locations.json"), :headers => {:content_type => "application/json; charset=utf-8"})
48
+ end
49
+ it "requests the correct resource" do
50
+ @client.trends_available
51
+ a_get("/1.1/trends/available.json").
52
+ should have_been_made
53
+ end
54
+ it "returns the locations that Twitter has trending topic information for" do
55
+ locations = @client.trends_available
56
+ locations.should be_an Array
57
+ locations.first.should be_a Twitter::Place
58
+ locations.first.name.should eq "Ireland"
59
+ end
60
+ end
61
+
62
+ describe "#trends_closest" do
63
+ before do
64
+ stub_get("/1.1/trends/closest.json").
65
+ to_return(:body => fixture("locations.json"), :headers => {:content_type => "application/json; charset=utf-8"})
66
+ end
67
+ it "requests the correct resource" do
68
+ @client.trends_closest
69
+ a_get("/1.1/trends/closest.json").
70
+ should have_been_made
71
+ end
72
+ it "returns the locations that Twitter has trending topic information for" do
73
+ locations = @client.trends_closest
74
+ locations.should be_an Array
75
+ locations.first.should be_a Twitter::Place
76
+ locations.first.name.should eq "Ireland"
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,419 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::API do
4
+
5
+ before do
6
+ @client = Twitter::Client.new
7
+ end
8
+
9
+ describe "#suggestions" do
10
+ context "with a category slug passed" do
11
+ before do
12
+ stub_get("/1.1/users/suggestions/art-design.json").
13
+ to_return(:body => fixture("category.json"), :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+ it "requests the correct resource" do
16
+ @client.suggestions("art-design")
17
+ a_get("/1.1/users/suggestions/art-design.json").
18
+ should have_been_made
19
+ end
20
+ it "returns the users in a given category of the Twitter suggested user list" do
21
+ suggestion = @client.suggestions("art-design")
22
+ suggestion.should be_a Twitter::Suggestion
23
+ suggestion.name.should eq "Art & Design"
24
+ suggestion.users.should be_an Array
25
+ suggestion.users.first.should be_a Twitter::User
26
+ end
27
+ end
28
+ context "without arguments passed" do
29
+ before do
30
+ stub_get("/1.1/users/suggestions.json").
31
+ to_return(:body => fixture("suggestions.json"), :headers => {:content_type => "application/json; charset=utf-8"})
32
+ end
33
+ it "requests the correct resource" do
34
+ @client.suggestions
35
+ a_get("/1.1/users/suggestions.json").
36
+ should have_been_made
37
+ end
38
+ it "returns the list of suggested user categories" do
39
+ suggestions = @client.suggestions
40
+ suggestions.should be_an Array
41
+ suggestions.first.should be_a Twitter::Suggestion
42
+ suggestions.first.name.should eq "Art & Design"
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#suggest_users" do
48
+ before do
49
+ stub_get("/1.1/users/suggestions/art-design/members.json").
50
+ to_return(:body => fixture("members.json"), :headers => {:content_type => "application/json; charset=utf-8"})
51
+ end
52
+ it "requests the correct resource" do
53
+ @client.suggest_users("art-design")
54
+ a_get("/1.1/users/suggestions/art-design/members.json").
55
+ should have_been_made
56
+ end
57
+ it "returns users in a given category of the Twitter suggested user list and return their most recent status if they are not a protected user" do
58
+ suggest_users = @client.suggest_users("art-design")
59
+ suggest_users.should be_an Array
60
+ suggest_users.first.should be_a Twitter::User
61
+ suggest_users.first.name.should eq "OMGFacts"
62
+ end
63
+ end
64
+
65
+ describe "#users" do
66
+ context "with screen names passed" do
67
+ before do
68
+ stub_post("/1.1/users/lookup.json").
69
+ with(:body => {:screen_name => "sferik,pengwynn"}).
70
+ to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
71
+ end
72
+ it "requests the correct resource" do
73
+ @client.users("sferik", "pengwynn")
74
+ a_post("/1.1/users/lookup.json").
75
+ with(:body => {:screen_name => "sferik,pengwynn"}).
76
+ should have_been_made
77
+ end
78
+ it "returns up to 100 users worth of extended information" do
79
+ users = @client.users("sferik", "pengwynn")
80
+ users.should be_an Array
81
+ users.first.should be_a Twitter::User
82
+ users.first.id.should eq 7505382
83
+ end
84
+ end
85
+ context "with numeric screen names passed" do
86
+ before do
87
+ stub_post("/1.1/users/lookup.json").
88
+ with(:body => {:screen_name => "0,311"}).
89
+ to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
90
+ end
91
+ it "requests the correct resource" do
92
+ @client.users("0", "311")
93
+ a_post("/1.1/users/lookup.json").
94
+ with(:body => {:screen_name => "0,311"}).
95
+ should have_been_made
96
+ end
97
+ end
98
+ context "with user IDs passed" do
99
+ before do
100
+ stub_post("/1.1/users/lookup.json").
101
+ with(:body => {:user_id => "7505382,14100886"}).
102
+ to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
103
+ end
104
+ it "requests the correct resource" do
105
+ @client.users(7505382, 14100886)
106
+ a_post("/1.1/users/lookup.json").
107
+ with(:body => {:user_id => "7505382,14100886"}).
108
+ should have_been_made
109
+ end
110
+ end
111
+ context "with both screen names and user IDs passed" do
112
+ before do
113
+ stub_post("/1.1/users/lookup.json").
114
+ with(:body => {:screen_name => "sferik", :user_id => "14100886"}).
115
+ to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
116
+ end
117
+ it "requests the correct resource" do
118
+ @client.users("sferik", 14100886)
119
+ a_post("/1.1/users/lookup.json").
120
+ with(:body => {:screen_name => "sferik", :user_id => "14100886"}).
121
+ should have_been_made
122
+ end
123
+ end
124
+ context "with user objects passed" do
125
+ before do
126
+ stub_post("/1.1/users/lookup.json").
127
+ with(:body => {:user_id => "7505382,14100886"}).
128
+ to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
129
+ end
130
+ it "requests the correct resource" do
131
+ user1 = Twitter::User.new(:id => '7505382')
132
+ user2 = Twitter::User.new(:id => '14100886')
133
+ @client.users(user1, user2)
134
+ a_post("/1.1/users/lookup.json").
135
+ with(:body => {:user_id => "7505382,14100886"}).
136
+ should have_been_made
137
+ end
138
+ end
139
+ end
140
+
141
+ describe "#user_search" do
142
+ before do
143
+ stub_get("/1.1/users/search.json").
144
+ with(:query => {:q => "Erik Michaels-Ober"}).
145
+ to_return(:body => fixture("user_search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
146
+ end
147
+ it "requests the correct resource" do
148
+ @client.user_search("Erik Michaels-Ober")
149
+ a_get("/1.1/users/search.json").
150
+ with(:query => {:q => "Erik Michaels-Ober"}).
151
+ should have_been_made
152
+ end
153
+ it "returns an array of user search results" do
154
+ user_search = @client.user_search("Erik Michaels-Ober")
155
+ user_search.should be_an Array
156
+ user_search.first.should be_a Twitter::User
157
+ user_search.first.id.should eq 7505382
158
+ end
159
+ end
160
+
161
+ describe "#user" do
162
+ context "with a screen name passed" do
163
+ before do
164
+ stub_get("/1.1/users/show.json").
165
+ with(:query => {:screen_name => "sferik"}).
166
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
167
+ end
168
+ it "requests the correct resource" do
169
+ @client.user("sferik")
170
+ a_get("/1.1/users/show.json").
171
+ with(:query => {:screen_name => "sferik"}).
172
+ should have_been_made
173
+ end
174
+ it "returns extended information of a given user" do
175
+ user = @client.user("sferik")
176
+ user.should be_a Twitter::User
177
+ user.id.should eq 7505382
178
+ end
179
+ end
180
+ context "with a screen name including '@' passed" do
181
+ before do
182
+ stub_get("/1.1/users/show.json").
183
+ with(:query => {:screen_name => "@sferik"}).
184
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
185
+ end
186
+ it "requests the correct resource" do
187
+ @client.user("@sferik")
188
+ a_get("/1.1/users/show.json").
189
+ with(:query => {:screen_name => "@sferik"}).
190
+ should have_been_made
191
+ end
192
+ end
193
+ context "with a numeric screen name passed" do
194
+ before do
195
+ stub_get("/1.1/users/show.json").
196
+ with(:query => {:screen_name => "0"}).
197
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
198
+ end
199
+ it "requests the correct resource" do
200
+ @client.user("0")
201
+ a_get("/1.1/users/show.json").
202
+ with(:query => {:screen_name => "0"}).
203
+ should have_been_made
204
+ end
205
+ end
206
+ context "with a user ID passed" do
207
+ before do
208
+ stub_get("/1.1/users/show.json").
209
+ with(:query => {:user_id => "7505382"}).
210
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
211
+ end
212
+ it "requests the correct resource" do
213
+ @client.user(7505382)
214
+ a_get("/1.1/users/show.json").
215
+ with(:query => {:user_id => "7505382"}).
216
+ should have_been_made
217
+ end
218
+ end
219
+ context "with a user object passed" do
220
+ before do
221
+ stub_get("/1.1/users/show.json").
222
+ with(:query => {:user_id => "7505382"}).
223
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
224
+ end
225
+ it "requests the correct resource" do
226
+ user = Twitter::User.new(:id => 7505382)
227
+ @client.user(user)
228
+ a_get("/1.1/users/show.json").
229
+ with(:query => {:user_id => "7505382"}).
230
+ should have_been_made
231
+ end
232
+ end
233
+ end
234
+ context "without a screen name or user ID passed" do
235
+ context "without options passed" do
236
+ before do
237
+ stub_get("/1.1/account/verify_credentials.json").
238
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
239
+ end
240
+ it "requests the correct resource" do
241
+ @client.user
242
+ a_get("/1.1/account/verify_credentials.json").
243
+ should have_been_made
244
+ end
245
+ end
246
+ context "with options passed" do
247
+ before do
248
+ stub_get("/1.1/account/verify_credentials.json").
249
+ with(:query => {:skip_status => "true"}).
250
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
251
+ end
252
+ it "requests the correct resource" do
253
+ @client.user(:skip_status => true)
254
+ a_get("/1.1/account/verify_credentials.json").
255
+ with(:query => {:skip_status => "true"}).
256
+ should have_been_made
257
+ end
258
+ end
259
+ end
260
+
261
+ describe "#user?" do
262
+ before do
263
+ stub_get("/1.1/users/show.json").
264
+ with(:query => {:screen_name => "sferik"}).
265
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
266
+ stub_get("/1.1/users/show.json").
267
+ with(:query => {:screen_name => "pengwynn"}).
268
+ to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
269
+ end
270
+ it "requests the correct resource" do
271
+ @client.user?("sferik")
272
+ a_get("/1.1/users/show.json").
273
+ with(:query => {:screen_name => "sferik"}).
274
+ should have_been_made
275
+ end
276
+ it "returns true if user exists" do
277
+ user = @client.user?("sferik")
278
+ user.should be_true
279
+ end
280
+ it "returns false if user does not exist" do
281
+ user = @client.user?("pengwynn")
282
+ user.should be_false
283
+ end
284
+ end
285
+
286
+ describe "#contributees" do
287
+ context "with a screen name passed" do
288
+ before do
289
+ stub_get("/1.1/users/contributees.json").
290
+ with(:query => {:screen_name => "sferik"}).
291
+ to_return(:body => fixture("contributees.json"), :headers => {:content_type => "application/json; charset=utf-8"})
292
+ end
293
+ it "requests the correct resource" do
294
+ @client.contributees("sferik")
295
+ a_get("/1.1/users/contributees.json").
296
+ with(:query => {:screen_name => "sferik"}).
297
+ should have_been_made
298
+ end
299
+ it "returns a user's contributees" do
300
+ contributees = @client.contributees("sferik")
301
+ contributees.should be_an Array
302
+ contributees.first.should be_a Twitter::User
303
+ contributees.first.name.should eq "Twitter API"
304
+ end
305
+ end
306
+ context "without arguments passed" do
307
+ before do
308
+ stub_get("/1.1/account/verify_credentials.json").
309
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
310
+ stub_get("/1.1/users/contributees.json").
311
+ with(:query => {:screen_name => "sferik"}).
312
+ to_return(:body => fixture("contributees.json"), :headers => {:content_type => "application/json; charset=utf-8"})
313
+ end
314
+ it "requests the correct resource" do
315
+ @client.contributees
316
+ a_get("/1.1/users/contributees.json").
317
+ with(:query => {:screen_name => "sferik"}).
318
+ should have_been_made
319
+ end
320
+ it "returns a user's contributees" do
321
+ contributees = @client.contributees
322
+ contributees.should be_an Array
323
+ contributees.first.should be_a Twitter::User
324
+ contributees.first.name.should eq "Twitter API"
325
+ end
326
+ end
327
+ end
328
+
329
+ describe "#contributors" do
330
+ context "with a screen name passed" do
331
+ before do
332
+ stub_get("/1.1/account/verify_credentials.json").
333
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
334
+ stub_get("/1.1/users/contributors.json").
335
+ with(:query => {:screen_name => "sferik"}).
336
+ to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"})
337
+ end
338
+ it "requests the correct resource" do
339
+ @client.contributors("sferik")
340
+ a_get("/1.1/users/contributors.json").
341
+ with(:query => {:screen_name => "sferik"}).
342
+ should have_been_made
343
+ end
344
+ it "returns a user's contributors" do
345
+ contributors = @client.contributors("sferik")
346
+ contributors.should be_an Array
347
+ contributors.first.should be_a Twitter::User
348
+ contributors.first.name.should eq "Biz Stone"
349
+ end
350
+ end
351
+ context "without arguments passed" do
352
+ before do
353
+ stub_get("/1.1/account/verify_credentials.json").
354
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
355
+ stub_get("/1.1/users/contributors.json").
356
+ with(:query => {:screen_name => "sferik"}).
357
+ to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"})
358
+ end
359
+ it "requests the correct resource" do
360
+ @client.contributors
361
+ a_get("/1.1/users/contributors.json").
362
+ with(:query => {:screen_name => "sferik"}).
363
+ should have_been_made
364
+ end
365
+ it "returns a user's contributors" do
366
+ contributors = @client.contributors
367
+ contributors.should be_an Array
368
+ contributors.first.should be_a Twitter::User
369
+ contributors.first.name.should eq "Biz Stone"
370
+ end
371
+ end
372
+ end
373
+
374
+ describe "#following_followers_of" do
375
+ context "with a screen_name passed" do
376
+ before do
377
+ stub_get("/users/following_followers_of.json").
378
+ with(:query => {:cursor => "-1", :screen_name => "sferik"}).
379
+ to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
380
+ end
381
+ it "requests the correct resource" do
382
+ @client.following_followers_of("sferik")
383
+ a_get("/users/following_followers_of.json").
384
+ with(:query => {:cursor => "-1", :screen_name => "sferik"}).
385
+ should have_been_made
386
+ end
387
+ it "returns an array of numeric IDs for every user following the specified user" do
388
+ following_followers_of = @client.following_followers_of("sferik")
389
+ following_followers_of.should be_a Twitter::Cursor
390
+ following_followers_of.users.should be_an Array
391
+ following_followers_of.users.first.should be_a Twitter::User
392
+ end
393
+ end
394
+ context "without arguments passed" do
395
+ before do
396
+ stub_get("/1.1/account/verify_credentials.json").
397
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
398
+ stub_get("/users/following_followers_of.json").
399
+ with(:query => {:cursor => "-1", :screen_name => "sferik"}).
400
+ to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
401
+ end
402
+ it "requests the correct resource" do
403
+ @client.following_followers_of
404
+ a_get("/1.1/account/verify_credentials.json").
405
+ should have_been_made
406
+ a_get("/users/following_followers_of.json").
407
+ with(:query => {:cursor => "-1", :screen_name => "sferik"}).
408
+ should have_been_made
409
+ end
410
+ it "returns an array of numeric IDs for every user following the specified user" do
411
+ following_followers_of = @client.following_followers_of
412
+ following_followers_of.should be_a Twitter::Cursor
413
+ following_followers_of.users.should be_an Array
414
+ following_followers_of.users.first.should be_a Twitter::User
415
+ end
416
+ end
417
+ end
418
+
419
+ end