ifttt-twitter 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +9 -0
  5. data/.yardopts +8 -0
  6. data/Gemfile +7 -0
  7. data/HISTORY.md +520 -0
  8. data/LICENSE.md +20 -0
  9. data/README.md +251 -0
  10. data/Rakefile +13 -0
  11. data/lib/twitter.rb +24 -0
  12. data/lib/twitter/action.rb +9 -0
  13. data/lib/twitter/action_factory.rb +28 -0
  14. data/lib/twitter/authenticatable.rb +24 -0
  15. data/lib/twitter/base.rb +40 -0
  16. data/lib/twitter/client.rb +126 -0
  17. data/lib/twitter/client/accounts.rb +180 -0
  18. data/lib/twitter/client/activity.rb +48 -0
  19. data/lib/twitter/client/block.rb +104 -0
  20. data/lib/twitter/client/direct_messages.rb +110 -0
  21. data/lib/twitter/client/favorites.rb +82 -0
  22. data/lib/twitter/client/friends_and_followers.rb +293 -0
  23. data/lib/twitter/client/help.rb +38 -0
  24. data/lib/twitter/client/legal.rb +32 -0
  25. data/lib/twitter/client/lists.rb +643 -0
  26. data/lib/twitter/client/local_trends.rb +46 -0
  27. data/lib/twitter/client/notification.rb +49 -0
  28. data/lib/twitter/client/places_and_geo.rb +113 -0
  29. data/lib/twitter/client/saved_searches.rb +73 -0
  30. data/lib/twitter/client/search.rb +94 -0
  31. data/lib/twitter/client/spam_reporting.rb +30 -0
  32. data/lib/twitter/client/suggested_users.rb +60 -0
  33. data/lib/twitter/client/timelines.rb +265 -0
  34. data/lib/twitter/client/trends.rb +55 -0
  35. data/lib/twitter/client/tweets.rb +191 -0
  36. data/lib/twitter/client/urls.rb +26 -0
  37. data/lib/twitter/client/users.rb +203 -0
  38. data/lib/twitter/config.rb +106 -0
  39. data/lib/twitter/configuration.rb +20 -0
  40. data/lib/twitter/connection.rb +43 -0
  41. data/lib/twitter/core_ext/hash.rb +81 -0
  42. data/lib/twitter/creatable.rb +14 -0
  43. data/lib/twitter/cursor.rb +44 -0
  44. data/lib/twitter/direct_message.rb +27 -0
  45. data/lib/twitter/error.rb +37 -0
  46. data/lib/twitter/error/bad_gateway.rb +7 -0
  47. data/lib/twitter/error/bad_request.rb +7 -0
  48. data/lib/twitter/error/client_error.rb +7 -0
  49. data/lib/twitter/error/enhance_your_calm.rb +13 -0
  50. data/lib/twitter/error/forbidden.rb +7 -0
  51. data/lib/twitter/error/internal_server_error.rb +7 -0
  52. data/lib/twitter/error/not_acceptable.rb +7 -0
  53. data/lib/twitter/error/not_found.rb +7 -0
  54. data/lib/twitter/error/server_error.rb +7 -0
  55. data/lib/twitter/error/service_unavailable.rb +7 -0
  56. data/lib/twitter/error/unauthorized.rb +7 -0
  57. data/lib/twitter/favorite.rb +28 -0
  58. data/lib/twitter/follow.rb +27 -0
  59. data/lib/twitter/geo_factory.rb +22 -0
  60. data/lib/twitter/language.rb +7 -0
  61. data/lib/twitter/list.rb +22 -0
  62. data/lib/twitter/list_member_added.rb +36 -0
  63. data/lib/twitter/media_factory.rb +21 -0
  64. data/lib/twitter/mention.rb +43 -0
  65. data/lib/twitter/metadata.rb +7 -0
  66. data/lib/twitter/oembed.rb +8 -0
  67. data/lib/twitter/photo.rb +24 -0
  68. data/lib/twitter/place.rb +36 -0
  69. data/lib/twitter/point.rb +27 -0
  70. data/lib/twitter/polygon.rb +14 -0
  71. data/lib/twitter/rate_limit_status.rb +15 -0
  72. data/lib/twitter/relationship.rb +18 -0
  73. data/lib/twitter/reply.rb +36 -0
  74. data/lib/twitter/request.rb +38 -0
  75. data/lib/twitter/request/gateway.rb +20 -0
  76. data/lib/twitter/request/multipart_with_file.rb +37 -0
  77. data/lib/twitter/request/oauth.rb +26 -0
  78. data/lib/twitter/request/phoenix.rb +22 -0
  79. data/lib/twitter/response/parse_json.rb +28 -0
  80. data/lib/twitter/response/raise_client_error.rb +49 -0
  81. data/lib/twitter/response/raise_server_error.rb +23 -0
  82. data/lib/twitter/retweet.rb +36 -0
  83. data/lib/twitter/saved_search.rb +16 -0
  84. data/lib/twitter/settings.rb +17 -0
  85. data/lib/twitter/size.rb +16 -0
  86. data/lib/twitter/status.rb +80 -0
  87. data/lib/twitter/suggestion.rb +22 -0
  88. data/lib/twitter/trend.rb +14 -0
  89. data/lib/twitter/user.rb +65 -0
  90. data/lib/twitter/version.rb +30 -0
  91. data/spec/faraday/request_spec.rb +25 -0
  92. data/spec/faraday/response_spec.rb +68 -0
  93. data/spec/fixtures/about_me.json +1 -0
  94. data/spec/fixtures/all.json +1 -0
  95. data/spec/fixtures/bad_gateway.json +1 -0
  96. data/spec/fixtures/bad_request.json +1 -0
  97. data/spec/fixtures/by_friends.json +1 -0
  98. data/spec/fixtures/category.json +1 -0
  99. data/spec/fixtures/configuration.json +1 -0
  100. data/spec/fixtures/contributees.json +1 -0
  101. data/spec/fixtures/contributors.json +1 -0
  102. data/spec/fixtures/direct_message.json +1 -0
  103. data/spec/fixtures/direct_messages.json +1 -0
  104. data/spec/fixtures/end_session.json +1 -0
  105. data/spec/fixtures/enhance_your_calm.text +11 -0
  106. data/spec/fixtures/false.json +1 -0
  107. data/spec/fixtures/favorites.json +1 -0
  108. data/spec/fixtures/forbidden.json +1 -0
  109. data/spec/fixtures/friendships.json +1 -0
  110. data/spec/fixtures/id_list.json +1 -0
  111. data/spec/fixtures/ids.json +1 -0
  112. data/spec/fixtures/image_facets.json +1 -0
  113. data/spec/fixtures/internal_server_error.json +1 -0
  114. data/spec/fixtures/languages.json +1 -0
  115. data/spec/fixtures/list.json +1 -0
  116. data/spec/fixtures/lists.json +1 -0
  117. data/spec/fixtures/locations.json +1 -0
  118. data/spec/fixtures/matching_trends.json +1 -0
  119. data/spec/fixtures/me.jpeg +0 -0
  120. data/spec/fixtures/media_timeline.json +1 -0
  121. data/spec/fixtures/members.json +1 -0
  122. data/spec/fixtures/n605431196_2079896_558_normal.jpg +0 -0
  123. data/spec/fixtures/no_user_matches.json +1 -0
  124. data/spec/fixtures/not_acceptable.json +1 -0
  125. data/spec/fixtures/not_found.json +1 -0
  126. data/spec/fixtures/oembed.json +1 -0
  127. data/spec/fixtures/pengwynn.json +1 -0
  128. data/spec/fixtures/phoenix_search.phoenix +1 -0
  129. data/spec/fixtures/place.json +1 -0
  130. data/spec/fixtures/places.json +1 -0
  131. data/spec/fixtures/privacy.json +1 -0
  132. data/spec/fixtures/profile_image.text +24 -0
  133. data/spec/fixtures/rate_limit_status.json +1 -0
  134. data/spec/fixtures/recommendations.json +1 -0
  135. data/spec/fixtures/relationship.json +1 -0
  136. data/spec/fixtures/resolve.json +1 -0
  137. data/spec/fixtures/retweet.json +1 -0
  138. data/spec/fixtures/retweeters_of.json +1 -0
  139. data/spec/fixtures/retweets.json +1 -0
  140. data/spec/fixtures/saved_search.json +1 -0
  141. data/spec/fixtures/saved_searches.json +1 -0
  142. data/spec/fixtures/search.json +1 -0
  143. data/spec/fixtures/service_unavailable.json +1 -0
  144. data/spec/fixtures/settings.json +1 -0
  145. data/spec/fixtures/sferik.json +1 -0
  146. data/spec/fixtures/status.json +1 -0
  147. data/spec/fixtures/status_with_media.json +104 -0
  148. data/spec/fixtures/statuses.json +1 -0
  149. data/spec/fixtures/suggestions.json +1 -0
  150. data/spec/fixtures/tos.json +1 -0
  151. data/spec/fixtures/totals.json +1 -0
  152. data/spec/fixtures/trends.json +1 -0
  153. data/spec/fixtures/trends_current.json +1 -0
  154. data/spec/fixtures/trends_daily.json +1 -0
  155. data/spec/fixtures/trends_weekly.json +1 -0
  156. data/spec/fixtures/true.json +1 -0
  157. data/spec/fixtures/unauthorized.json +1 -0
  158. data/spec/fixtures/user_search.json +1 -0
  159. data/spec/fixtures/user_timeline.json +1 -0
  160. data/spec/fixtures/users.json +1 -0
  161. data/spec/fixtures/users_list.json +1 -0
  162. data/spec/fixtures/video_facets.json +1 -0
  163. data/spec/fixtures/we_concept_bg2.png +0 -0
  164. data/spec/helper.rb +49 -0
  165. data/spec/twitter/action_factory_spec.rb +37 -0
  166. data/spec/twitter/action_spec.rb +16 -0
  167. data/spec/twitter/base_spec.rb +29 -0
  168. data/spec/twitter/client/accounts_spec.rb +181 -0
  169. data/spec/twitter/client/activity_spec.rb +43 -0
  170. data/spec/twitter/client/block_spec.rb +106 -0
  171. data/spec/twitter/client/direct_messages_spec.rb +98 -0
  172. data/spec/twitter/client/favorites_spec.rb +80 -0
  173. data/spec/twitter/client/friends_and_followers_spec.rb +478 -0
  174. data/spec/twitter/client/help_spec.rb +44 -0
  175. data/spec/twitter/client/legal_spec.rb +41 -0
  176. data/spec/twitter/client/lists_spec.rb +1104 -0
  177. data/spec/twitter/client/local_trends_spec.rb +58 -0
  178. data/spec/twitter/client/notification_spec.rb +47 -0
  179. data/spec/twitter/client/places_and_geo_spec.rb +100 -0
  180. data/spec/twitter/client/saved_searches_spec.rb +80 -0
  181. data/spec/twitter/client/search_spec.rb +92 -0
  182. data/spec/twitter/client/spam_reporting_spec.rb +28 -0
  183. data/spec/twitter/client/suggested_users_spec.rb +65 -0
  184. data/spec/twitter/client/timelines_spec.rb +231 -0
  185. data/spec/twitter/client/trends_spec.rb +51 -0
  186. data/spec/twitter/client/tweets_spec.rb +189 -0
  187. data/spec/twitter/client/urls_spec.rb +31 -0
  188. data/spec/twitter/client/users_spec.rb +323 -0
  189. data/spec/twitter/client_spec.rb +94 -0
  190. data/spec/twitter/configuration_spec.rb +17 -0
  191. data/spec/twitter/cursor_spec.rb +43 -0
  192. data/spec/twitter/direct_message_spec.rb +56 -0
  193. data/spec/twitter/favorite_spec.rb +29 -0
  194. data/spec/twitter/follow_spec.rb +29 -0
  195. data/spec/twitter/geo_factory_spec.rb +21 -0
  196. data/spec/twitter/list_spec.rb +34 -0
  197. data/spec/twitter/media_factory_spec.rb +17 -0
  198. data/spec/twitter/mention_spec.rb +52 -0
  199. data/spec/twitter/oembed_spec.rb +145 -0
  200. data/spec/twitter/photo_spec.rb +35 -0
  201. data/spec/twitter/place_spec.rb +75 -0
  202. data/spec/twitter/point_spec.rb +32 -0
  203. data/spec/twitter/polygon_spec.rb +18 -0
  204. data/spec/twitter/rate_limit_status_spec.rb +16 -0
  205. data/spec/twitter/relationship_spec.rb +27 -0
  206. data/spec/twitter/reply_spec.rb +41 -0
  207. data/spec/twitter/retweet_spec.rb +41 -0
  208. data/spec/twitter/saved_search_spec.rb +34 -0
  209. data/spec/twitter/settings_spec.rb +16 -0
  210. data/spec/twitter/size_spec.rb +18 -0
  211. data/spec/twitter/status_spec.rb +148 -0
  212. data/spec/twitter/suggestion_spec.rb +20 -0
  213. data/spec/twitter/trend_spec.rb +20 -0
  214. data/spec/twitter/user_spec.rb +50 -0
  215. data/spec/twitter_spec.rb +91 -0
  216. data/twitter.gemspec +42 -0
  217. metadata +564 -0
