twitter 4.2.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/twitter/api/direct_messages.rb +150 -0
- data/lib/twitter/api/favorites.rb +132 -0
- data/lib/twitter/api/friends_and_followers.rb +259 -0
- data/lib/twitter/api/help.rb +64 -0
- data/lib/twitter/api/lists.rb +570 -0
- data/lib/twitter/api/places_and_geo.rb +121 -0
- data/lib/twitter/api/saved_searches.rb +98 -0
- data/lib/twitter/api/search.rb +37 -0
- data/lib/twitter/api/spam_reporting.rb +30 -0
- data/lib/twitter/api/suggested_users.rb +54 -0
- data/lib/twitter/api/timelines.rb +213 -0
- data/lib/twitter/api/trends.rb +63 -0
- data/lib/twitter/api/tweets.rb +284 -0
- data/lib/twitter/api/undocumented.rb +116 -0
- data/lib/twitter/api/users.rb +427 -0
- data/lib/twitter/api/utils.rb +111 -0
- data/lib/twitter/client.rb +41 -13
- data/lib/twitter/core_ext/enumerable.rb +1 -1
- data/lib/twitter/default.rb +16 -18
- data/lib/twitter/error/already_favorited.rb +1 -1
- data/lib/twitter/error/already_retweeted.rb +1 -1
- data/lib/twitter/profile_banner.rb +18 -0
- data/lib/twitter/version.rb +1 -1
- data/spec/fixtures/profile_banner.json +1 -0
- data/spec/twitter/api/direct_messages_spec.rb +32 -32
- data/spec/twitter/api/favorites_spec.rb +114 -0
- data/spec/twitter/api/{friendships_spec.rb → friends_and_followers_spec.rb} +146 -146
- data/spec/twitter/api/geo_spec.rb +28 -28
- data/spec/twitter/api/help_spec.rb +1 -1
- data/spec/twitter/api/lists_spec.rb +82 -82
- data/spec/twitter/api/saved_searches_spec.rb +1 -1
- data/spec/twitter/api/search_spec.rb +1 -17
- data/spec/twitter/api/{report_spam_spec.rb → spam_reporting_spec.rb} +1 -1
- data/spec/twitter/api/suggested_users_spec.rb +94 -0
- data/spec/twitter/api/timelines_spec.rb +138 -0
- data/spec/twitter/api/trends_spec.rb +1 -1
- data/spec/twitter/api/tweets_spec.rb +249 -0
- data/spec/twitter/api/undocumented_spec.rb +103 -0
- data/spec/twitter/api/users_spec.rb +308 -17
- data/spec/twitter/client_spec.rb +1 -1
- data/spec/twitter/profile_banner_spec.rb +13 -0
- data/twitter.gemspec +3 -2
- metadata +44 -21
- data/lib/twitter/api.rb +0 -2558
- data/spec/twitter/api/account_spec.rb +0 -152
- data/spec/twitter/api/activity_spec.rb +0 -37
- data/spec/twitter/api/blocks_spec.rb +0 -122
- data/spec/twitter/api/statuses_spec.rb +0 -541
@@ -0,0 +1,249 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::API::Tweets do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#retweets" do
|
10
|
+
before do
|
11
|
+
stub_get("/1.1/statuses/retweets/28561922516.json").to_return(:body => fixture("retweets.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
12
|
+
end
|
13
|
+
it "requests the correct resource" do
|
14
|
+
@client.retweets(28561922516)
|
15
|
+
expect(a_get("/1.1/statuses/retweets/28561922516.json")).to have_been_made
|
16
|
+
end
|
17
|
+
it "returns up to 100 of the first retweets of a given tweet" do
|
18
|
+
tweets = @client.retweets(28561922516)
|
19
|
+
expect(tweets).to be_an Array
|
20
|
+
expect(tweets.first).to be_a Twitter::Tweet
|
21
|
+
expect(tweets.first.text).to eq "RT @gruber: As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#retweeters_of" do
|
26
|
+
context "with ids_only passed" do
|
27
|
+
before do
|
28
|
+
stub_get("/1.1/statuses/retweets/28561922516.json").to_return(:body => fixture("retweets.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
29
|
+
end
|
30
|
+
it "requests the correct resource" do
|
31
|
+
@client.retweeters_of(28561922516, :ids_only => true)
|
32
|
+
expect(a_get("/1.1/statuses/retweets/28561922516.json")).to have_been_made
|
33
|
+
end
|
34
|
+
it "returns an array of numeric user IDs of retweeters of a Tweet" do
|
35
|
+
ids = @client.retweeters_of(28561922516, :ids_only => true)
|
36
|
+
expect(ids).to be_an Array
|
37
|
+
expect(ids.first).to eq 7505382
|
38
|
+
end
|
39
|
+
end
|
40
|
+
context "without ids_only passed" do
|
41
|
+
before do
|
42
|
+
stub_get("/1.1/statuses/retweets/28561922516.json").to_return(:body => fixture("retweets.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
43
|
+
end
|
44
|
+
it "requests the correct resource" do
|
45
|
+
@client.retweeters_of(28561922516)
|
46
|
+
expect(a_get("/1.1/statuses/retweets/28561922516.json")).to have_been_made
|
47
|
+
end
|
48
|
+
it "returns an array of user of retweeters of a Tweet" do
|
49
|
+
users = @client.retweeters_of(28561922516)
|
50
|
+
expect(users).to be_an Array
|
51
|
+
expect(users.first).to be_a Twitter::User
|
52
|
+
expect(users.first.id).to eq 7505382
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#status" do
|
58
|
+
before do
|
59
|
+
stub_get("/1.1/statuses/show/25938088801.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
60
|
+
end
|
61
|
+
it "requests the correct resource" do
|
62
|
+
@client.status(25938088801)
|
63
|
+
expect(a_get("/1.1/statuses/show/25938088801.json")).to have_been_made
|
64
|
+
end
|
65
|
+
it "returns a Tweet" do
|
66
|
+
tweet = @client.status(25938088801)
|
67
|
+
expect(tweet).to be_a Twitter::Tweet
|
68
|
+
expect(tweet.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#statuses" do
|
73
|
+
before do
|
74
|
+
stub_get("/1.1/statuses/show/25938088801.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
75
|
+
end
|
76
|
+
it "requests the correct resource" do
|
77
|
+
@client.statuses(25938088801)
|
78
|
+
expect(a_get("/1.1/statuses/show/25938088801.json")).to have_been_made
|
79
|
+
end
|
80
|
+
it "returns an array of Tweets" do
|
81
|
+
tweets = @client.statuses(25938088801)
|
82
|
+
expect(tweets).to be_an Array
|
83
|
+
expect(tweets.first).to be_a Twitter::Tweet
|
84
|
+
expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#status_destroy" do
|
89
|
+
before do
|
90
|
+
stub_post("/1.1/statuses/destroy/25938088801.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
91
|
+
end
|
92
|
+
it "requests the correct resource" do
|
93
|
+
@client.status_destroy(25938088801)
|
94
|
+
expect(a_post("/1.1/statuses/destroy/25938088801.json")).to have_been_made
|
95
|
+
end
|
96
|
+
it "returns an array of Tweets" do
|
97
|
+
tweets = @client.status_destroy(25938088801)
|
98
|
+
expect(tweets).to be_an Array
|
99
|
+
expect(tweets.first).to be_a Twitter::Tweet
|
100
|
+
expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#tweet" do
|
105
|
+
before do
|
106
|
+
stub_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do."}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
107
|
+
end
|
108
|
+
it "requests the correct resource" do
|
109
|
+
@client.update("The problem with your code is that it's doing exactly what you told it to do.")
|
110
|
+
expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do."})).to have_been_made
|
111
|
+
end
|
112
|
+
it "returns a Tweet" do
|
113
|
+
tweet = @client.update("The problem with your code is that it's doing exactly what you told it to do.")
|
114
|
+
expect(tweet).to be_a Twitter::Tweet
|
115
|
+
expect(tweet.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#retweet" do
|
120
|
+
before do
|
121
|
+
stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:body => fixture("retweet.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
122
|
+
end
|
123
|
+
it "requests the correct resource" do
|
124
|
+
@client.retweet(28561922516)
|
125
|
+
expect(a_post("/1.1/statuses/retweet/28561922516.json")).to have_been_made
|
126
|
+
end
|
127
|
+
it "returns an array of Tweets with retweet details embedded" do
|
128
|
+
tweets = @client.retweet(28561922516)
|
129
|
+
expect(tweets).to be_an Array
|
130
|
+
expect(tweets.first).to be_a Twitter::Tweet
|
131
|
+
expect(tweets.first.text).to eq "As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
|
132
|
+
expect(tweets.first.retweeted_tweet.text).to eq "RT @gruber: As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
|
133
|
+
expect(tweets.first.retweeted_tweet.id).not_to eq tweets.first.id
|
134
|
+
end
|
135
|
+
context "already retweeted" do
|
136
|
+
before do
|
137
|
+
stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:status => 403, :body => fixture("already_retweeted.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
138
|
+
end
|
139
|
+
it "does not raise an error" do
|
140
|
+
expect{@client.retweet(28561922516)}.not_to raise_error
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#retweet!" do
|
146
|
+
before do
|
147
|
+
stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:body => fixture("retweet.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
148
|
+
end
|
149
|
+
it "requests the correct resource" do
|
150
|
+
@client.retweet!(28561922516)
|
151
|
+
expect(a_post("/1.1/statuses/retweet/28561922516.json")).to have_been_made
|
152
|
+
end
|
153
|
+
it "returns an array of Tweets with retweet details embedded" do
|
154
|
+
tweets = @client.retweet!(28561922516)
|
155
|
+
expect(tweets).to be_an Array
|
156
|
+
expect(tweets.first).to be_a Twitter::Tweet
|
157
|
+
expect(tweets.first.text).to eq "As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
|
158
|
+
expect(tweets.first.retweeted_tweet.text).to eq "RT @gruber: As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
|
159
|
+
expect(tweets.first.retweeted_tweet.id).not_to eq tweets.first.id
|
160
|
+
end
|
161
|
+
context "fobidden" do
|
162
|
+
before do
|
163
|
+
stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:status => 403, :headers => {:content_type => "application/json; charset=utf-8"})
|
164
|
+
end
|
165
|
+
it "raises a Forbidden error" do
|
166
|
+
expect{@client.retweet!(28561922516)}.to raise_error(Twitter::Error::Forbidden)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
context "already retweeted" do
|
170
|
+
before do
|
171
|
+
stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:status => 403, :body => fixture("already_retweeted.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
172
|
+
end
|
173
|
+
it "raises an AlreadyRetweeted error" do
|
174
|
+
expect{@client.retweet!(28561922516)}.to raise_error(Twitter::Error::AlreadyRetweeted, "Tweet with the ID 28561922516 has already been retweeted by the authenticated user.")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "#update_with_media" do
|
180
|
+
before do
|
181
|
+
stub_post("/1.1/statuses/update_with_media.json").to_return(:body => fixture("status_with_media.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
182
|
+
end
|
183
|
+
context "a gif image" do
|
184
|
+
it "requests the correct resource" do
|
185
|
+
@client.update_with_media("You always have options", fixture("pbjt.gif"))
|
186
|
+
expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
|
187
|
+
end
|
188
|
+
it "returns a Tweet" do
|
189
|
+
tweet = @client.update_with_media("You always have options", fixture("pbjt.gif"))
|
190
|
+
expect(tweet).to be_a Twitter::Tweet
|
191
|
+
expect(tweet.text).to eq "You always have options http://t.co/CBYa7Ri"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
context "a jpe image" do
|
195
|
+
it "requests the correct resource" do
|
196
|
+
@client.update_with_media("You always have options", fixture("wildcomet2.jpe"))
|
197
|
+
expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
|
198
|
+
end
|
199
|
+
end
|
200
|
+
context "a jpeg image" do
|
201
|
+
it "requests the correct resource" do
|
202
|
+
@client.update_with_media("You always have options", fixture("me.jpeg"))
|
203
|
+
expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
|
204
|
+
end
|
205
|
+
end
|
206
|
+
context "a png image" do
|
207
|
+
it "requests the correct resource" do
|
208
|
+
@client.update_with_media("You always have options", fixture("we_concept_bg2.png"))
|
209
|
+
expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
|
210
|
+
end
|
211
|
+
end
|
212
|
+
context "a Tempfile" do
|
213
|
+
it "requests the correct resource" do
|
214
|
+
@client.update_with_media("You always have options", Tempfile.new("tmp"))
|
215
|
+
expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "#oembed" do
|
221
|
+
before do
|
222
|
+
stub_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"}).to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
223
|
+
end
|
224
|
+
it "requests the correct resource" do
|
225
|
+
@client.oembed(25938088801)
|
226
|
+
expect(a_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"})).to have_been_made
|
227
|
+
end
|
228
|
+
it "returns an array of OEmbed instances" do
|
229
|
+
oembed = @client.oembed(25938088801)
|
230
|
+
expect(oembed).to be_a Twitter::OEmbed
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "#oembeds" do
|
235
|
+
before do
|
236
|
+
stub_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"}).to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
237
|
+
end
|
238
|
+
it "requests the correct resource" do
|
239
|
+
@client.oembeds(25938088801)
|
240
|
+
expect(a_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"})).to have_been_made
|
241
|
+
end
|
242
|
+
it "returns an array of OEmbed instances" do
|
243
|
+
oembeds = @client.oembeds(25938088801)
|
244
|
+
expect(oembeds).to be_an Array
|
245
|
+
expect(oembeds.first).to be_a Twitter::OEmbed
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::API::Undocumented do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#activity_about_me" do
|
10
|
+
before do
|
11
|
+
stub_get("/i/activity/about_me.json").to_return(:body => fixture("about_me.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
12
|
+
end
|
13
|
+
it "requests the correct resource" do
|
14
|
+
@client.activity_about_me
|
15
|
+
expect(a_get("/i/activity/about_me.json")).to have_been_made
|
16
|
+
end
|
17
|
+
it "returns activity about me" do
|
18
|
+
activity_about_me = @client.activity_about_me
|
19
|
+
expect(activity_about_me.first).to be_a Twitter::Action::Mention
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#activity_by_friends" do
|
24
|
+
before do
|
25
|
+
stub_get("/i/activity/by_friends.json").to_return(:body => fixture("by_friends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
26
|
+
end
|
27
|
+
it "requests the correct resource" do
|
28
|
+
@client.activity_by_friends
|
29
|
+
expect(a_get("/i/activity/by_friends.json")).to have_been_made
|
30
|
+
end
|
31
|
+
it "returns activity by friends" do
|
32
|
+
activity_by_friends = @client.activity_by_friends
|
33
|
+
expect(activity_by_friends.first).to be_a Twitter::Action::Favorite
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#following_followers_of" do
|
38
|
+
context "with a screen_name passed" do
|
39
|
+
before do
|
40
|
+
stub_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
41
|
+
end
|
42
|
+
it "requests the correct resource" do
|
43
|
+
@client.following_followers_of("sferik")
|
44
|
+
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
|
45
|
+
end
|
46
|
+
it "returns an array of numeric IDs for every user following the specified user" do
|
47
|
+
following_followers_of = @client.following_followers_of("sferik")
|
48
|
+
expect(following_followers_of).to be_a Twitter::Cursor
|
49
|
+
expect(following_followers_of.users).to be_an Array
|
50
|
+
expect(following_followers_of.users.first).to be_a Twitter::User
|
51
|
+
end
|
52
|
+
end
|
53
|
+
context "without arguments passed" do
|
54
|
+
before do
|
55
|
+
stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
56
|
+
stub_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
57
|
+
end
|
58
|
+
it "requests the correct resource" do
|
59
|
+
@client.following_followers_of
|
60
|
+
expect(a_get("/1.1/account/verify_credentials.json")).to have_been_made
|
61
|
+
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
|
62
|
+
end
|
63
|
+
it "returns an array of numeric IDs for every user following the specified user" do
|
64
|
+
following_followers_of = @client.following_followers_of
|
65
|
+
expect(following_followers_of).to be_a Twitter::Cursor
|
66
|
+
expect(following_followers_of.users).to be_an Array
|
67
|
+
expect(following_followers_of.users.first).to be_a Twitter::User
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#status_activity" do
|
73
|
+
before do
|
74
|
+
stub_get("/i/statuses/25938088801/activity/summary.json").to_return(:body => fixture("activity_summary.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
75
|
+
end
|
76
|
+
it "requests the correct resource" do
|
77
|
+
@client.status_activity(25938088801)
|
78
|
+
expect(a_get("/i/statuses/25938088801/activity/summary.json")).to have_been_made
|
79
|
+
end
|
80
|
+
it "returns a Tweet" do
|
81
|
+
tweet = @client.status_activity(25938088801)
|
82
|
+
expect(tweet).to be_a Twitter::Tweet
|
83
|
+
expect(tweet.retweeters_count).to eq 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#statuses_activity" do
|
88
|
+
before do
|
89
|
+
stub_get("/i/statuses/25938088801/activity/summary.json").to_return(:body => fixture("activity_summary.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
90
|
+
end
|
91
|
+
it "requests the correct resource" do
|
92
|
+
@client.statuses_activity(25938088801)
|
93
|
+
expect(a_get("/i/statuses/25938088801/activity/summary.json")).to have_been_made
|
94
|
+
end
|
95
|
+
it "returns an array of Tweets" do
|
96
|
+
tweets = @client.statuses_activity(25938088801)
|
97
|
+
expect(tweets).to be_an Array
|
98
|
+
expect(tweets.first).to be_a Twitter::Tweet
|
99
|
+
expect(tweets.first.retweeters_count).to eq 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -1,11 +1,126 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
describe Twitter::API do
|
3
|
+
describe Twitter::API::Users do
|
4
4
|
|
5
5
|
before do
|
6
6
|
@client = Twitter::Client.new
|
7
7
|
end
|
8
8
|
|
9
|
+
describe "#settings" do
|
10
|
+
before do
|
11
|
+
stub_get("/1.1/account/settings.json").to_return(:body => fixture("settings.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
12
|
+
stub_post("/1.1/account/settings.json").with(:body => {:trend_location_woeid => "23424803"}).to_return(:body => fixture("settings.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
13
|
+
end
|
14
|
+
it "requests the correct resource on GET" do
|
15
|
+
@client.settings
|
16
|
+
expect(a_get("/1.1/account/settings.json")).to have_been_made
|
17
|
+
end
|
18
|
+
it "returns settings" do
|
19
|
+
settings = @client.settings
|
20
|
+
expect(settings).to be_a Twitter::Settings
|
21
|
+
expect(settings.language).to eq 'en'
|
22
|
+
end
|
23
|
+
it "requests the correct resource on POST" do
|
24
|
+
@client.settings(:trend_location_woeid => "23424803")
|
25
|
+
expect(a_post("/1.1/account/settings.json").with(:body => {:trend_location_woeid => "23424803"})).to have_been_made
|
26
|
+
end
|
27
|
+
it "returns settings" do
|
28
|
+
settings = @client.settings(:trend_location_woeid => "23424803")
|
29
|
+
expect(settings).to be_a Twitter::Settings
|
30
|
+
expect(settings.language).to eq 'en'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#verify_credentials" do
|
35
|
+
before do
|
36
|
+
stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
37
|
+
end
|
38
|
+
it "requests the correct resource" do
|
39
|
+
@client.verify_credentials
|
40
|
+
expect(a_get("/1.1/account/verify_credentials.json")).to have_been_made
|
41
|
+
end
|
42
|
+
it "returns the requesting user" do
|
43
|
+
user = @client.verify_credentials
|
44
|
+
expect(user).to be_a Twitter::User
|
45
|
+
expect(user.id).to eq 7505382
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#update_delivery_device" do
|
50
|
+
before do
|
51
|
+
stub_post("/1.1/account/update_delivery_device.json").with(:body => {:device => "sms"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
52
|
+
end
|
53
|
+
it "requests the correct resource" do
|
54
|
+
@client.update_delivery_device("sms")
|
55
|
+
expect(a_post("/1.1/account/update_delivery_device.json").with(:body => {:device => "sms"})).to have_been_made
|
56
|
+
end
|
57
|
+
it "returns a user" do
|
58
|
+
user = @client.update_delivery_device("sms")
|
59
|
+
expect(user).to be_a Twitter::User
|
60
|
+
expect(user.id).to eq 7505382
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#update_profile" do
|
65
|
+
before do
|
66
|
+
stub_post("/1.1/account/update_profile.json").with(:body => {:url => "http://github.com/sferik/"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
67
|
+
end
|
68
|
+
it "requests the correct resource" do
|
69
|
+
@client.update_profile(:url => "http://github.com/sferik/")
|
70
|
+
expect(a_post("/1.1/account/update_profile.json").with(:body => {:url => "http://github.com/sferik/"})).to have_been_made
|
71
|
+
end
|
72
|
+
it "returns a user" do
|
73
|
+
user = @client.update_profile(:url => "http://github.com/sferik/")
|
74
|
+
expect(user).to be_a Twitter::User
|
75
|
+
expect(user.id).to eq 7505382
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#update_profile_background_image" do
|
80
|
+
before do
|
81
|
+
stub_post("/1.1/account/update_profile_background_image.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
82
|
+
end
|
83
|
+
it "requests the correct resource" do
|
84
|
+
@client.update_profile_background_image(fixture("we_concept_bg2.png"))
|
85
|
+
expect(a_post("/1.1/account/update_profile_background_image.json")).to have_been_made
|
86
|
+
end
|
87
|
+
it "returns a user" do
|
88
|
+
user = @client.update_profile_background_image(fixture("we_concept_bg2.png"))
|
89
|
+
expect(user).to be_a Twitter::User
|
90
|
+
expect(user.id).to eq 7505382
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#update_profile_colors" do
|
95
|
+
before do
|
96
|
+
stub_post("/1.1/account/update_profile_colors.json").with(:body => {:profile_background_color => "000000"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
97
|
+
end
|
98
|
+
it "requests the correct resource" do
|
99
|
+
@client.update_profile_colors(:profile_background_color => "000000")
|
100
|
+
expect(a_post("/1.1/account/update_profile_colors.json").with(:body => {:profile_background_color => "000000"})).to have_been_made
|
101
|
+
end
|
102
|
+
it "returns a user" do
|
103
|
+
user = @client.update_profile_colors(:profile_background_color => "000000")
|
104
|
+
expect(user).to be_a Twitter::User
|
105
|
+
expect(user.id).to eq 7505382
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#update_profile_image" do
|
110
|
+
before do
|
111
|
+
stub_post("/1.1/account/update_profile_image.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
112
|
+
end
|
113
|
+
it "requests the correct resource" do
|
114
|
+
@client.update_profile_image(fixture("me.jpeg"))
|
115
|
+
expect(a_post("/1.1/account/update_profile_image.json")).to have_been_made
|
116
|
+
end
|
117
|
+
it "returns a user" do
|
118
|
+
user = @client.update_profile_image(fixture("me.jpeg"))
|
119
|
+
expect(user).to be_a Twitter::User
|
120
|
+
expect(user.id).to eq 7505382
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
9
124
|
describe "#suggestions" do
|
10
125
|
context "with a category slug passed" do
|
11
126
|
before do
|
@@ -56,6 +171,119 @@ describe Twitter::API do
|
|
56
171
|
end
|
57
172
|
end
|
58
173
|
|
174
|
+
describe "#blocking" do
|
175
|
+
before do
|
176
|
+
stub_get("/1.1/blocks/list.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
177
|
+
end
|
178
|
+
it "requests the correct resource" do
|
179
|
+
@client.blocking
|
180
|
+
expect(a_get("/1.1/blocks/list.json").with(:query => {:cursor => "-1"})).to have_been_made
|
181
|
+
end
|
182
|
+
it "returns an array of user objects that the authenticating user is blocking" do
|
183
|
+
blocking = @client.blocking
|
184
|
+
expect(blocking).to be_a Twitter::Cursor
|
185
|
+
expect(blocking.users).to be_an Array
|
186
|
+
expect(blocking.users.first).to be_a Twitter::User
|
187
|
+
expect(blocking.users.first.id).to eq 7505382
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#blocked_ids" do
|
192
|
+
before do
|
193
|
+
stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
194
|
+
end
|
195
|
+
it "requests the correct resource" do
|
196
|
+
@client.blocked_ids
|
197
|
+
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
|
198
|
+
end
|
199
|
+
it "returns an array of numeric user IDs the authenticating user is blocking" do
|
200
|
+
blocked_ids = @client.blocked_ids
|
201
|
+
expect(blocked_ids).to be_a Twitter::Cursor
|
202
|
+
expect(blocked_ids.ids).to be_an Array
|
203
|
+
expect(blocked_ids.ids.first).to eq 14100886
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "#block?" do
|
208
|
+
context "with a screen name passed" do
|
209
|
+
before do
|
210
|
+
stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
211
|
+
stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
212
|
+
stub_get("/1.1/users/show.json").with(:query => {:screen_name => "pengwynn"}).to_return(:body => fixture("pengwynn.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
213
|
+
stub_get("/1.1/users/show.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
214
|
+
end
|
215
|
+
it "requests the correct resource" do
|
216
|
+
@client.block?("sferik")
|
217
|
+
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
|
218
|
+
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"})).to have_been_made
|
219
|
+
expect(a_get("/1.1/users/show.json").with(:query => {:screen_name => "sferik"})).to have_been_made
|
220
|
+
end
|
221
|
+
it "returns true if block exists" do
|
222
|
+
block = @client.block?("pengwynn")
|
223
|
+
expect(block).to be_true
|
224
|
+
end
|
225
|
+
it "returns false if block does not exist" do
|
226
|
+
block = @client.block?("sferik")
|
227
|
+
expect(block).to be_false
|
228
|
+
end
|
229
|
+
end
|
230
|
+
context "with a user ID passed" do
|
231
|
+
before do
|
232
|
+
stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
233
|
+
stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
234
|
+
end
|
235
|
+
it "requests the correct resources" do
|
236
|
+
@client.block?(7505382)
|
237
|
+
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
|
238
|
+
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"})).to have_been_made
|
239
|
+
end
|
240
|
+
end
|
241
|
+
context "with a user object passed" do
|
242
|
+
before do
|
243
|
+
stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
244
|
+
stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
245
|
+
end
|
246
|
+
it "requests the correct resources" do
|
247
|
+
user = Twitter::User.new(:id => '7505382')
|
248
|
+
@client.block?(user)
|
249
|
+
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
|
250
|
+
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"})).to have_been_made
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "#block" do
|
256
|
+
before do
|
257
|
+
stub_post("/1.1/blocks/create.json").with(:body => {:screen_name => "sferik"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
258
|
+
end
|
259
|
+
it "requests the correct resource" do
|
260
|
+
@client.block("sferik")
|
261
|
+
expect(a_post("/1.1/blocks/create.json")).to have_been_made
|
262
|
+
end
|
263
|
+
it "returns an array of blocked users" do
|
264
|
+
users = @client.block("sferik")
|
265
|
+
expect(users).to be_an Array
|
266
|
+
expect(users.first).to be_a Twitter::User
|
267
|
+
expect(users.first.id).to eq 7505382
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe "#unblock" do
|
272
|
+
before do
|
273
|
+
stub_post("/1.1/blocks/destroy.json").with(:body => {:screen_name => "sferik"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
274
|
+
end
|
275
|
+
it "requests the correct resource" do
|
276
|
+
@client.unblock("sferik")
|
277
|
+
expect(a_post("/1.1/blocks/destroy.json").with(:body => {:screen_name => "sferik"})).to have_been_made
|
278
|
+
end
|
279
|
+
it "returns an array of un-blocked users" do
|
280
|
+
users = @client.unblock("sferik")
|
281
|
+
expect(users).to be_an Array
|
282
|
+
expect(users.first).to be_a Twitter::User
|
283
|
+
expect(users.first.id).to eq 7505382
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
59
287
|
describe "#users" do
|
60
288
|
context "with screen names passed" do
|
61
289
|
before do
|
@@ -112,22 +340,6 @@ describe Twitter::API do
|
|
112
340
|
end
|
113
341
|
end
|
114
342
|
|
115
|
-
describe "#user_search" do
|
116
|
-
before do
|
117
|
-
stub_get("/1.1/users/search.json").with(:query => {:q => "Erik Michaels-Ober"}).to_return(:body => fixture("user_search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
118
|
-
end
|
119
|
-
it "requests the correct resource" do
|
120
|
-
@client.user_search("Erik Michaels-Ober")
|
121
|
-
expect(a_get("/1.1/users/search.json").with(:query => {:q => "Erik Michaels-Ober"})).to have_been_made
|
122
|
-
end
|
123
|
-
it "returns an array of user search results" do
|
124
|
-
user_search = @client.user_search("Erik Michaels-Ober")
|
125
|
-
expect(user_search).to be_an Array
|
126
|
-
expect(user_search.first).to be_a Twitter::User
|
127
|
-
expect(user_search.first.id).to eq 7505382
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
343
|
describe "#user" do
|
132
344
|
context "with a screen name passed" do
|
133
345
|
before do
|
@@ -221,6 +433,22 @@ describe Twitter::API do
|
|
221
433
|
end
|
222
434
|
end
|
223
435
|
|
436
|
+
describe "#user_search" do
|
437
|
+
before do
|
438
|
+
stub_get("/1.1/users/search.json").with(:query => {:q => "Erik Michaels-Ober"}).to_return(:body => fixture("user_search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
439
|
+
end
|
440
|
+
it "requests the correct resource" do
|
441
|
+
@client.user_search("Erik Michaels-Ober")
|
442
|
+
expect(a_get("/1.1/users/search.json").with(:query => {:q => "Erik Michaels-Ober"})).to have_been_made
|
443
|
+
end
|
444
|
+
it "returns an array of user search results" do
|
445
|
+
user_search = @client.user_search("Erik Michaels-Ober")
|
446
|
+
expect(user_search).to be_an Array
|
447
|
+
expect(user_search.first).to be_a Twitter::User
|
448
|
+
expect(user_search.first.id).to eq 7505382
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
224
452
|
describe "#contributees" do
|
225
453
|
context "with a screen name passed" do
|
226
454
|
before do
|
@@ -325,4 +553,67 @@ describe Twitter::API do
|
|
325
553
|
end
|
326
554
|
end
|
327
555
|
|
556
|
+
describe "#remove_profile_banner" do
|
557
|
+
before do
|
558
|
+
stub_post("/1.1/account/remove_profile_banner.json").to_return(:body => fixture("empty.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
559
|
+
end
|
560
|
+
it "requests the correct resource" do
|
561
|
+
@client.remove_profile_banner
|
562
|
+
expect(a_post("/1.1/account/remove_profile_banner.json")).to have_been_made
|
563
|
+
end
|
564
|
+
it "returns a user" do
|
565
|
+
user = @client.remove_profile_banner
|
566
|
+
expect(user).to be_nil
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
describe "#update_profile_banner" do
|
571
|
+
before do
|
572
|
+
stub_post("/1.1/account/update_profile_banner.json").to_return(:body => fixture("empty.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
573
|
+
end
|
574
|
+
it "requests the correct resource" do
|
575
|
+
@client.update_profile_banner(fixture("me.jpeg"))
|
576
|
+
expect(a_post("/1.1/account/update_profile_banner.json")).to have_been_made
|
577
|
+
end
|
578
|
+
it "returns a user" do
|
579
|
+
user = @client.update_profile_banner(fixture("me.jpeg"))
|
580
|
+
expect(user).to be_nil
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
describe '#profile_banner' do
|
585
|
+
context "with a screen_name passed" do
|
586
|
+
before do
|
587
|
+
stub_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("profile_banner.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
588
|
+
end
|
589
|
+
it "requests the correct resource" do
|
590
|
+
@client.profile_banner('sferik')
|
591
|
+
expect(a_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"})).to have_been_made
|
592
|
+
end
|
593
|
+
it "returns a user's profile banner" do
|
594
|
+
banner = @client.profile_banner('sferik')
|
595
|
+
expect(banner).to be_a Twitter::ProfileBanner
|
596
|
+
expect(banner.sizes).to be_a Hash
|
597
|
+
expect(banner.sizes[:mobile].height).to eq 160
|
598
|
+
end
|
599
|
+
end
|
600
|
+
context "without arguments passed" do
|
601
|
+
before do
|
602
|
+
stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
603
|
+
stub_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("profile_banner.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
604
|
+
end
|
605
|
+
it "requests the correct resource" do
|
606
|
+
@client.profile_banner
|
607
|
+
expect(a_get("/1.1/account/verify_credentials.json")).to have_been_made
|
608
|
+
expect(a_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"})).to have_been_made
|
609
|
+
end
|
610
|
+
it "returns an array of numeric IDs for every user following the specified user" do
|
611
|
+
banner = @client.profile_banner
|
612
|
+
expect(banner).to be_a Twitter::ProfileBanner
|
613
|
+
expect(banner.sizes).to be_a Hash
|
614
|
+
expect(banner.sizes[:mobile].height).to eq 160
|
615
|
+
end
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
328
619
|
end
|