twitter 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +673 -0
- data/LICENSE.md +20 -0
- data/README.md +415 -0
- data/Rakefile +11 -0
- data/lib/twitter.rb +29 -0
- data/lib/twitter/action/favorite.rb +19 -0
- data/lib/twitter/action/follow.rb +31 -0
- data/lib/twitter/action/list_member_added.rb +41 -0
- data/lib/twitter/action/mention.rb +48 -0
- data/lib/twitter/action/reply.rb +27 -0
- data/lib/twitter/action/retweet.rb +27 -0
- data/lib/twitter/action/tweet.rb +22 -0
- data/lib/twitter/action_factory.rb +22 -0
- data/lib/twitter/api.rb +2442 -0
- data/lib/twitter/base.rb +119 -0
- data/lib/twitter/basic_user.rb +8 -0
- data/lib/twitter/client.rb +96 -0
- data/lib/twitter/configurable.rb +67 -0
- data/lib/twitter/configuration.rb +20 -0
- data/lib/twitter/core_ext/array.rb +7 -0
- data/lib/twitter/core_ext/enumerable.rb +11 -0
- data/lib/twitter/core_ext/hash.rb +100 -0
- data/lib/twitter/core_ext/kernel.rb +15 -0
- data/lib/twitter/core_ext/string.rb +10 -0
- data/lib/twitter/creatable.rb +20 -0
- data/lib/twitter/cursor.rb +87 -0
- data/lib/twitter/default.rb +101 -0
- data/lib/twitter/direct_message.rb +21 -0
- data/lib/twitter/entity.rb +7 -0
- data/lib/twitter/entity/hashtag.rb +9 -0
- data/lib/twitter/entity/url.rb +9 -0
- data/lib/twitter/entity/user_mention.rb +9 -0
- data/lib/twitter/error.rb +34 -0
- data/lib/twitter/error/bad_gateway.rb +11 -0
- data/lib/twitter/error/bad_request.rb +10 -0
- data/lib/twitter/error/client_error.rb +35 -0
- data/lib/twitter/error/decode_error.rb +9 -0
- data/lib/twitter/error/forbidden.rb +10 -0
- data/lib/twitter/error/gateway_timeout.rb +11 -0
- data/lib/twitter/error/identity_map_key_error.rb +9 -0
- data/lib/twitter/error/internal_server_error.rb +11 -0
- data/lib/twitter/error/not_acceptable.rb +10 -0
- data/lib/twitter/error/not_found.rb +10 -0
- data/lib/twitter/error/rate_limited.rb +11 -0
- data/lib/twitter/error/server_error.rb +28 -0
- data/lib/twitter/error/service_unavailable.rb +11 -0
- data/lib/twitter/error/unauthorized.rb +10 -0
- data/lib/twitter/factory.rb +21 -0
- data/lib/twitter/geo.rb +15 -0
- data/lib/twitter/geo/point.rb +22 -0
- data/lib/twitter/geo/polygon.rb +8 -0
- data/lib/twitter/geo_factory.rb +18 -0
- data/lib/twitter/identity.rb +50 -0
- data/lib/twitter/identity_map.rb +22 -0
- data/lib/twitter/language.rb +7 -0
- data/lib/twitter/list.rb +18 -0
- data/lib/twitter/media/photo.rb +22 -0
- data/lib/twitter/media_factory.rb +17 -0
- data/lib/twitter/metadata.rb +7 -0
- data/lib/twitter/oembed.rb +8 -0
- data/lib/twitter/place.rb +34 -0
- data/lib/twitter/rate_limit.rb +45 -0
- data/lib/twitter/relationship.rb +36 -0
- data/lib/twitter/request/multipart_with_file.rb +41 -0
- data/lib/twitter/response/parse_json.rb +25 -0
- data/lib/twitter/response/raise_error.rb +30 -0
- data/lib/twitter/saved_search.rb +9 -0
- data/lib/twitter/search_results.rb +48 -0
- data/lib/twitter/settings.rb +17 -0
- data/lib/twitter/size.rb +24 -0
- data/lib/twitter/source_user.rb +15 -0
- data/lib/twitter/suggestion.rb +22 -0
- data/lib/twitter/target_user.rb +8 -0
- data/lib/twitter/trend.rb +14 -0
- data/lib/twitter/tweet.rb +145 -0
- data/lib/twitter/user.rb +97 -0
- data/lib/twitter/version.rb +18 -0
- data/spec/fixtures/about_me.json +1 -0
- data/spec/fixtures/activity_summary.json +1 -0
- data/spec/fixtures/all.json +1 -0
- data/spec/fixtures/bad_gateway.json +1 -0
- data/spec/fixtures/bad_request.json +1 -0
- data/spec/fixtures/by_friends.json +1 -0
- data/spec/fixtures/category.json +1 -0
- data/spec/fixtures/configuration.json +1 -0
- data/spec/fixtures/contributees.json +1 -0
- data/spec/fixtures/contributors.json +1 -0
- data/spec/fixtures/direct_message.json +1 -0
- data/spec/fixtures/direct_messages.json +1 -0
- data/spec/fixtures/end_session.json +1 -0
- data/spec/fixtures/enhance_your_calm.text +11 -0
- data/spec/fixtures/favorites.json +1 -0
- data/spec/fixtures/following.json +1 -0
- data/spec/fixtures/forbidden.json +1 -0
- data/spec/fixtures/friendships.json +1 -0
- data/spec/fixtures/ids.json +1 -0
- data/spec/fixtures/ids_list.json +1 -0
- data/spec/fixtures/ids_list2.json +1 -0
- data/spec/fixtures/image_facets.json +1 -0
- data/spec/fixtures/internal_server_error.json +1 -0
- data/spec/fixtures/languages.json +1 -0
- data/spec/fixtures/list.json +1 -0
- data/spec/fixtures/lists.json +1 -0
- data/spec/fixtures/locations.json +1 -0
- data/spec/fixtures/matching_trends.json +1 -0
- data/spec/fixtures/me.jpeg +0 -0
- data/spec/fixtures/media_timeline.json +1 -0
- data/spec/fixtures/members.json +1 -0
- data/spec/fixtures/no_user_matches.json +1 -0
- data/spec/fixtures/not_acceptable.json +1 -0
- data/spec/fixtures/not_following.json +1 -0
- data/spec/fixtures/not_found.json +1 -0
- data/spec/fixtures/oembed.json +1 -0
- data/spec/fixtures/pbjt.gif +0 -0
- data/spec/fixtures/pengwynn.json +1 -0
- data/spec/fixtures/phoenix_search.phoenix +1 -0
- data/spec/fixtures/place.json +1 -0
- data/spec/fixtures/places.json +1 -0
- data/spec/fixtures/privacy.json +1 -0
- data/spec/fixtures/profile_image.text +24 -0
- data/spec/fixtures/rate_limit_status.json +1 -0
- data/spec/fixtures/recommendations.json +1 -0
- data/spec/fixtures/related_results.json +1 -0
- data/spec/fixtures/resolve.json +1 -0
- data/spec/fixtures/retweet.json +1 -0
- data/spec/fixtures/retweeted_status.json +1 -0
- data/spec/fixtures/retweeters_of.json +1 -0
- data/spec/fixtures/retweets.json +1 -0
- data/spec/fixtures/saved_search.json +1 -0
- data/spec/fixtures/saved_searches.json +1 -0
- data/spec/fixtures/search.json +1 -0
- data/spec/fixtures/search_malformed.json +1 -0
- data/spec/fixtures/service_unavailable.json +1 -0
- data/spec/fixtures/settings.json +1 -0
- data/spec/fixtures/sferik.json +1 -0
- data/spec/fixtures/status.json +1 -0
- data/spec/fixtures/status_with_media.json +104 -0
- data/spec/fixtures/statuses.json +1 -0
- data/spec/fixtures/suggestions.json +1 -0
- data/spec/fixtures/tos.json +1 -0
- data/spec/fixtures/totals.json +1 -0
- data/spec/fixtures/trends.json +1 -0
- data/spec/fixtures/trends_current.json +1 -0
- data/spec/fixtures/trends_daily.json +1 -0
- data/spec/fixtures/trends_weekly.json +1 -0
- data/spec/fixtures/unauthorized.json +1 -0
- data/spec/fixtures/user_search.json +1 -0
- data/spec/fixtures/user_timeline.json +1 -0
- data/spec/fixtures/users.json +1 -0
- data/spec/fixtures/users_list.json +1 -0
- data/spec/fixtures/video_facets.json +1 -0
- data/spec/fixtures/we_concept_bg2.png +0 -0
- data/spec/fixtures/wildcomet2.jpe +0 -0
- data/spec/helper.rb +53 -0
- data/spec/twitter/action/favorite_spec.rb +29 -0
- data/spec/twitter/action/follow_spec.rb +29 -0
- data/spec/twitter/action/list_member_added_spec.rb +41 -0
- data/spec/twitter/action/mention_spec.rb +52 -0
- data/spec/twitter/action/reply_spec.rb +41 -0
- data/spec/twitter/action/retweet_spec.rb +41 -0
- data/spec/twitter/action_factory_spec.rb +37 -0
- data/spec/twitter/action_spec.rb +16 -0
- data/spec/twitter/api/account_spec.rb +148 -0
- data/spec/twitter/api/activity_spec.rb +41 -0
- data/spec/twitter/api/blocks_spec.rb +167 -0
- data/spec/twitter/api/direct_messages_spec.rb +142 -0
- data/spec/twitter/api/friendships_spec.rb +567 -0
- data/spec/twitter/api/geo_spec.rb +100 -0
- data/spec/twitter/api/help_spec.rb +76 -0
- data/spec/twitter/api/lists_spec.rb +900 -0
- data/spec/twitter/api/report_spam_spec.rb +29 -0
- data/spec/twitter/api/saved_searches_spec.rb +100 -0
- data/spec/twitter/api/search_spec.rb +68 -0
- data/spec/twitter/api/statuses_spec.rb +559 -0
- data/spec/twitter/api/trends_spec.rb +80 -0
- data/spec/twitter/api/users_spec.rb +419 -0
- data/spec/twitter/base_spec.rb +113 -0
- data/spec/twitter/basic_user_spec.rb +23 -0
- data/spec/twitter/client_spec.rb +175 -0
- data/spec/twitter/configuration_spec.rb +17 -0
- data/spec/twitter/cursor_spec.rb +102 -0
- data/spec/twitter/direct_message_spec.rb +56 -0
- data/spec/twitter/error/client_error_spec.rb +40 -0
- data/spec/twitter/error/server_error_spec.rb +24 -0
- data/spec/twitter/error_spec.rb +20 -0
- data/spec/twitter/geo/point_spec.rb +41 -0
- data/spec/twitter/geo/polygon_spec.rb +29 -0
- data/spec/twitter/geo_factory_spec.rb +21 -0
- data/spec/twitter/geo_spec.rb +29 -0
- data/spec/twitter/identifiable_spec.rb +54 -0
- data/spec/twitter/list_spec.rb +45 -0
- data/spec/twitter/media/photo_spec.rb +35 -0
- data/spec/twitter/media_factory_spec.rb +17 -0
- data/spec/twitter/oembed_spec.rb +146 -0
- data/spec/twitter/place_spec.rb +75 -0
- data/spec/twitter/rate_limit_spec.rb +76 -0
- data/spec/twitter/relationship_spec.rb +35 -0
- data/spec/twitter/saved_search_spec.rb +34 -0
- data/spec/twitter/search_results_spec.rb +89 -0
- data/spec/twitter/settings_spec.rb +16 -0
- data/spec/twitter/size_spec.rb +38 -0
- data/spec/twitter/source_user_spec.rb +23 -0
- data/spec/twitter/suggestion_spec.rb +50 -0
- data/spec/twitter/target_user_spec.rb +23 -0
- data/spec/twitter/trend_spec.rb +38 -0
- data/spec/twitter/tweet_spec.rb +307 -0
- data/spec/twitter/user_spec.rb +127 -0
- data/spec/twitter_spec.rb +93 -0
- data/twitter.gemspec +30 -0
- metadata +584 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::API do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#blocking" do
|
10
|
+
before do
|
11
|
+
stub_get("/1.1/blocks/list.json").
|
12
|
+
with(:query => {:cursor => "-1"}).
|
13
|
+
to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
end
|
15
|
+
it "requests the correct resource" do
|
16
|
+
@client.blocking
|
17
|
+
a_get("/1.1/blocks/list.json").
|
18
|
+
with(:query => {:cursor => "-1"}).
|
19
|
+
should have_been_made
|
20
|
+
end
|
21
|
+
it "returns an array of user objects that the authenticating user is blocking" do
|
22
|
+
blocking = @client.blocking
|
23
|
+
blocking.should be_a Twitter::Cursor
|
24
|
+
blocking.users.should be_an Array
|
25
|
+
blocking.users.first.should be_a Twitter::User
|
26
|
+
blocking.users.first.id.should eq 7505382
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#blocked_ids" do
|
31
|
+
before do
|
32
|
+
stub_get("/1.1/blocks/ids.json").
|
33
|
+
with(:query => {:cursor => "-1"}).
|
34
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
35
|
+
end
|
36
|
+
it "requests the correct resource" do
|
37
|
+
@client.blocked_ids
|
38
|
+
a_get("/1.1/blocks/ids.json").
|
39
|
+
with(:query => {:cursor => "-1"}).
|
40
|
+
should have_been_made
|
41
|
+
end
|
42
|
+
it "returns an array of numeric user IDs the authenticating user is blocking" do
|
43
|
+
blocked_ids = @client.blocked_ids
|
44
|
+
blocked_ids.should be_a Twitter::Cursor
|
45
|
+
blocked_ids.ids.should be_an Array
|
46
|
+
blocked_ids.ids.first.should eq 14100886
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#block?" do
|
51
|
+
context "with a screen name passed" do
|
52
|
+
before do
|
53
|
+
stub_get("/1.1/blocks/ids.json").
|
54
|
+
with(:query => {:cursor => "-1"}).
|
55
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
56
|
+
stub_get("/1.1/blocks/ids.json").
|
57
|
+
with(:query => {:cursor => "1305102810874389703"}).
|
58
|
+
to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
59
|
+
stub_get("/1.1/users/show.json").
|
60
|
+
with(:query => {:screen_name => "pengwynn"}).
|
61
|
+
to_return(:body => fixture("pengwynn.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
62
|
+
stub_get("/1.1/users/show.json").
|
63
|
+
with(:query => {:screen_name => "sferik"}).
|
64
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
65
|
+
end
|
66
|
+
it "requests the correct resource" do
|
67
|
+
@client.block?("sferik")
|
68
|
+
a_get("/1.1/blocks/ids.json").
|
69
|
+
with(:query => {:cursor => "-1"}).
|
70
|
+
should have_been_made
|
71
|
+
a_get("/1.1/blocks/ids.json").
|
72
|
+
with(:query => {:cursor => "1305102810874389703"}).
|
73
|
+
should have_been_made
|
74
|
+
a_get("/1.1/users/show.json").
|
75
|
+
with(:query => {:screen_name => "sferik"}).
|
76
|
+
should have_been_made
|
77
|
+
end
|
78
|
+
it "returns true if block exists" do
|
79
|
+
block = @client.block?("pengwynn")
|
80
|
+
block.should be_true
|
81
|
+
end
|
82
|
+
it "returns false if block does not exist" do
|
83
|
+
block = @client.block?("sferik")
|
84
|
+
block.should be_false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
context "with a user ID passed" do
|
88
|
+
before do
|
89
|
+
stub_get("/1.1/blocks/ids.json").
|
90
|
+
with(:query => {:cursor => "-1"}).
|
91
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
92
|
+
stub_get("/1.1/blocks/ids.json").
|
93
|
+
with(:query => {:cursor => "1305102810874389703"}).
|
94
|
+
to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
95
|
+
end
|
96
|
+
it "requests the correct resources" do
|
97
|
+
@client.block?(7505382)
|
98
|
+
a_get("/1.1/blocks/ids.json").
|
99
|
+
with(:query => {:cursor => "-1"}).
|
100
|
+
should have_been_made
|
101
|
+
a_get("/1.1/blocks/ids.json").
|
102
|
+
with(:query => {:cursor => "1305102810874389703"}).
|
103
|
+
should have_been_made
|
104
|
+
end
|
105
|
+
end
|
106
|
+
context "with a user object passed" do
|
107
|
+
before do
|
108
|
+
stub_get("/1.1/blocks/ids.json").
|
109
|
+
with(:query => {:cursor => "-1"}).
|
110
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
111
|
+
stub_get("/1.1/blocks/ids.json").
|
112
|
+
with(:query => {:cursor => "1305102810874389703"}).
|
113
|
+
to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
114
|
+
end
|
115
|
+
it "requests the correct resources" do
|
116
|
+
user = Twitter::User.new(:id => '7505382')
|
117
|
+
@client.block?(user)
|
118
|
+
a_get("/1.1/blocks/ids.json").
|
119
|
+
with(:query => {:cursor => "-1"}).
|
120
|
+
should have_been_made
|
121
|
+
a_get("/1.1/blocks/ids.json").
|
122
|
+
with(:query => {:cursor => "1305102810874389703"}).
|
123
|
+
should have_been_made
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#block" do
|
129
|
+
before do
|
130
|
+
stub_post("/1.1/blocks/create.json").
|
131
|
+
with(:body => {:screen_name => "sferik"}).
|
132
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
133
|
+
end
|
134
|
+
it "requests the correct resource" do
|
135
|
+
@client.block("sferik")
|
136
|
+
a_post("/1.1/blocks/create.json").
|
137
|
+
should have_been_made
|
138
|
+
end
|
139
|
+
it "returns an array of blocked users" do
|
140
|
+
users = @client.block("sferik")
|
141
|
+
users.should be_an Array
|
142
|
+
users.first.should be_a Twitter::User
|
143
|
+
users.first.id.should eq 7505382
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "#unblock" do
|
148
|
+
before do
|
149
|
+
stub_post("/1.1/blocks/destroy.json").
|
150
|
+
with(:body => {:screen_name => "sferik"}).
|
151
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
152
|
+
end
|
153
|
+
it "requests the correct resource" do
|
154
|
+
@client.unblock("sferik")
|
155
|
+
a_post("/1.1/blocks/destroy.json").
|
156
|
+
with(:body => {:screen_name => "sferik"}).
|
157
|
+
should have_been_made
|
158
|
+
end
|
159
|
+
it "returns an array of un-blocked users" do
|
160
|
+
users = @client.unblock("sferik")
|
161
|
+
users.should be_an Array
|
162
|
+
users.first.should be_a Twitter::User
|
163
|
+
users.first.id.should eq 7505382
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::API do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#direct_messages_received" do
|
10
|
+
before do
|
11
|
+
stub_get("/1.1/direct_messages.json").
|
12
|
+
to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
13
|
+
end
|
14
|
+
it "requests the correct resource" do
|
15
|
+
@client.direct_messages_received
|
16
|
+
a_get("/1.1/direct_messages.json").
|
17
|
+
should have_been_made
|
18
|
+
end
|
19
|
+
it "returns the 20 most recent direct messages sent to the authenticating user" do
|
20
|
+
direct_messages = @client.direct_messages_received
|
21
|
+
direct_messages.should be_an Array
|
22
|
+
direct_messages.first.should be_a Twitter::DirectMessage
|
23
|
+
direct_messages.first.sender.id.should eq 7505382
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#direct_messages_sent" do
|
28
|
+
before do
|
29
|
+
stub_get("/1.1/direct_messages/sent.json").
|
30
|
+
to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
31
|
+
end
|
32
|
+
it "requests the correct resource" do
|
33
|
+
@client.direct_messages_sent
|
34
|
+
a_get("/1.1/direct_messages/sent.json").
|
35
|
+
should have_been_made
|
36
|
+
end
|
37
|
+
it "returns the 20 most recent direct messages sent by the authenticating user" do
|
38
|
+
direct_messages = @client.direct_messages_sent
|
39
|
+
direct_messages.should be_an Array
|
40
|
+
direct_messages.first.should be_a Twitter::DirectMessage
|
41
|
+
direct_messages.first.sender.id.should eq 7505382
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#direct_message_destroy" do
|
46
|
+
before do
|
47
|
+
stub_post("/1.1/direct_messages/destroy.json").
|
48
|
+
with(:body => {:id => "1825785544"}).
|
49
|
+
to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
50
|
+
end
|
51
|
+
it "requests the correct resource" do
|
52
|
+
@client.direct_message_destroy(1825785544)
|
53
|
+
a_post("/1.1/direct_messages/destroy.json").
|
54
|
+
with(:body => {:id => "1825785544"}).
|
55
|
+
should have_been_made
|
56
|
+
end
|
57
|
+
it "returns an array of deleted messages" do
|
58
|
+
direct_messages = @client.direct_message_destroy(1825785544)
|
59
|
+
direct_messages.should be_an Array
|
60
|
+
direct_messages.first.should be_a Twitter::DirectMessage
|
61
|
+
direct_messages.first.sender.id.should eq 7505382
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#direct_message_create" do
|
66
|
+
before do
|
67
|
+
stub_post("/1.1/direct_messages/new.json").
|
68
|
+
with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"}).
|
69
|
+
to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
70
|
+
end
|
71
|
+
it "requests the correct resource" do
|
72
|
+
@client.direct_message_create("pengwynn", "Creating a fixture for the Twitter gem")
|
73
|
+
a_post("/1.1/direct_messages/new.json").
|
74
|
+
with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"}).
|
75
|
+
should have_been_made
|
76
|
+
end
|
77
|
+
it "returns the sent message" do
|
78
|
+
direct_message = @client.direct_message_create("pengwynn", "Creating a fixture for the Twitter gem")
|
79
|
+
direct_message.should be_a Twitter::DirectMessage
|
80
|
+
direct_message.text.should eq "Creating a fixture for the Twitter gem"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#direct_message" do
|
85
|
+
before do
|
86
|
+
stub_get("/1.1/direct_messages/show.json").
|
87
|
+
with(:query => {:id => "1825786345"}).
|
88
|
+
to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
89
|
+
end
|
90
|
+
it "requests the correct resource" do
|
91
|
+
@client.direct_message(1825786345)
|
92
|
+
a_get("/1.1/direct_messages/show.json").
|
93
|
+
with(:query => {:id => "1825786345"}).
|
94
|
+
should have_been_made
|
95
|
+
end
|
96
|
+
it "returns the specified direct message" do
|
97
|
+
direct_message = @client.direct_message(1825786345)
|
98
|
+
direct_message.should be_a Twitter::DirectMessage
|
99
|
+
direct_message.sender.id.should eq 7505382
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#direct_messages" do
|
104
|
+
context "with ids passed" do
|
105
|
+
before do
|
106
|
+
stub_get("/1.1/direct_messages/show.json").
|
107
|
+
with(:query => {:id => "1825786345"}).
|
108
|
+
to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
109
|
+
end
|
110
|
+
it "requests the correct resource" do
|
111
|
+
@client.direct_messages(1825786345)
|
112
|
+
a_get("/1.1/direct_messages/show.json").
|
113
|
+
with(:query => {:id => "1825786345"}).
|
114
|
+
should have_been_made
|
115
|
+
end
|
116
|
+
it "returns an array of direct messages" do
|
117
|
+
direct_messages = @client.direct_messages(1825786345)
|
118
|
+
direct_messages.should be_an Array
|
119
|
+
direct_messages.first.should be_a Twitter::DirectMessage
|
120
|
+
direct_messages.first.sender.id.should eq 7505382
|
121
|
+
end
|
122
|
+
end
|
123
|
+
context "without ids passed" do
|
124
|
+
before do
|
125
|
+
stub_get("/1.1/direct_messages.json").
|
126
|
+
to_return(:body => fixture("direct_messages.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
127
|
+
end
|
128
|
+
it "requests the correct resource" do
|
129
|
+
@client.direct_messages
|
130
|
+
a_get("/1.1/direct_messages.json").
|
131
|
+
should have_been_made
|
132
|
+
end
|
133
|
+
it "returns the 20 most recent direct messages sent to the authenticating user" do
|
134
|
+
direct_messages = @client.direct_messages
|
135
|
+
direct_messages.should be_an Array
|
136
|
+
direct_messages.first.should be_a Twitter::DirectMessage
|
137
|
+
direct_messages.first.sender.id.should eq 7505382
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
@@ -0,0 +1,567 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::API 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.1/followers/ids.json").
|
13
|
+
with(:query => {:cursor => "-1", :screen_name => "sferik"}).
|
14
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
15
|
+
end
|
16
|
+
it "requests the correct resource" do
|
17
|
+
@client.follower_ids("sferik")
|
18
|
+
a_get("/1.1/followers/ids.json").
|
19
|
+
with(:query => {:cursor => "-1", :screen_name => "sferik"}).
|
20
|
+
should have_been_made
|
21
|
+
end
|
22
|
+
it "returns 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 eq 14100886
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context "without arguments passed" do
|
30
|
+
before do
|
31
|
+
stub_get("/1.1/followers/ids.json").
|
32
|
+
with(:query => {:cursor => "-1"}).
|
33
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
34
|
+
end
|
35
|
+
it "requests the correct resource" do
|
36
|
+
@client.follower_ids
|
37
|
+
a_get("/1.1/followers/ids.json").
|
38
|
+
with(:query => {:cursor => "-1"}).
|
39
|
+
should have_been_made
|
40
|
+
end
|
41
|
+
it "returns 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 eq 14100886
|
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.1/friends/ids.json").
|
54
|
+
with(:query => {:cursor => "-1", :screen_name => "sferik"}).
|
55
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
56
|
+
end
|
57
|
+
it "requests the correct resource" do
|
58
|
+
@client.friend_ids("sferik")
|
59
|
+
a_get("/1.1/friends/ids.json").
|
60
|
+
with(:query => {:cursor => "-1", :screen_name => "sferik"}).
|
61
|
+
should have_been_made
|
62
|
+
end
|
63
|
+
it "returns 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 eq 14100886
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "without arguments passed" do
|
71
|
+
before do
|
72
|
+
stub_get("/1.1/friends/ids.json").
|
73
|
+
with(:query => {:cursor => "-1"}).
|
74
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
75
|
+
end
|
76
|
+
it "requests the correct resource" do
|
77
|
+
@client.friend_ids
|
78
|
+
a_get("/1.1/friends/ids.json").
|
79
|
+
with(:query => {:cursor => "-1"}).
|
80
|
+
should have_been_made
|
81
|
+
end
|
82
|
+
it "returns 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 eq 14100886
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#friendship?" do
|
92
|
+
context "with screen names passed" do
|
93
|
+
before do
|
94
|
+
stub_get("/1.1/friendships/show.json").
|
95
|
+
with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).
|
96
|
+
to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
97
|
+
stub_get("/1.1/friendships/show.json").
|
98
|
+
with(:query => {:source_screen_name => "pengwynn", :target_screen_name => "sferik"}).
|
99
|
+
to_return(:body => fixture("not_following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
100
|
+
end
|
101
|
+
it "requests the correct resource" do
|
102
|
+
@client.friendship?("sferik", "pengwynn")
|
103
|
+
a_get("/1.1/friendships/show.json").
|
104
|
+
with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).
|
105
|
+
should have_been_made
|
106
|
+
end
|
107
|
+
it "returns true if user A follows user B" do
|
108
|
+
friendship = @client.friendship?("sferik", "pengwynn")
|
109
|
+
friendship.should be_true
|
110
|
+
end
|
111
|
+
it "returns false if user A does not follow user B" do
|
112
|
+
friendship = @client.friendship?("pengwynn", "sferik")
|
113
|
+
friendship.should be_false
|
114
|
+
end
|
115
|
+
end
|
116
|
+
context "with user IDs passed" do
|
117
|
+
before do
|
118
|
+
stub_get("/1.1/friendships/show.json").
|
119
|
+
with(:query => {:source_id => "7505382", :target_id => "14100886"}).
|
120
|
+
to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
121
|
+
end
|
122
|
+
it "requests the correct resource" do
|
123
|
+
@client.friendship?(7505382, 14100886)
|
124
|
+
a_get("/1.1/friendships/show.json").
|
125
|
+
with(:query => {:source_id => "7505382", :target_id => "14100886"}).
|
126
|
+
should have_been_made
|
127
|
+
end
|
128
|
+
end
|
129
|
+
context "with user objects passed" do
|
130
|
+
before do
|
131
|
+
stub_get("/1.1/friendships/show.json").
|
132
|
+
with(:query => {:source_id => "7505382", :target_id => "14100886"}).
|
133
|
+
to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
134
|
+
end
|
135
|
+
it "requests the correct resource" do
|
136
|
+
user1 = Twitter::User.new(:id => '7505382')
|
137
|
+
user2 = Twitter::User.new(:id => '14100886')
|
138
|
+
@client.friendship?(user1, user2)
|
139
|
+
a_get("/1.1/friendships/show.json").
|
140
|
+
with(:query => {:source_id => "7505382", :target_id => "14100886"}).
|
141
|
+
should have_been_made
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#friendships_incoming" do
|
147
|
+
before do
|
148
|
+
stub_get("/1.1/friendships/incoming.json").
|
149
|
+
with(:query => {:cursor => "-1"}).
|
150
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
151
|
+
end
|
152
|
+
it "requests the correct resource" do
|
153
|
+
@client.friendships_incoming
|
154
|
+
a_get("/1.1/friendships/incoming.json").
|
155
|
+
with(:query => {:cursor => "-1"}).
|
156
|
+
should have_been_made
|
157
|
+
end
|
158
|
+
it "returns an array of numeric IDs for every user who has a pending request to follow the authenticating user" do
|
159
|
+
friendships_incoming = @client.friendships_incoming
|
160
|
+
friendships_incoming.should be_a Twitter::Cursor
|
161
|
+
friendships_incoming.ids.should be_an Array
|
162
|
+
friendships_incoming.ids.first.should eq 14100886
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "#friendships_outgoing" do
|
167
|
+
before do
|
168
|
+
stub_get("/1.1/friendships/outgoing.json").
|
169
|
+
with(:query => {:cursor => "-1"}).
|
170
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
171
|
+
end
|
172
|
+
it "requests the correct resource" do
|
173
|
+
@client.friendships_outgoing
|
174
|
+
a_get("/1.1/friendships/outgoing.json").
|
175
|
+
with(:query => {:cursor => "-1"}).
|
176
|
+
should have_been_made
|
177
|
+
end
|
178
|
+
it "returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request" do
|
179
|
+
friendships_outgoing = @client.friendships_outgoing
|
180
|
+
friendships_outgoing.should be_a Twitter::Cursor
|
181
|
+
friendships_outgoing.ids.should be_an Array
|
182
|
+
friendships_outgoing.ids.first.should eq 14100886
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "#friendship" do
|
187
|
+
context "with screen names passed" do
|
188
|
+
before do
|
189
|
+
stub_get("/1.1/friendships/show.json").
|
190
|
+
with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).
|
191
|
+
to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
192
|
+
end
|
193
|
+
it "requests the correct resource" do
|
194
|
+
@client.friendship("sferik", "pengwynn")
|
195
|
+
a_get("/1.1/friendships/show.json").
|
196
|
+
with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).
|
197
|
+
should have_been_made
|
198
|
+
end
|
199
|
+
it "returns detailed information about the relationship between two users" do
|
200
|
+
relationship = @client.friendship("sferik", "pengwynn")
|
201
|
+
relationship.should be_a Twitter::Relationship
|
202
|
+
relationship.source.id.should eq 7505382
|
203
|
+
end
|
204
|
+
end
|
205
|
+
context "with numeric screen names passed" do
|
206
|
+
before do
|
207
|
+
stub_get("/1.1/friendships/show.json").
|
208
|
+
with(:query => {:source_screen_name => "0", :target_screen_name => "311"}).
|
209
|
+
to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
210
|
+
end
|
211
|
+
it "requests the correct resource" do
|
212
|
+
@client.friendship("0", "311")
|
213
|
+
a_get("/1.1/friendships/show.json").
|
214
|
+
with(:query => {:source_screen_name => "0", :target_screen_name => "311"}).
|
215
|
+
should have_been_made
|
216
|
+
end
|
217
|
+
end
|
218
|
+
context "with user IDs passed" do
|
219
|
+
before do
|
220
|
+
stub_get("/1.1/friendships/show.json").
|
221
|
+
with(:query => {:source_id => "7505382", :target_id => "14100886"}).
|
222
|
+
to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
223
|
+
end
|
224
|
+
it "requests the correct resource" do
|
225
|
+
@client.friendship(7505382, 14100886)
|
226
|
+
a_get("/1.1/friendships/show.json").
|
227
|
+
with(:query => {:source_id => "7505382", :target_id => "14100886"}).
|
228
|
+
should have_been_made
|
229
|
+
end
|
230
|
+
end
|
231
|
+
context "with user objects passed" do
|
232
|
+
before do
|
233
|
+
stub_get("/1.1/friendships/show.json").
|
234
|
+
with(:query => {:source_id => "7505382", :target_id => "14100886"}).
|
235
|
+
to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
236
|
+
end
|
237
|
+
it "requests the correct resource" do
|
238
|
+
user1 = Twitter::User.new(:id => '7505382')
|
239
|
+
user2 = Twitter::User.new(:id => '14100886')
|
240
|
+
@client.friendship(user1, user2)
|
241
|
+
a_get("/1.1/friendships/show.json").
|
242
|
+
with(:query => {:source_id => "7505382", :target_id => "14100886"}).
|
243
|
+
should have_been_made
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe "#follow" do
|
249
|
+
context "with :follow => true passed" do
|
250
|
+
before do
|
251
|
+
stub_get("/1.1/friends/ids.json").
|
252
|
+
with(:query => {:cursor => "-1"}).
|
253
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
254
|
+
stub_post("/1.1/users/lookup.json").
|
255
|
+
with(:body => {:screen_name => "sferik,pengwynn"}).
|
256
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
257
|
+
stub_post("/1.1/friendships/create.json").
|
258
|
+
with(:body => {:user_id => "7505382", :follow => "true"}).
|
259
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
260
|
+
end
|
261
|
+
it "requests the correct resource" do
|
262
|
+
@client.follow("sferik", "pengwynn", :follow => true)
|
263
|
+
a_get("/1.1/friends/ids.json").
|
264
|
+
with(:query => {:cursor => "-1"}).
|
265
|
+
should have_been_made
|
266
|
+
a_post("/1.1/users/lookup.json").
|
267
|
+
with(:body => {:screen_name => "sferik,pengwynn"}).
|
268
|
+
should have_been_made
|
269
|
+
a_post("/1.1/friendships/create.json").
|
270
|
+
with(:body => {:user_id => "7505382", :follow => "true"}).
|
271
|
+
should have_been_made
|
272
|
+
end
|
273
|
+
it "returns an array of befriended users" do
|
274
|
+
users = @client.follow("sferik", "pengwynn", :follow => true)
|
275
|
+
users.should be_an Array
|
276
|
+
users.first.should be_a Twitter::User
|
277
|
+
users.first.id.should eq 7505382
|
278
|
+
end
|
279
|
+
end
|
280
|
+
context "with :follow => false passed" do
|
281
|
+
before do
|
282
|
+
stub_get("/1.1/friends/ids.json").
|
283
|
+
with(:query => {:cursor => "-1"}).
|
284
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
285
|
+
stub_post("/1.1/users/lookup.json").
|
286
|
+
with(:body => {:screen_name => "sferik,pengwynn"}).
|
287
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
288
|
+
stub_post("/1.1/friendships/create.json").
|
289
|
+
with(:body => {:user_id => "7505382"}).
|
290
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
291
|
+
end
|
292
|
+
it "requests the correct resource" do
|
293
|
+
@client.follow("sferik", "pengwynn", :follow => false)
|
294
|
+
a_get("/1.1/friends/ids.json").
|
295
|
+
with(:query => {:cursor => "-1"}).
|
296
|
+
should have_been_made
|
297
|
+
a_post("/1.1/users/lookup.json").
|
298
|
+
with(:body => {:screen_name => "sferik,pengwynn"}).
|
299
|
+
should have_been_made
|
300
|
+
a_post("/1.1/friendships/create.json").
|
301
|
+
with(:body => {:user_id => "7505382"}).
|
302
|
+
should have_been_made
|
303
|
+
end
|
304
|
+
it "returns an array of befriended users" do
|
305
|
+
users = @client.follow("sferik", "pengwynn", :follow => false)
|
306
|
+
users.should be_an Array
|
307
|
+
users.first.should be_a Twitter::User
|
308
|
+
users.first.id.should eq 7505382
|
309
|
+
end
|
310
|
+
end
|
311
|
+
context "without :follow passed" do
|
312
|
+
before do
|
313
|
+
stub_get("/1.1/friends/ids.json").
|
314
|
+
with(:query => {:cursor => "-1"}).
|
315
|
+
to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
316
|
+
stub_post("/1.1/users/lookup.json").
|
317
|
+
with(:body => {:screen_name => "sferik,pengwynn"}).
|
318
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
319
|
+
stub_post("/1.1/friendships/create.json").
|
320
|
+
with(:body => {:user_id => "7505382"}).
|
321
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
322
|
+
end
|
323
|
+
it "requests the correct resource" do
|
324
|
+
@client.follow("sferik", "pengwynn")
|
325
|
+
a_get("/1.1/friends/ids.json").
|
326
|
+
with(:query => {:cursor => "-1"}).
|
327
|
+
should have_been_made
|
328
|
+
a_post("/1.1/users/lookup.json").
|
329
|
+
with(:body => {:screen_name => "sferik,pengwynn"}).
|
330
|
+
should have_been_made
|
331
|
+
a_post("/1.1/friendships/create.json").
|
332
|
+
with(:body => {:user_id => "7505382"}).
|
333
|
+
should have_been_made
|
334
|
+
end
|
335
|
+
it "returns an array of befriended users" do
|
336
|
+
users = @client.follow("sferik", "pengwynn")
|
337
|
+
users.should be_an Array
|
338
|
+
users.first.should be_a Twitter::User
|
339
|
+
users.first.id.should eq 7505382
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
describe "#follow!" do
|
345
|
+
context "with :follow => true passed" do
|
346
|
+
before do
|
347
|
+
stub_post("/1.1/friendships/create.json").
|
348
|
+
with(:body => {:screen_name => "sferik", :follow => "true"}).
|
349
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
350
|
+
end
|
351
|
+
it "requests the correct resource" do
|
352
|
+
@client.follow!("sferik", :follow => true)
|
353
|
+
a_post("/1.1/friendships/create.json").
|
354
|
+
with(:body => {:screen_name => "sferik", :follow => "true"}).
|
355
|
+
should have_been_made
|
356
|
+
end
|
357
|
+
it "returns an array of befriended users" do
|
358
|
+
users = @client.follow!("sferik", :follow => true)
|
359
|
+
users.should be_an Array
|
360
|
+
users.first.should be_a Twitter::User
|
361
|
+
users.first.id.should eq 7505382
|
362
|
+
end
|
363
|
+
end
|
364
|
+
context "with :follow => false passed" do
|
365
|
+
before do
|
366
|
+
stub_post("/1.1/friendships/create.json").
|
367
|
+
with(:body => {:screen_name => "sferik"}).
|
368
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
369
|
+
end
|
370
|
+
it "requests the correct resource" do
|
371
|
+
@client.follow!("sferik", :follow => false)
|
372
|
+
a_post("/1.1/friendships/create.json").
|
373
|
+
with(:body => {:screen_name => "sferik"}).
|
374
|
+
should have_been_made
|
375
|
+
end
|
376
|
+
it "returns an array of befriended users" do
|
377
|
+
users = @client.follow!("sferik", :follow => false)
|
378
|
+
users.should be_an Array
|
379
|
+
users.first.should be_a Twitter::User
|
380
|
+
users.first.id.should eq 7505382
|
381
|
+
end
|
382
|
+
end
|
383
|
+
context "without :follow passed" do
|
384
|
+
before do
|
385
|
+
stub_post("/1.1/friendships/create.json").
|
386
|
+
with(:body => {:screen_name => "sferik"}).
|
387
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
388
|
+
end
|
389
|
+
it "requests the correct resource" do
|
390
|
+
@client.follow!("sferik")
|
391
|
+
a_post("/1.1/friendships/create.json").
|
392
|
+
with(:body => {:screen_name => "sferik"}).
|
393
|
+
should have_been_made
|
394
|
+
end
|
395
|
+
it "returns an array of befriended users" do
|
396
|
+
users = @client.follow!("sferik")
|
397
|
+
users.should be_an Array
|
398
|
+
users.first.should be_a Twitter::User
|
399
|
+
users.first.id.should eq 7505382
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
describe "#unfollow" do
|
405
|
+
before do
|
406
|
+
stub_post("/1.1/friendships/destroy.json").
|
407
|
+
with(:body => {:screen_name => "sferik"}).
|
408
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
409
|
+
end
|
410
|
+
it "requests the correct resource" do
|
411
|
+
@client.unfollow("sferik")
|
412
|
+
a_post("/1.1/friendships/destroy.json").
|
413
|
+
with(:body => {:screen_name => "sferik"}).
|
414
|
+
should have_been_made
|
415
|
+
end
|
416
|
+
it "returns an array of unfollowed users" do
|
417
|
+
users = @client.friendship_destroy("sferik")
|
418
|
+
users.should be_an Array
|
419
|
+
users.first.should be_a Twitter::User
|
420
|
+
users.first.id.should eq 7505382
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
describe "#friendships" do
|
425
|
+
context "with screen names passed" do
|
426
|
+
before do
|
427
|
+
stub_get("/1.1/friendships/lookup.json").
|
428
|
+
with(:query => {:screen_name => "sferik,pengwynn"}).
|
429
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
430
|
+
end
|
431
|
+
it "requests the correct resource" do
|
432
|
+
@client.friendships("sferik", "pengwynn")
|
433
|
+
a_get("/1.1/friendships/lookup.json").
|
434
|
+
with(:query => {:screen_name => "sferik,pengwynn"}).
|
435
|
+
should have_been_made
|
436
|
+
end
|
437
|
+
it "returns up to 100 users worth of extended information" do
|
438
|
+
friendships = @client.friendships("sferik", "pengwynn")
|
439
|
+
friendships.should be_an Array
|
440
|
+
friendships.first.should be_a Twitter::User
|
441
|
+
friendships.first.id.should eq 7505382
|
442
|
+
friendships.first.connections.should eq ["none"]
|
443
|
+
end
|
444
|
+
end
|
445
|
+
context "with numeric screen names passed" do
|
446
|
+
before do
|
447
|
+
stub_get("/1.1/friendships/lookup.json").
|
448
|
+
with(:query => {:screen_name => "0,311"}).
|
449
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
450
|
+
end
|
451
|
+
it "requests the correct resource" do
|
452
|
+
@client.friendships("0", "311")
|
453
|
+
a_get("/1.1/friendships/lookup.json").
|
454
|
+
with(:query => {:screen_name => "0,311"}).
|
455
|
+
should have_been_made
|
456
|
+
end
|
457
|
+
end
|
458
|
+
context "with user IDs passed" do
|
459
|
+
before do
|
460
|
+
stub_get("/1.1/friendships/lookup.json").
|
461
|
+
with(:query => {:user_id => "7505382,14100886"}).
|
462
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
463
|
+
end
|
464
|
+
it "requests the correct resource" do
|
465
|
+
@client.friendships(7505382, 14100886)
|
466
|
+
a_get("/1.1/friendships/lookup.json").
|
467
|
+
with(:query => {:user_id => "7505382,14100886"}).
|
468
|
+
should have_been_made
|
469
|
+
end
|
470
|
+
end
|
471
|
+
context "with both screen names and user IDs passed" do
|
472
|
+
before do
|
473
|
+
stub_get("/1.1/friendships/lookup.json").
|
474
|
+
with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
|
475
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
476
|
+
end
|
477
|
+
it "requests the correct resource" do
|
478
|
+
@client.friendships("sferik", 14100886)
|
479
|
+
a_get("/1.1/friendships/lookup.json").
|
480
|
+
with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
|
481
|
+
should have_been_made
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
describe "#friendships" do
|
487
|
+
context "with screen names passed" do
|
488
|
+
before do
|
489
|
+
stub_get("/1.1/friendships/lookup.json").
|
490
|
+
with(:query => {:screen_name => "sferik,pengwynn"}).
|
491
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
492
|
+
end
|
493
|
+
it "requests the correct resource" do
|
494
|
+
@client.friendships("sferik", "pengwynn")
|
495
|
+
a_get("/1.1/friendships/lookup.json").
|
496
|
+
with(:query => {:screen_name => "sferik,pengwynn"}).
|
497
|
+
should have_been_made
|
498
|
+
end
|
499
|
+
it "returns up to 100 users worth of extended information" do
|
500
|
+
friendships = @client.friendships("sferik", "pengwynn")
|
501
|
+
friendships.should be_an Array
|
502
|
+
friendships.first.should be_a Twitter::User
|
503
|
+
friendships.first.id.should eq 7505382
|
504
|
+
friendships.first.connections.should eq ["none"]
|
505
|
+
end
|
506
|
+
end
|
507
|
+
context "with numeric screen names passed" do
|
508
|
+
before do
|
509
|
+
stub_get("/1.1/friendships/lookup.json").
|
510
|
+
with(:query => {:screen_name => "0,311"}).
|
511
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
512
|
+
end
|
513
|
+
it "requests the correct resource" do
|
514
|
+
@client.friendships("0", "311")
|
515
|
+
a_get("/1.1/friendships/lookup.json").
|
516
|
+
with(:query => {:screen_name => "0,311"}).
|
517
|
+
should have_been_made
|
518
|
+
end
|
519
|
+
end
|
520
|
+
context "with user IDs passed" do
|
521
|
+
before do
|
522
|
+
stub_get("/1.1/friendships/lookup.json").
|
523
|
+
with(:query => {:user_id => "7505382,14100886"}).
|
524
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
525
|
+
end
|
526
|
+
it "requests the correct resource" do
|
527
|
+
@client.friendships(7505382, 14100886)
|
528
|
+
a_get("/1.1/friendships/lookup.json").
|
529
|
+
with(:query => {:user_id => "7505382,14100886"}).
|
530
|
+
should have_been_made
|
531
|
+
end
|
532
|
+
end
|
533
|
+
context "with both screen names and user IDs passed" do
|
534
|
+
before do
|
535
|
+
stub_get("/1.1/friendships/lookup.json").
|
536
|
+
with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
|
537
|
+
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
538
|
+
end
|
539
|
+
it "requests the correct resource" do
|
540
|
+
@client.friendships("sferik", 14100886)
|
541
|
+
a_get("/1.1/friendships/lookup.json").
|
542
|
+
with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
|
543
|
+
should have_been_made
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
describe "#friendship_update" do
|
549
|
+
before do
|
550
|
+
stub_post("/1.1/friendships/update.json").
|
551
|
+
with(:body => {:screen_name => "sferik", :retweets => "true"}).
|
552
|
+
to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
553
|
+
end
|
554
|
+
it "requests the correct resource" do
|
555
|
+
@client.friendship_update("sferik", :retweets => true)
|
556
|
+
a_post("/1.1/friendships/update.json").
|
557
|
+
with(:body => {:screen_name => "sferik", :retweets => "true"}).
|
558
|
+
should have_been_made
|
559
|
+
end
|
560
|
+
it "returns detailed information about the relationship between two users" do
|
561
|
+
relationship = @client.friendship_update("sferik", :retweets => true)
|
562
|
+
relationship.should be_a Twitter::Relationship
|
563
|
+
relationship.source.id.should eq 7505382
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
end
|