ifttt-twitter 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/.yardopts +8 -0
- data/Gemfile +7 -0
- data/HISTORY.md +520 -0
- data/LICENSE.md +20 -0
- data/README.md +251 -0
- data/Rakefile +13 -0
- data/lib/twitter.rb +24 -0
- data/lib/twitter/action.rb +9 -0
- data/lib/twitter/action_factory.rb +28 -0
- data/lib/twitter/authenticatable.rb +24 -0
- data/lib/twitter/base.rb +40 -0
- data/lib/twitter/client.rb +126 -0
- data/lib/twitter/client/accounts.rb +180 -0
- data/lib/twitter/client/activity.rb +48 -0
- data/lib/twitter/client/block.rb +104 -0
- data/lib/twitter/client/direct_messages.rb +110 -0
- data/lib/twitter/client/favorites.rb +82 -0
- data/lib/twitter/client/friends_and_followers.rb +293 -0
- data/lib/twitter/client/help.rb +38 -0
- data/lib/twitter/client/legal.rb +32 -0
- data/lib/twitter/client/lists.rb +643 -0
- data/lib/twitter/client/local_trends.rb +46 -0
- data/lib/twitter/client/notification.rb +49 -0
- data/lib/twitter/client/places_and_geo.rb +113 -0
- data/lib/twitter/client/saved_searches.rb +73 -0
- data/lib/twitter/client/search.rb +94 -0
- data/lib/twitter/client/spam_reporting.rb +30 -0
- data/lib/twitter/client/suggested_users.rb +60 -0
- data/lib/twitter/client/timelines.rb +265 -0
- data/lib/twitter/client/trends.rb +55 -0
- data/lib/twitter/client/tweets.rb +191 -0
- data/lib/twitter/client/urls.rb +26 -0
- data/lib/twitter/client/users.rb +203 -0
- data/lib/twitter/config.rb +106 -0
- data/lib/twitter/configuration.rb +20 -0
- data/lib/twitter/connection.rb +43 -0
- data/lib/twitter/core_ext/hash.rb +81 -0
- data/lib/twitter/creatable.rb +14 -0
- data/lib/twitter/cursor.rb +44 -0
- data/lib/twitter/direct_message.rb +27 -0
- data/lib/twitter/error.rb +37 -0
- data/lib/twitter/error/bad_gateway.rb +7 -0
- data/lib/twitter/error/bad_request.rb +7 -0
- data/lib/twitter/error/client_error.rb +7 -0
- data/lib/twitter/error/enhance_your_calm.rb +13 -0
- data/lib/twitter/error/forbidden.rb +7 -0
- data/lib/twitter/error/internal_server_error.rb +7 -0
- data/lib/twitter/error/not_acceptable.rb +7 -0
- data/lib/twitter/error/not_found.rb +7 -0
- data/lib/twitter/error/server_error.rb +7 -0
- data/lib/twitter/error/service_unavailable.rb +7 -0
- data/lib/twitter/error/unauthorized.rb +7 -0
- data/lib/twitter/favorite.rb +28 -0
- data/lib/twitter/follow.rb +27 -0
- data/lib/twitter/geo_factory.rb +22 -0
- data/lib/twitter/language.rb +7 -0
- data/lib/twitter/list.rb +22 -0
- data/lib/twitter/list_member_added.rb +36 -0
- data/lib/twitter/media_factory.rb +21 -0
- data/lib/twitter/mention.rb +43 -0
- data/lib/twitter/metadata.rb +7 -0
- data/lib/twitter/oembed.rb +8 -0
- data/lib/twitter/photo.rb +24 -0
- data/lib/twitter/place.rb +36 -0
- data/lib/twitter/point.rb +27 -0
- data/lib/twitter/polygon.rb +14 -0
- data/lib/twitter/rate_limit_status.rb +15 -0
- data/lib/twitter/relationship.rb +18 -0
- data/lib/twitter/reply.rb +36 -0
- data/lib/twitter/request.rb +38 -0
- data/lib/twitter/request/gateway.rb +20 -0
- data/lib/twitter/request/multipart_with_file.rb +37 -0
- data/lib/twitter/request/oauth.rb +26 -0
- data/lib/twitter/request/phoenix.rb +22 -0
- data/lib/twitter/response/parse_json.rb +28 -0
- data/lib/twitter/response/raise_client_error.rb +49 -0
- data/lib/twitter/response/raise_server_error.rb +23 -0
- data/lib/twitter/retweet.rb +36 -0
- data/lib/twitter/saved_search.rb +16 -0
- data/lib/twitter/settings.rb +17 -0
- data/lib/twitter/size.rb +16 -0
- data/lib/twitter/status.rb +80 -0
- data/lib/twitter/suggestion.rb +22 -0
- data/lib/twitter/trend.rb +14 -0
- data/lib/twitter/user.rb +65 -0
- data/lib/twitter/version.rb +30 -0
- data/spec/faraday/request_spec.rb +25 -0
- data/spec/faraday/response_spec.rb +68 -0
- data/spec/fixtures/about_me.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/false.json +1 -0
- data/spec/fixtures/favorites.json +1 -0
- data/spec/fixtures/forbidden.json +1 -0
- data/spec/fixtures/friendships.json +1 -0
- data/spec/fixtures/id_list.json +1 -0
- data/spec/fixtures/ids.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/n605431196_2079896_558_normal.jpg +0 -0
- data/spec/fixtures/no_user_matches.json +1 -0
- data/spec/fixtures/not_acceptable.json +1 -0
- data/spec/fixtures/not_found.json +1 -0
- data/spec/fixtures/oembed.json +1 -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/relationship.json +1 -0
- data/spec/fixtures/resolve.json +1 -0
- data/spec/fixtures/retweet.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/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/true.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/helper.rb +49 -0
- data/spec/twitter/action_factory_spec.rb +37 -0
- data/spec/twitter/action_spec.rb +16 -0
- data/spec/twitter/base_spec.rb +29 -0
- data/spec/twitter/client/accounts_spec.rb +181 -0
- data/spec/twitter/client/activity_spec.rb +43 -0
- data/spec/twitter/client/block_spec.rb +106 -0
- data/spec/twitter/client/direct_messages_spec.rb +98 -0
- data/spec/twitter/client/favorites_spec.rb +80 -0
- data/spec/twitter/client/friends_and_followers_spec.rb +478 -0
- data/spec/twitter/client/help_spec.rb +44 -0
- data/spec/twitter/client/legal_spec.rb +41 -0
- data/spec/twitter/client/lists_spec.rb +1104 -0
- data/spec/twitter/client/local_trends_spec.rb +58 -0
- data/spec/twitter/client/notification_spec.rb +47 -0
- data/spec/twitter/client/places_and_geo_spec.rb +100 -0
- data/spec/twitter/client/saved_searches_spec.rb +80 -0
- data/spec/twitter/client/search_spec.rb +92 -0
- data/spec/twitter/client/spam_reporting_spec.rb +28 -0
- data/spec/twitter/client/suggested_users_spec.rb +65 -0
- data/spec/twitter/client/timelines_spec.rb +231 -0
- data/spec/twitter/client/trends_spec.rb +51 -0
- data/spec/twitter/client/tweets_spec.rb +189 -0
- data/spec/twitter/client/urls_spec.rb +31 -0
- data/spec/twitter/client/users_spec.rb +323 -0
- data/spec/twitter/client_spec.rb +94 -0
- data/spec/twitter/configuration_spec.rb +17 -0
- data/spec/twitter/cursor_spec.rb +43 -0
- data/spec/twitter/direct_message_spec.rb +56 -0
- data/spec/twitter/favorite_spec.rb +29 -0
- data/spec/twitter/follow_spec.rb +29 -0
- data/spec/twitter/geo_factory_spec.rb +21 -0
- data/spec/twitter/list_spec.rb +34 -0
- data/spec/twitter/media_factory_spec.rb +17 -0
- data/spec/twitter/mention_spec.rb +52 -0
- data/spec/twitter/oembed_spec.rb +145 -0
- data/spec/twitter/photo_spec.rb +35 -0
- data/spec/twitter/place_spec.rb +75 -0
- data/spec/twitter/point_spec.rb +32 -0
- data/spec/twitter/polygon_spec.rb +18 -0
- data/spec/twitter/rate_limit_status_spec.rb +16 -0
- data/spec/twitter/relationship_spec.rb +27 -0
- data/spec/twitter/reply_spec.rb +41 -0
- data/spec/twitter/retweet_spec.rb +41 -0
- data/spec/twitter/saved_search_spec.rb +34 -0
- data/spec/twitter/settings_spec.rb +16 -0
- data/spec/twitter/size_spec.rb +18 -0
- data/spec/twitter/status_spec.rb +148 -0
- data/spec/twitter/suggestion_spec.rb +20 -0
- data/spec/twitter/trend_spec.rb +20 -0
- data/spec/twitter/user_spec.rb +50 -0
- data/spec/twitter_spec.rb +91 -0
- data/twitter.gemspec +42 -0
- metadata +564 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Client do
|
4
|
+
before do
|
5
|
+
@client = Twitter::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".resolve" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
stub_get("/1/urls/resolve.json").
|
12
|
+
with(:query => {:urls => ["http://t.co/uw5bn1w"]}).
|
13
|
+
to_return(:body => fixture("resolve.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should request the correct resource" do
|
17
|
+
@client.resolve('http://t.co/uw5bn1w')
|
18
|
+
a_get("/1/urls/resolve.json").
|
19
|
+
with(:query => {:urls => ["http://t.co/uw5bn1w"]}).
|
20
|
+
with(:headers => {'X-Phx' => 'true'}).
|
21
|
+
should have_been_made
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return the canonical version of a URL shortened by Twitter" do
|
25
|
+
resolve = @client.resolve('http://t.co/uw5bn1w')
|
26
|
+
resolve.should be_a Hash
|
27
|
+
resolve["http://t.co/uw5bn1w"].should == "http://www.jeanniejeannie.com/2011/08/29/the-art-of-clean-up-sorting-and-stacking-everyday-objects/"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Client do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".users" do
|
10
|
+
context "with screen names passed" do
|
11
|
+
before do
|
12
|
+
stub_get("/1/users/lookup.json").
|
13
|
+
with(:query => {:screen_name => "sferik,pengwynn"}).
|
14
|
+
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
15
|
+
end
|
16
|
+
it "should request the correct resource" do
|
17
|
+
@client.users("sferik", "pengwynn")
|
18
|
+
a_get("/1/users/lookup.json").
|
19
|
+
with(:query => {:screen_name => "sferik,pengwynn"}).
|
20
|
+
should have_been_made
|
21
|
+
end
|
22
|
+
it "should return up to 100 users worth of extended information" do
|
23
|
+
users = @client.users("sferik", "pengwynn")
|
24
|
+
users.should be_an Array
|
25
|
+
users.first.should be_a Twitter::User
|
26
|
+
users.first.name.should == "Erik Michaels-Ober"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context "with numeric screen names passed" do
|
30
|
+
before do
|
31
|
+
stub_get("/1/users/lookup.json").
|
32
|
+
with(:query => {:screen_name => "0,311"}).
|
33
|
+
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
34
|
+
end
|
35
|
+
it "should request the correct resource" do
|
36
|
+
@client.users("0", "311")
|
37
|
+
a_get("/1/users/lookup.json").
|
38
|
+
with(:query => {:screen_name => "0,311"}).
|
39
|
+
should have_been_made
|
40
|
+
end
|
41
|
+
end
|
42
|
+
context "with user IDs passed" do
|
43
|
+
before do
|
44
|
+
stub_get("/1/users/lookup.json").
|
45
|
+
with(:query => {:user_id => "7505382,14100886"}).
|
46
|
+
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
47
|
+
end
|
48
|
+
it "should request the correct resource" do
|
49
|
+
@client.users(7505382, 14100886)
|
50
|
+
a_get("/1/users/lookup.json").
|
51
|
+
with(:query => {:user_id => "7505382,14100886"}).
|
52
|
+
should have_been_made
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context "with both screen names and user IDs passed" do
|
56
|
+
before do
|
57
|
+
stub_get("/1/users/lookup.json").
|
58
|
+
with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
|
59
|
+
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
60
|
+
end
|
61
|
+
it "should request the correct resource" do
|
62
|
+
@client.users("sferik", 14100886)
|
63
|
+
a_get("/1/users/lookup.json").
|
64
|
+
with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
|
65
|
+
should have_been_made
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe ".profile_image" do
|
71
|
+
context "with a screen name passed" do
|
72
|
+
before do
|
73
|
+
stub_get("/1/users/profile_image/sferik").
|
74
|
+
to_return(fixture("profile_image.text"))
|
75
|
+
end
|
76
|
+
it "should redirect to the correct resource" do
|
77
|
+
profile_image = @client.profile_image("sferik")
|
78
|
+
a_get("/1/users/profile_image/sferik").
|
79
|
+
with(:status => 302).
|
80
|
+
should have_been_made
|
81
|
+
profile_image.should == "http://a0.twimg.com/profile_images/323331048/me_normal.jpg"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
context "without a screen name passed" do
|
85
|
+
before do
|
86
|
+
stub_get("/1/account/verify_credentials.json").
|
87
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
88
|
+
stub_get("/1/users/profile_image/sferik").
|
89
|
+
to_return(fixture("profile_image.text"))
|
90
|
+
end
|
91
|
+
it "should redirect to the correct resource" do
|
92
|
+
profile_image = @client.profile_image
|
93
|
+
a_get("/1/users/profile_image/sferik").
|
94
|
+
with(:status => 302).
|
95
|
+
should have_been_made
|
96
|
+
profile_image.should == "http://a0.twimg.com/profile_images/323331048/me_normal.jpg"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe ".user_search" do
|
102
|
+
before do
|
103
|
+
stub_get("/1/users/search.json").
|
104
|
+
with(:query => {:q => "Erik Michaels-Ober"}).
|
105
|
+
to_return(:body => fixture("user_search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
106
|
+
end
|
107
|
+
it "should request the correct resource" do
|
108
|
+
@client.user_search("Erik Michaels-Ober")
|
109
|
+
a_get("/1/users/search.json").
|
110
|
+
with(:query => {:q => "Erik Michaels-Ober"}).
|
111
|
+
should have_been_made
|
112
|
+
end
|
113
|
+
it "should return an array of user search results" do
|
114
|
+
user_search = @client.user_search("Erik Michaels-Ober")
|
115
|
+
user_search.should be_an Array
|
116
|
+
user_search.first.should be_a Twitter::User
|
117
|
+
user_search.first.name.should == "Erik Michaels-Ober"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe ".user" do
|
122
|
+
context "with a screen name passed" do
|
123
|
+
before do
|
124
|
+
stub_get("/1/users/show.json").
|
125
|
+
with(:query => {:screen_name => "sferik"}).
|
126
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
127
|
+
end
|
128
|
+
it "should request the correct resource" do
|
129
|
+
@client.user("sferik")
|
130
|
+
a_get("/1/users/show.json").
|
131
|
+
with(:query => {:screen_name => "sferik"}).
|
132
|
+
should have_been_made
|
133
|
+
end
|
134
|
+
it "should return extended information of a given user" do
|
135
|
+
user = @client.user("sferik")
|
136
|
+
user.should be_a Twitter::User
|
137
|
+
user.name.should == "Erik Michaels-Ober"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
context "with a screen name including '@' passed" do
|
141
|
+
before do
|
142
|
+
stub_get("/1/users/show.json").
|
143
|
+
with(:query => {:screen_name => "@sferik"}).
|
144
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
145
|
+
end
|
146
|
+
it "should request the correct resource" do
|
147
|
+
@client.user("@sferik")
|
148
|
+
a_get("/1/users/show.json").
|
149
|
+
with(:query => {:screen_name => "@sferik"}).
|
150
|
+
should have_been_made
|
151
|
+
end
|
152
|
+
end
|
153
|
+
context "with a numeric screen name passed" do
|
154
|
+
before do
|
155
|
+
stub_get("/1/users/show.json").
|
156
|
+
with(:query => {:screen_name => "0"}).
|
157
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
158
|
+
end
|
159
|
+
it "should request the correct resource" do
|
160
|
+
@client.user("0")
|
161
|
+
a_get("/1/users/show.json").
|
162
|
+
with(:query => {:screen_name => "0"}).
|
163
|
+
should have_been_made
|
164
|
+
end
|
165
|
+
end
|
166
|
+
context "with a user ID passed" do
|
167
|
+
before do
|
168
|
+
stub_get("/1/users/show.json").
|
169
|
+
with(:query => {:user_id => "7505382"}).
|
170
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
171
|
+
end
|
172
|
+
it "should request the correct resource" do
|
173
|
+
@client.user(7505382)
|
174
|
+
a_get("/1/users/show.json").
|
175
|
+
with(:query => {:user_id => "7505382"}).
|
176
|
+
should have_been_made
|
177
|
+
end
|
178
|
+
end
|
179
|
+
context "without a screen name or user ID passed" do
|
180
|
+
before do
|
181
|
+
stub_get("/1/account/verify_credentials.json").
|
182
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
183
|
+
end
|
184
|
+
it "should request the correct resource" do
|
185
|
+
@client.user
|
186
|
+
a_get("/1/account/verify_credentials.json").
|
187
|
+
should have_been_made
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe ".user?" do
|
193
|
+
before do
|
194
|
+
stub_get("/1/users/show.json").
|
195
|
+
with(:query => {:screen_name => "sferik"}).
|
196
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
197
|
+
stub_get("/1/users/show.json").
|
198
|
+
with(:query => {:screen_name => "pengwynn"}).
|
199
|
+
to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
200
|
+
end
|
201
|
+
it "should request the correct resource" do
|
202
|
+
@client.user?("sferik")
|
203
|
+
a_get("/1/users/show.json").
|
204
|
+
with(:query => {:screen_name => "sferik"}).
|
205
|
+
should have_been_made
|
206
|
+
end
|
207
|
+
it "should return true if user exists" do
|
208
|
+
user = @client.user?("sferik")
|
209
|
+
user.should be_true
|
210
|
+
end
|
211
|
+
it "should return false if user does not exist" do
|
212
|
+
user = @client.user?("pengwynn")
|
213
|
+
user.should be_false
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe ".contributees" do
|
218
|
+
context "with a screen name passed" do
|
219
|
+
before do
|
220
|
+
stub_get("/1/users/contributees.json").
|
221
|
+
with(:query => {:screen_name => "sferik"}).
|
222
|
+
to_return(:body => fixture("contributees.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
223
|
+
end
|
224
|
+
it "should request the correct resource" do
|
225
|
+
@client.contributees("sferik")
|
226
|
+
a_get("/1/users/contributees.json").
|
227
|
+
with(:query => {:screen_name => "sferik"}).
|
228
|
+
should have_been_made
|
229
|
+
end
|
230
|
+
it "should return a user's contributees" do
|
231
|
+
contributees = @client.contributees("sferik")
|
232
|
+
contributees.should be_an Array
|
233
|
+
contributees.first.should be_a Twitter::User
|
234
|
+
contributees.first.name.should == "Twitter API"
|
235
|
+
end
|
236
|
+
end
|
237
|
+
context "without arguments passed" do
|
238
|
+
before do
|
239
|
+
stub_get("/1/account/verify_credentials.json").
|
240
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
241
|
+
stub_get("/1/users/contributees.json").
|
242
|
+
with(:query => {:screen_name => "sferik"}).
|
243
|
+
to_return(:body => fixture("contributees.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
244
|
+
end
|
245
|
+
it "should request the correct resource" do
|
246
|
+
@client.contributees
|
247
|
+
a_get("/1/users/contributees.json").
|
248
|
+
with(:query => {:screen_name => "sferik"}).
|
249
|
+
should have_been_made
|
250
|
+
end
|
251
|
+
it "should return a user's contributees" do
|
252
|
+
contributees = @client.contributees
|
253
|
+
contributees.should be_an Array
|
254
|
+
contributees.first.should be_a Twitter::User
|
255
|
+
contributees.first.name.should == "Twitter API"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe ".contributors" do
|
261
|
+
context "with a screen name passed" do
|
262
|
+
before do
|
263
|
+
stub_get("/1/account/verify_credentials.json").
|
264
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
265
|
+
stub_get("/1/users/contributors.json").
|
266
|
+
with(:query => {:screen_name => "sferik"}).
|
267
|
+
to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
268
|
+
end
|
269
|
+
it "should request the correct resource" do
|
270
|
+
@client.contributors("sferik")
|
271
|
+
a_get("/1/users/contributors.json").
|
272
|
+
with(:query => {:screen_name => "sferik"}).
|
273
|
+
should have_been_made
|
274
|
+
end
|
275
|
+
it "should return a user's contributors" do
|
276
|
+
contributors = @client.contributors("sferik")
|
277
|
+
contributors.should be_an Array
|
278
|
+
contributors.first.should be_a Twitter::User
|
279
|
+
contributors.first.name.should == "Biz Stone"
|
280
|
+
end
|
281
|
+
end
|
282
|
+
context "without arguments passed" do
|
283
|
+
before do
|
284
|
+
stub_get("/1/account/verify_credentials.json").
|
285
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
286
|
+
stub_get("/1/users/contributors.json").
|
287
|
+
with(:query => {:screen_name => "sferik"}).
|
288
|
+
to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
289
|
+
end
|
290
|
+
it "should request the correct resource" do
|
291
|
+
@client.contributors
|
292
|
+
a_get("/1/users/contributors.json").
|
293
|
+
with(:query => {:screen_name => "sferik"}).
|
294
|
+
should have_been_made
|
295
|
+
end
|
296
|
+
it "should return a user's contributors" do
|
297
|
+
contributors = @client.contributors
|
298
|
+
contributors.should be_an Array
|
299
|
+
contributors.first.should be_a Twitter::User
|
300
|
+
contributors.first.name.should == "Biz Stone"
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe ".recommendations" do
|
306
|
+
before do
|
307
|
+
stub_get("/1/users/recommendations.json").
|
308
|
+
to_return(:body => fixture("recommendations.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
309
|
+
end
|
310
|
+
it "should request the correct resource" do
|
311
|
+
@client.recommendations
|
312
|
+
a_get("/1/users/recommendations.json").
|
313
|
+
should have_been_made
|
314
|
+
end
|
315
|
+
it "should return recommended users for the authenticated user" do
|
316
|
+
recommendations = @client.recommendations
|
317
|
+
recommendations.should be_an Array
|
318
|
+
recommendations.first.should be_a Twitter::User
|
319
|
+
recommendations.first.name.should == "John Trupiano"
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Client do
|
4
|
+
before do
|
5
|
+
@keys = Twitter::Config::VALID_OPTIONS_KEYS
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with module configuration" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
Twitter.configure do |config|
|
12
|
+
@keys.each do |key|
|
13
|
+
config.send("#{key}=", key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Twitter.reset
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should inherit module configuration" do
|
23
|
+
api = Twitter::Client.new
|
24
|
+
@keys.each do |key|
|
25
|
+
api.send(key).should == key
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with class configuration" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
@configuration = {
|
33
|
+
:consumer_key => 'CK',
|
34
|
+
:consumer_secret => 'CS',
|
35
|
+
:oauth_token => 'OT',
|
36
|
+
:oauth_token_secret => 'OS',
|
37
|
+
:adapter => :typhoeus,
|
38
|
+
:endpoint => 'http://tumblr.com/',
|
39
|
+
:gateway => 'apigee-1111.apigee.com',
|
40
|
+
:proxy => 'http://erik:sekret@proxy.example.com:8080',
|
41
|
+
:search_endpoint => 'http://google.com/',
|
42
|
+
:media_endpoint => 'https://upload.twitter.com/',
|
43
|
+
:user_agent => 'Custom User Agent',
|
44
|
+
:connection_options => {:timeout => 10},
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
context "during initialization" do
|
49
|
+
it "should override module configuration" do
|
50
|
+
api = Twitter::Client.new(@configuration)
|
51
|
+
@keys.each do |key|
|
52
|
+
api.send(key).should == @configuration[key]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "after initilization" do
|
58
|
+
it "should override module configuration after initialization" do
|
59
|
+
api = Twitter::Client.new
|
60
|
+
@configuration.each do |key, value|
|
61
|
+
api.send("#{key}=", value)
|
62
|
+
end
|
63
|
+
@keys.each do |key|
|
64
|
+
api.send(key).should == @configuration[key]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not cache the screen name across clients" do
|
73
|
+
stub_get("/1/account/verify_credentials.json").
|
74
|
+
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
75
|
+
client1 = Twitter::Client.new
|
76
|
+
client1.current_user.screen_name.should == 'sferik'
|
77
|
+
stub_get("/1/account/verify_credentials.json").
|
78
|
+
to_return(:body => fixture("pengwynn.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
79
|
+
client2 = Twitter::Client.new
|
80
|
+
client2.current_user.screen_name.should == 'pengwynn'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should recursively merge connection options" do
|
84
|
+
stub_get("/1/statuses/user_timeline.json").
|
85
|
+
with(:query => {:screen_name => "sferik"}, :headers => {"Accept" => "application/json", "User-Agent" => "Custom User Agent"}).
|
86
|
+
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
87
|
+
client = Twitter::Client.new(:connection_options => {:headers => {:user_agent => 'Custom User Agent'}})
|
88
|
+
client.user_timeline("sferik")
|
89
|
+
a_get("/1/statuses/user_timeline.json").
|
90
|
+
with(:query => {:screen_name => "sferik"}, :headers => {"User-Agent" => "Custom User Agent"}).
|
91
|
+
should have_been_made
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|