@@ -0,0 +1,478 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::Client do
4
+
5
+ before do
6
+ @client = Twitter::Client.new
7
+ end
8
+
9
+ describe ".follower_ids" do
10
+ context "with a screen_name passed" do
11
+ before do
12
+ stub_get("/1/followers/ids.json").
13
+ with(:query => {:screen_name => "sferik", :cursor => "-1"}).
14
+ to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
15
+ end
16
+ it "should request the correct resource" do
17
+ @client.follower_ids("sferik")
18
+ a_get("/1/followers/ids.json").
19
+ with(:query => {:screen_name => "sferik", :cursor => "-1"}).
20
+ should have_been_made
21
+ end
22
+ it "should return an array of numeric IDs for every user following the specified user" do
23
+ follower_ids = @client.follower_ids("sferik")
24
+ follower_ids.should be_a Twitter::Cursor
25
+ follower_ids.ids.should be_an Array
26
+ follower_ids.ids.first.should == 146197851
27
+ end
28
+ end
29
+ context "without arguments passed" do
30
+ before do
31
+ stub_get("/1/followers/ids.json").
32
+ with(:query => {:cursor => "-1"}).
33
+ to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
34
+ end
35
+ it "should request the correct resource" do
36
+ @client.follower_ids
37
+ a_get("/1/followers/ids.json").
38
+ with(:query => {:cursor => "-1"}).
39
+ should have_been_made
40
+ end
41
+ it "should return an array of numeric IDs for every user following the specified user" do
42
+ follower_ids = @client.follower_ids
43
+ follower_ids.should be_a Twitter::Cursor
44
+ follower_ids.ids.should be_an Array
45
+ follower_ids.ids.first.should == 146197851
46
+ end
47
+ end
48
+ end
49
+
50
+ describe ".friend_ids" do
51
+ context "with a screen_name passed" do
52
+ before do
53
+ stub_get("/1/friends/ids.json").
54
+ with(:query => {:screen_name => "sferik", :cursor => "-1"}).
55
+ to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
56
+ end
57
+ it "should request the correct resource" do
58
+ @client.friend_ids("sferik")
59
+ a_get("/1/friends/ids.json").
60
+ with(:query => {:screen_name => "sferik", :cursor => "-1"}).
61
+ should have_been_made
62
+ end
63
+ it "should return an array of numeric IDs for every user the specified user is following" do
64
+ friend_ids = @client.friend_ids("sferik")
65
+ friend_ids.should be_a Twitter::Cursor
66
+ friend_ids.ids.should be_an Array
67
+ friend_ids.ids.first.should == 146197851
68
+ end
69
+ end
70
+ context "without arguments passed" do
71
+ before do
72
+ stub_get("/1/friends/ids.json").
73
+ with(:query => {:cursor => "-1"}).
74
+ to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
75
+ end
76
+ it "should request the correct resource" do
77
+ @client.friend_ids
78
+ a_get("/1/friends/ids.json").
79
+ with(:query => {:cursor => "-1"}).
80
+ should have_been_made
81
+ end
82
+ it "should return an array of numeric IDs for every user the specified user is following" do
83
+ friend_ids = @client.friend_ids
84
+ friend_ids.should be_a Twitter::Cursor
85
+ friend_ids.ids.should be_an Array
86
+ friend_ids.ids.first.should == 146197851
87
+ end
88
+ end
89
+ end
90
+
91
+ describe ".friendship?" do
92
+ before do
93
+ stub_get("/1/friendships/exists.json").
94
+ with(:query => {:user_a => "sferik", :user_b => "pengwynn"}).
95
+ to_return(:body => fixture("true.json"), :headers => {:content_type => "application/json; charset=utf-8"})
96
+ stub_get("/1/friendships/exists.json").
97
+ with(:query => {:user_a => "pengwynn", :user_b => "sferik"}).
98
+ to_return(:body => fixture("false.json"), :headers => {:content_type => "application/json; charset=utf-8"})
99
+ end
100
+ it "should request the correct resource" do
101
+ @client.friendship?("sferik", "pengwynn")
102
+ a_get("/1/friendships/exists.json").
103
+ with(:query => {:user_a => "sferik", :user_b => "pengwynn"}).
104
+ should have_been_made
105
+ end
106
+ it "should return true if user_a follows user_b" do
107
+ friendship = @client.friendship?("sferik", "pengwynn")
108
+ friendship.should be_true
109
+ end
110
+ it "should return false if user_a does not follows user_b" do
111
+ friendship = @client.friendship?("pengwynn", "sferik")
112
+ friendship.should be_false
113
+ end
114
+ end
115
+
116
+ describe ".friendships_incoming" do
117
+ before do
118
+ stub_get("/1/friendships/incoming.json").
119
+ with(:query => {:cursor => "-1"}).
120
+ to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
121
+ end
122
+ it "should request the correct resource" do
123
+ @client.friendships_incoming
124
+ a_get("/1/friendships/incoming.json").
125
+ with(:query => {:cursor => "-1"}).
126
+ should have_been_made
127
+ end
128
+ it "should return an array of numeric IDs for every user who has a pending request to follow the authenticating user" do
129
+ friendships_incoming = @client.friendships_incoming
130
+ friendships_incoming.should be_a Twitter::Cursor
131
+ friendships_incoming.ids.should be_an Array
132
+ friendships_incoming.ids.first.should == 146197851
133
+ end
134
+ end
135
+
136
+ describe ".friendships_outgoing" do
137
+ before do
138
+ stub_get("/1/friendships/outgoing.json").
139
+ with(:query => {:cursor => "-1"}).
140
+ to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
141
+ end
142
+ it "should request the correct resource" do
143
+ @client.friendships_outgoing
144
+ a_get("/1/friendships/outgoing.json").
145
+ with(:query => {:cursor => "-1"}).
146
+ should have_been_made
147
+ end
148
+ it "should return an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request" do
149
+ friendships_outgoing = @client.friendships_outgoing
150
+ friendships_outgoing.should be_a Twitter::Cursor
151
+ friendships_outgoing.ids.should be_an Array
152
+ friendships_outgoing.ids.first.should == 146197851
153
+ end
154
+ end
155
+
156
+ describe ".friendship" do
157
+ context "with screen names passed" do
158
+ before do
159
+ stub_get("/1/friendships/show.json").
160
+ with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).
161
+ to_return(:body => fixture("relationship.json"), :headers => {:content_type => "application/json; charset=utf-8"})
162
+ end
163
+ it "should request the correct resource" do
164
+ @client.friendship("sferik", "pengwynn")
165
+ a_get("/1/friendships/show.json").
166
+ with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).
167
+ should have_been_made
168
+ end
169
+ it "should return detailed information about the relationship between two users" do
170
+ relationship = @client.friendship("sferik", "pengwynn")
171
+ relationship.should be_a Twitter::Relationship
172
+ relationship.source.screen_name.should == "sferik"
173
+ end
174
+ end
175
+ context "with numeric screen names passed" do
176
+ before do
177
+ stub_get("/1/friendships/show.json").
178
+ with(:query => {:source_screen_name => "0", :target_screen_name => "311"}).
179
+ to_return(:body => fixture("relationship.json"), :headers => {:content_type => "application/json; charset=utf-8"})
180
+ end
181
+ it "should request the correct resource" do
182
+ @client.friendship("0", "311")
183
+ a_get("/1/friendships/show.json").
184
+ with(:query => {:source_screen_name => "0", :target_screen_name => "311"}).
185
+ should have_been_made
186
+ end
187
+ end
188
+ context "with user IDs passed" do
189
+ before do
190
+ stub_get("/1/friendships/show.json").
191
+ with(:query => {:source_id => "7505382", :target_id => "14100886"}).
192
+ to_return(:body => fixture("relationship.json"), :headers => {:content_type => "application/json; charset=utf-8"})
193
+ end
194
+ it "should request the correct resource" do
195
+ @client.friendship(7505382, 14100886)
196
+ a_get("/1/friendships/show.json").
197
+ with(:query => {:source_id => "7505382", :target_id => "14100886"}).
198
+ should have_been_made
199
+ end
200
+ end
201
+ end
202
+
203
+ describe ".follow" do
204
+ context "with :follow => true passed" do
205
+ before do
206
+ stub_post("/1/friendships/create.json").
207
+ with(:body => {:screen_name => "sferik", :follow => "true"}).
208
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
209
+ end
210
+ it "should request the correct resource" do
211
+ @client.follow("sferik", :follow => true)
212
+ a_post("/1/friendships/create.json").
213
+ with(:body => {:screen_name => "sferik", :follow => "true"}).
214
+ should have_been_made
215
+ end
216
+ it "should return the befriended user" do
217
+ user = @client.follow("sferik", :follow => true)
218
+ user.should be_a Twitter::User
219
+ user.name.should == "Erik Michaels-Ober"
220
+ end
221
+ end
222
+ context "with :follow => false passed" do
223
+ before do
224
+ stub_post("/1/friendships/create.json").
225
+ with(:body => {:screen_name => "sferik"}).
226
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
227
+ end
228
+ it "should request the correct resource" do
229
+ @client.follow("sferik", :follow => false)
230
+ a_post("/1/friendships/create.json").
231
+ with(:body => {:screen_name => "sferik"}).
232
+ should have_been_made
233
+ end
234
+ it "should return the befriended user" do
235
+ user = @client.follow("sferik", :follow => false)
236
+ user.should be_a Twitter::User
237
+ user.name.should == "Erik Michaels-Ober"
238
+ end
239
+ end
240
+ context "without :follow passed" do
241
+ before do
242
+ stub_post("/1/friendships/create.json").
243
+ with(:body => {:screen_name => "sferik"}).
244
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
245
+ end
246
+ it "should request the correct resource" do
247
+ @client.follow("sferik")
248
+ a_post("/1/friendships/create.json").
249
+ with(:body => {:screen_name => "sferik"}).
250
+ should have_been_made
251
+ end
252
+ it "should return the befriended user" do
253
+ user = @client.follow("sferik")
254
+ user.should be_a Twitter::User
255
+ user.name.should == "Erik Michaels-Ober"
256
+ end
257
+ end
258
+ end
259
+
260
+ describe ".unfollow" do
261
+ before do
262
+ stub_delete("/1/friendships/destroy.json").
263
+ with(:query => {:screen_name => "sferik"}).
264
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
265
+ end
266
+ it "should request the correct resource" do
267
+ @client.unfollow("sferik")
268
+ a_delete("/1/friendships/destroy.json").
269
+ with(:query => {:screen_name => "sferik"}).
270
+ should have_been_made
271
+ end
272
+ it "should return the unfollowed" do
273
+ user = @client.friendship_destroy("sferik")
274
+ user.should be_a Twitter::User
275
+ user.name.should == "Erik Michaels-Ober"
276
+ end
277
+ end
278
+
279
+ describe ".friendships" do
280
+ context "with screen names passed" do
281
+ before do
282
+ stub_get("/1/friendships/lookup.json").
283
+ with(:query => {:screen_name => "sferik,pengwynn"}).
284
+ to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
285
+ end
286
+ it "should request the correct resource" do
287
+ @client.friendships("sferik", "pengwynn")
288
+ a_get("/1/friendships/lookup.json").
289
+ with(:query => {:screen_name => "sferik,pengwynn"}).
290
+ should have_been_made
291
+ end
292
+ it "should return up to 100 users worth of extended information" do
293
+ friendships = @client.friendships("sferik", "pengwynn")
294
+ friendships.should be_an Array
295
+ friendships.first.should be_a Twitter::User
296
+ friendships.first.name.should == "Erik Michaels-Ober"
297
+ friendships.first.connections.should == ["none"]
298
+ end
299
+ end
300
+ context "with numeric screen names passed" do
301
+ before do
302
+ stub_get("/1/friendships/lookup.json").
303
+ with(:query => {:screen_name => "0,311"}).
304
+ to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
305
+ end
306
+ it "should request the correct resource" do
307
+ @client.friendships("0", "311")
308
+ a_get("/1/friendships/lookup.json").
309
+ with(:query => {:screen_name => "0,311"}).
310
+ should have_been_made
311
+ end
312
+ end
313
+ context "with user IDs passed" do
314
+ before do
315
+ stub_get("/1/friendships/lookup.json").
316
+ with(:query => {:user_id => "7505382,14100886"}).
317
+ to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
318
+ end
319
+ it "should request the correct resource" do
320
+ @client.friendships(7505382, 14100886)
321
+ a_get("/1/friendships/lookup.json").
322
+ with(:query => {:user_id => "7505382,14100886"}).
323
+ should have_been_made
324
+ end
325
+ end
326
+ context "with both screen names and user IDs passed" do
327
+ before do
328
+ stub_get("/1/friendships/lookup.json").
329
+ with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
330
+ to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
331
+ end
332
+ it "should request the correct resource" do
333
+ @client.friendships("sferik", 14100886)
334
+ a_get("/1/friendships/lookup.json").
335
+ with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
336
+ should have_been_made
337
+ end
338
+ end
339
+ end
340
+
341
+ describe ".friendships" do
342
+ context "with screen names passed" do
343
+ before do
344
+ stub_get("/1/friendships/lookup.json").
345
+ with(:query => {:screen_name => "sferik,pengwynn"}).
346
+ to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
347
+ end
348
+ it "should request the correct resource" do
349
+ @client.friendships("sferik", "pengwynn")
350
+ a_get("/1/friendships/lookup.json").
351
+ with(:query => {:screen_name => "sferik,pengwynn"}).
352
+ should have_been_made
353
+ end
354
+ it "should return up to 100 users worth of extended information" do
355
+ friendships = @client.friendships("sferik", "pengwynn")
356
+ friendships.should be_an Array
357
+ friendships.first.should be_a Twitter::User
358
+ friendships.first.name.should == "Erik Michaels-Ober"
359
+ friendships.first.connections.should == ["none"]
360
+ end
361
+ end
362
+ context "with numeric screen names passed" do
363
+ before do
364
+ stub_get("/1/friendships/lookup.json").
365
+ with(:query => {:screen_name => "0,311"}).
366
+ to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
367
+ end
368
+ it "should request the correct resource" do
369
+ @client.friendships("0", "311")
370
+ a_get("/1/friendships/lookup.json").
371
+ with(:query => {:screen_name => "0,311"}).
372
+ should have_been_made
373
+ end
374
+ end
375
+ context "with user IDs passed" do
376
+ before do
377
+ stub_get("/1/friendships/lookup.json").
378
+ with(:query => {:user_id => "7505382,14100886"}).
379
+ to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
380
+ end
381
+ it "should request the correct resource" do
382
+ @client.friendships(7505382, 14100886)
383
+ a_get("/1/friendships/lookup.json").
384
+ with(:query => {:user_id => "7505382,14100886"}).
385
+ should have_been_made
386
+ end
387
+ end
388
+ context "with both screen names and user IDs passed" do
389
+ before do
390
+ stub_get("/1/friendships/lookup.json").
391
+ with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
392
+ to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
393
+ end
394
+ it "should request the correct resource" do
395
+ @client.friendships("sferik", 14100886)
396
+ a_get("/1/friendships/lookup.json").
397
+ with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
398
+ should have_been_made
399
+ end
400
+ end
401
+ end
402
+
403
+ describe ".friendship_update" do
404
+ before do
405
+ stub_post("/1/friendships/update.json").
406
+ with(:body => {:screen_name => "sferik", :retweets => "true"}).
407
+ to_return(:body => fixture("relationship.json"), :headers => {:content_type => "application/json; charset=utf-8"})
408
+ end
409
+ it "should request the correct resource" do
410
+ @client.friendship_update("sferik", :retweets => true)
411
+ a_post("/1/friendships/update.json").
412
+ with(:body => {:screen_name => "sferik", :retweets => "true"}).
413
+ should have_been_made
414
+ end
415
+ it "should return detailed information about the relationship between two users" do
416
+ relationship = @client.friendship_update("sferik", :retweets => true)
417
+ relationship.should be_a Twitter::Relationship
418
+ relationship.source.screen_name.should == "sferik"
419
+ end
420
+ end
421
+
422
+ describe ".no_retweet_ids" do
423
+ before do
424
+ stub_get("/1/friendships/no_retweet_ids.json").
425
+ to_return(:body => fixture("ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
426
+ end
427
+ it "should request the correct resource" do
428
+ @client.no_retweet_ids
429
+ a_get("/1/friendships/no_retweet_ids.json").
430
+ should have_been_made
431
+ end
432
+ it "should return detailed information about the relationship between two users" do
433
+ no_retweet_ids = @client.no_retweet_ids
434
+ no_retweet_ids.should be_an Array
435
+ no_retweet_ids.first.should be_an Integer
436
+ no_retweet_ids.first.should == 47
437
+ end
438
+ end
439
+
440
+ describe ".accept" do
441
+ before do
442
+ stub_post("/1/friendships/accept.json").
443
+ with(:body => {:screen_name => "sferik"}).
444
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
445
+ end
446
+ it "should request the correct resource" do
447
+ @client.accept("sferik")
448
+ a_post("/1/friendships/accept.json").
449
+ with(:body => {:screen_name => "sferik"}).
450
+ should have_been_made
451
+ end
452
+ it "should return the accepted user" do
453
+ user = @client.accept("sferik")
454
+ user.should be_a Twitter::User
455
+ user.name.should == "Erik Michaels-Ober"
456
+ end
457
+ end
458
+
459
+ describe ".deny" do
460
+ before do
461
+ stub_post("/1/friendships/deny.json").
462
+ with(:body => {:screen_name => "sferik"}).
463
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
464
+ end
465
+ it "should request the correct resource" do
466
+ @client.deny("sferik")
467
+ a_post("/1/friendships/deny.json").
468
+ with(:body => {:screen_name => "sferik"}).
469
+ should have_been_made
470
+ end
471
+ it "should return the denied user" do
472
+ user = @client.deny("sferik")
473
+ user.should be_a Twitter::User
474
+ user.name.should == "Erik Michaels-Ober"
475
+ end
476
+ end
477
+
478
+ end