twitter 4.8.1 → 5.0.0.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +30 -0
- data/LICENSE.md +1 -1
- data/README.md +386 -266
- data/lib/twitter.rb +4 -39
- data/lib/twitter/arguments.rb +11 -0
- data/lib/twitter/base.rb +89 -68
- data/lib/twitter/client.rb +69 -110
- data/lib/twitter/configuration.rb +7 -3
- data/lib/twitter/creatable.rb +2 -4
- data/lib/twitter/cursor.rb +50 -42
- data/lib/twitter/direct_message.rb +2 -11
- data/lib/twitter/entity/uri.rb +13 -0
- data/lib/twitter/enumerable.rb +15 -0
- data/lib/twitter/error.rb +55 -7
- data/lib/twitter/error/already_favorited.rb +1 -1
- data/lib/twitter/error/already_posted.rb +10 -0
- data/lib/twitter/error/already_retweeted.rb +1 -1
- data/lib/twitter/error/bad_gateway.rb +2 -3
- data/lib/twitter/error/bad_request.rb +2 -2
- data/lib/twitter/error/forbidden.rb +2 -2
- data/lib/twitter/error/gateway_timeout.rb +2 -3
- data/lib/twitter/error/internal_server_error.rb +2 -3
- data/lib/twitter/error/not_acceptable.rb +2 -2
- data/lib/twitter/error/not_found.rb +2 -2
- data/lib/twitter/error/service_unavailable.rb +2 -3
- data/lib/twitter/error/too_many_requests.rb +2 -2
- data/lib/twitter/error/unauthorized.rb +2 -2
- data/lib/twitter/error/unprocessable_entity.rb +2 -2
- data/lib/twitter/factory.rb +2 -8
- data/lib/twitter/geo_factory.rb +2 -2
- data/lib/twitter/geo_results.rb +36 -0
- data/lib/twitter/identity.rb +0 -22
- data/lib/twitter/list.rb +18 -4
- data/lib/twitter/media/photo.rb +3 -3
- data/lib/twitter/media_factory.rb +2 -2
- data/lib/twitter/null_object.rb +24 -0
- data/lib/twitter/oembed.rb +3 -2
- data/lib/twitter/place.rb +15 -9
- data/lib/twitter/profile_banner.rb +5 -3
- data/lib/twitter/rate_limit.rb +1 -17
- data/lib/twitter/relationship.rb +2 -10
- data/lib/twitter/rest/api/direct_messages.rb +135 -0
- data/lib/twitter/rest/api/favorites.rb +120 -0
- data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
- data/lib/twitter/rest/api/help.rb +58 -0
- data/lib/twitter/rest/api/lists.rb +491 -0
- data/lib/twitter/rest/api/oauth.rb +45 -0
- data/lib/twitter/rest/api/places_and_geo.rb +104 -0
- data/lib/twitter/rest/api/saved_searches.rb +91 -0
- data/lib/twitter/rest/api/search.rb +37 -0
- data/lib/twitter/rest/api/spam_reporting.rb +29 -0
- data/lib/twitter/rest/api/suggested_users.rb +51 -0
- data/lib/twitter/rest/api/timelines.rb +202 -0
- data/lib/twitter/rest/api/trends.rb +58 -0
- data/lib/twitter/rest/api/tweets.rb +293 -0
- data/lib/twitter/rest/api/undocumented.rb +52 -0
- data/lib/twitter/rest/api/users.rb +383 -0
- data/lib/twitter/rest/api/utils.rb +219 -0
- data/lib/twitter/rest/client.rb +193 -0
- data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
- data/lib/twitter/rest/response/parse_json.rb +27 -0
- data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
- data/lib/twitter/search_results.rb +33 -21
- data/lib/twitter/settings.rb +1 -6
- data/lib/twitter/size.rb +1 -1
- data/lib/twitter/streaming/client.rb +77 -0
- data/lib/twitter/streaming/connection.rb +22 -0
- data/lib/twitter/streaming/response.rb +30 -0
- data/lib/twitter/suggestion.rb +4 -2
- data/lib/twitter/token.rb +8 -0
- data/lib/twitter/trend.rb +2 -1
- data/lib/twitter/trend_results.rb +59 -0
- data/lib/twitter/tweet.rb +41 -85
- data/lib/twitter/user.rb +51 -41
- data/lib/twitter/version.rb +4 -4
- data/spec/fixtures/already_posted.json +1 -0
- data/spec/fixtures/ids_list.json +1 -1
- data/spec/fixtures/ids_list2.json +1 -1
- data/spec/fixtures/search.json +1 -1
- data/spec/fixtures/search_malformed.json +1 -1
- data/spec/fixtures/track_streaming.json +3 -0
- data/spec/helper.rb +8 -13
- data/spec/twitter/base_spec.rb +25 -99
- data/spec/twitter/configuration_spec.rb +1 -1
- data/spec/twitter/cursor_spec.rb +13 -31
- data/spec/twitter/direct_message_spec.rb +41 -8
- data/spec/twitter/entity/uri_spec.rb +74 -0
- data/spec/twitter/error_spec.rb +59 -11
- data/spec/twitter/geo/point_spec.rb +1 -1
- data/spec/twitter/geo_factory_spec.rb +3 -3
- data/spec/twitter/geo_results_spec.rb +35 -0
- data/spec/twitter/identifiable_spec.rb +0 -21
- data/spec/twitter/list_spec.rb +51 -8
- data/spec/twitter/media/photo_spec.rb +118 -3
- data/spec/twitter/media_factory_spec.rb +2 -2
- data/spec/twitter/null_object_spec.rb +26 -0
- data/spec/twitter/oembed_spec.rb +69 -45
- data/spec/twitter/place_spec.rb +68 -12
- data/spec/twitter/profile_banner_spec.rb +1 -1
- data/spec/twitter/rate_limit_spec.rb +12 -12
- data/spec/twitter/relationship_spec.rb +31 -9
- data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
- data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
- data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
- data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
- data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
- data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
- data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
- data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
- data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
- data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
- data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
- data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
- data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
- data/spec/twitter/rest/api/tweets_spec.rb +503 -0
- data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
- data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
- data/spec/twitter/rest/client_spec.rb +193 -0
- data/spec/twitter/saved_search_spec.rb +11 -0
- data/spec/twitter/search_results_spec.rb +29 -42
- data/spec/twitter/settings_spec.rb +17 -6
- data/spec/twitter/streaming/client_spec.rb +75 -0
- data/spec/twitter/token_spec.rb +16 -0
- data/spec/twitter/trend_results_spec.rb +89 -0
- data/spec/twitter/trend_spec.rb +23 -0
- data/spec/twitter/tweet_spec.rb +122 -115
- data/spec/twitter/user_spec.rb +136 -77
- data/spec/twitter_spec.rb +0 -119
- data/twitter.gemspec +8 -5
- metadata +148 -141
- metadata.gz.sig +0 -0
- data/lib/twitter/action/favorite.rb +0 -19
- data/lib/twitter/action/follow.rb +0 -30
- data/lib/twitter/action/list_member_added.rb +0 -39
- data/lib/twitter/action/mention.rb +0 -46
- data/lib/twitter/action/reply.rb +0 -27
- data/lib/twitter/action/retweet.rb +0 -27
- data/lib/twitter/action/tweet.rb +0 -20
- data/lib/twitter/action_factory.rb +0 -22
- data/lib/twitter/api/arguments.rb +0 -13
- data/lib/twitter/api/direct_messages.rb +0 -148
- data/lib/twitter/api/favorites.rb +0 -126
- data/lib/twitter/api/friends_and_followers.rb +0 -334
- data/lib/twitter/api/help.rb +0 -64
- data/lib/twitter/api/lists.rb +0 -618
- data/lib/twitter/api/oauth.rb +0 -44
- data/lib/twitter/api/places_and_geo.rb +0 -121
- data/lib/twitter/api/saved_searches.rb +0 -99
- data/lib/twitter/api/search.rb +0 -37
- data/lib/twitter/api/spam_reporting.rb +0 -30
- data/lib/twitter/api/suggested_users.rb +0 -55
- data/lib/twitter/api/timelines.rb +0 -214
- data/lib/twitter/api/trends.rb +0 -63
- data/lib/twitter/api/tweets.rb +0 -304
- data/lib/twitter/api/undocumented.rb +0 -97
- data/lib/twitter/api/users.rb +0 -439
- data/lib/twitter/api/utils.rb +0 -187
- data/lib/twitter/configurable.rb +0 -96
- data/lib/twitter/default.rb +0 -102
- data/lib/twitter/entity/url.rb +0 -9
- data/lib/twitter/error/client_error.rb +0 -35
- data/lib/twitter/error/decode_error.rb +0 -9
- data/lib/twitter/error/identity_map_key_error.rb +0 -9
- data/lib/twitter/error/server_error.rb +0 -28
- data/lib/twitter/exceptable.rb +0 -36
- data/lib/twitter/identity_map.rb +0 -22
- data/lib/twitter/request/multipart_with_file.rb +0 -34
- data/lib/twitter/response/parse_json.rb +0 -25
- data/spec/fixtures/about_me.json +0 -1
- data/spec/fixtures/activity_summary.json +0 -1
- data/spec/fixtures/bad_gateway.json +0 -1
- data/spec/fixtures/bad_request.json +0 -1
- data/spec/fixtures/by_friends.json +0 -1
- data/spec/fixtures/end_session.json +0 -1
- data/spec/fixtures/forbidden.json +0 -1
- data/spec/fixtures/internal_server_error.json +0 -1
- data/spec/fixtures/not_acceptable.json +0 -1
- data/spec/fixtures/phoenix_search.phoenix +0 -1
- data/spec/fixtures/resolve.json +0 -1
- data/spec/fixtures/service_unavailable.json +0 -1
- data/spec/fixtures/totals.json +0 -1
- data/spec/fixtures/trends.json +0 -1
- data/spec/fixtures/unauthorized.json +0 -1
- data/spec/fixtures/video_facets.json +0 -1
- data/spec/twitter/action/favorite_spec.rb +0 -29
- data/spec/twitter/action/follow_spec.rb +0 -29
- data/spec/twitter/action/list_member_added_spec.rb +0 -41
- data/spec/twitter/action/mention_spec.rb +0 -52
- data/spec/twitter/action/reply_spec.rb +0 -41
- data/spec/twitter/action/retweet_spec.rb +0 -41
- data/spec/twitter/action_factory_spec.rb +0 -35
- data/spec/twitter/action_spec.rb +0 -16
- data/spec/twitter/api/tweets_spec.rb +0 -285
- data/spec/twitter/client_spec.rb +0 -223
- data/spec/twitter/error/client_error_spec.rb +0 -23
- data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
describe Twitter::API::Undocumented do
|
3
|
+
describe Twitter::REST::API::Undocumented do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@client = Twitter::Client.new
|
6
|
+
@client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#following_followers_of" do
|
@@ -18,15 +18,14 @@ describe Twitter::API::Undocumented do
|
|
18
18
|
it "returns an array of numeric IDs for every user following the specified user" do
|
19
19
|
following_followers_of = @client.following_followers_of("sferik")
|
20
20
|
expect(following_followers_of).to be_a Twitter::Cursor
|
21
|
-
expect(following_followers_of.
|
22
|
-
expect(following_followers_of.users.first).to be_a Twitter::User
|
21
|
+
expect(following_followers_of.first).to be_a Twitter::User
|
23
22
|
end
|
24
|
-
context "with
|
23
|
+
context "with each" do
|
25
24
|
before do
|
26
25
|
stub_get("/users/following_followers_of.json").with(:query => {:cursor => "1322801608223717003", :screen_name => "sferik"}).to_return(:body => fixture("users_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
27
26
|
end
|
28
27
|
it "requests the correct resource" do
|
29
|
-
@client.following_followers_of("sferik").
|
28
|
+
@client.following_followers_of("sferik").each{}
|
30
29
|
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
|
31
30
|
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "1322801608223717003", :screen_name => "sferik"})).to have_been_made
|
32
31
|
end
|
@@ -40,12 +39,12 @@ describe Twitter::API::Undocumented do
|
|
40
39
|
@client.following_followers_of(7505382)
|
41
40
|
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :user_id => "7505382"})).to have_been_made
|
42
41
|
end
|
43
|
-
context "with
|
42
|
+
context "with each" do
|
44
43
|
before do
|
45
44
|
stub_get("/users/following_followers_of.json").with(:query => {:cursor => "1322801608223717003", :user_id => "7505382"}).to_return(:body => fixture("users_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
46
45
|
end
|
47
46
|
it "requests the correct resource" do
|
48
|
-
@client.following_followers_of(7505382).
|
47
|
+
@client.following_followers_of(7505382).each{}
|
49
48
|
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :user_id => "7505382"})).to have_been_made
|
50
49
|
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "1322801608223717003", :user_id => "7505382"})).to have_been_made
|
51
50
|
end
|
@@ -64,15 +63,14 @@ describe Twitter::API::Undocumented do
|
|
64
63
|
it "returns an array of numeric IDs for every user following the specified user" do
|
65
64
|
following_followers_of = @client.following_followers_of
|
66
65
|
expect(following_followers_of).to be_a Twitter::Cursor
|
67
|
-
expect(following_followers_of.
|
68
|
-
expect(following_followers_of.users.first).to be_a Twitter::User
|
66
|
+
expect(following_followers_of.first).to be_a Twitter::User
|
69
67
|
end
|
70
|
-
context "with
|
68
|
+
context "with each" do
|
71
69
|
before do
|
72
70
|
stub_get("/users/following_followers_of.json").with(:query => {:cursor => "1322801608223717003", :screen_name => "sferik"}).to_return(:body => fixture("users_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
73
71
|
end
|
74
72
|
it "requests the correct resource" do
|
75
|
-
@client.following_followers_of.
|
73
|
+
@client.following_followers_of.each{}
|
76
74
|
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
|
77
75
|
expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "1322801608223717003", :screen_name => "sferik"})).to have_been_made
|
78
76
|
end
|
@@ -80,38 +78,7 @@ describe Twitter::API::Undocumented do
|
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
83
|
-
describe "#
|
84
|
-
before do
|
85
|
-
stub_get("/i/statuses/25938088801/activity/summary.json").to_return(:body => fixture("activity_summary.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
86
|
-
end
|
87
|
-
it "requests the correct resource" do
|
88
|
-
@client.status_activity(25938088801)
|
89
|
-
expect(a_get("/i/statuses/25938088801/activity/summary.json")).to have_been_made
|
90
|
-
end
|
91
|
-
it "returns a Tweet" do
|
92
|
-
tweet = @client.status_activity(25938088801)
|
93
|
-
expect(tweet).to be_a Twitter::Tweet
|
94
|
-
expect(tweet.retweeters_count).to eq 1
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#statuses_activity" do
|
99
|
-
before do
|
100
|
-
stub_get("/i/statuses/25938088801/activity/summary.json").to_return(:body => fixture("activity_summary.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
101
|
-
end
|
102
|
-
it "requests the correct resource" do
|
103
|
-
@client.statuses_activity(25938088801)
|
104
|
-
expect(a_get("/i/statuses/25938088801/activity/summary.json")).to have_been_made
|
105
|
-
end
|
106
|
-
it "returns an array of Tweets" do
|
107
|
-
tweets = @client.statuses_activity(25938088801)
|
108
|
-
expect(tweets).to be_an Array
|
109
|
-
expect(tweets.first).to be_a Twitter::Tweet
|
110
|
-
expect(tweets.first.retweeters_count).to eq 1
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "#statuses_activity" do
|
81
|
+
describe "#tweet_count" do
|
115
82
|
before do
|
116
83
|
stub_request(:get, "https://cdn.api.twitter.com/1/urls/count.json").with(:query => {:url => "http://twitter.com"}).to_return(:body => fixture("count.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
117
84
|
end
|
@@ -122,7 +89,14 @@ describe Twitter::API::Undocumented do
|
|
122
89
|
it "returns a Tweet count" do
|
123
90
|
tweet_count = @client.tweet_count("http://twitter.com")
|
124
91
|
expect(tweet_count).to be_an Integer
|
125
|
-
expect(tweet_count).to eq
|
92
|
+
expect(tweet_count).to eq(13845465)
|
93
|
+
end
|
94
|
+
context "with a URI" do
|
95
|
+
it "requests the correct resource" do
|
96
|
+
uri = URI.parse("http://twitter.com")
|
97
|
+
@client.tweet_count(uri)
|
98
|
+
expect(a_request(:get, "https://cdn.api.twitter.com/1/urls/count.json").with(:query => {:url => "http://twitter.com"})).to have_been_made
|
99
|
+
end
|
126
100
|
end
|
127
101
|
end
|
128
102
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
describe Twitter::API::Users do
|
3
|
+
describe Twitter::REST::API::Users do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@client = Twitter::Client.new
|
6
|
+
@client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#settings" do
|
@@ -18,7 +18,7 @@ describe Twitter::API::Users do
|
|
18
18
|
it "returns settings" do
|
19
19
|
settings = @client.settings
|
20
20
|
expect(settings).to be_a Twitter::Settings
|
21
|
-
expect(settings.language).to eq
|
21
|
+
expect(settings.language).to eq("en")
|
22
22
|
end
|
23
23
|
it "requests the correct resource on POST" do
|
24
24
|
@client.settings(:trend_location_woeid => "23424803")
|
@@ -27,7 +27,7 @@ describe Twitter::API::Users do
|
|
27
27
|
it "returns settings" do
|
28
28
|
settings = @client.settings(:trend_location_woeid => "23424803")
|
29
29
|
expect(settings).to be_a Twitter::Settings
|
30
|
-
expect(settings.language).to eq
|
30
|
+
expect(settings.language).to eq("en")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -42,7 +42,7 @@ describe Twitter::API::Users do
|
|
42
42
|
it "returns the requesting user" do
|
43
43
|
user = @client.verify_credentials
|
44
44
|
expect(user).to be_a Twitter::User
|
45
|
-
expect(user.id).to eq
|
45
|
+
expect(user.id).to eq(7505382)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -57,7 +57,7 @@ describe Twitter::API::Users do
|
|
57
57
|
it "returns a user" do
|
58
58
|
user = @client.update_delivery_device("sms")
|
59
59
|
expect(user).to be_a Twitter::User
|
60
|
-
expect(user.id).to eq
|
60
|
+
expect(user.id).to eq(7505382)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -72,7 +72,7 @@ describe Twitter::API::Users do
|
|
72
72
|
it "returns a user" do
|
73
73
|
user = @client.update_profile(:url => "http://github.com/sferik/")
|
74
74
|
expect(user).to be_a Twitter::User
|
75
|
-
expect(user.id).to eq
|
75
|
+
expect(user.id).to eq(7505382)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -87,7 +87,7 @@ describe Twitter::API::Users do
|
|
87
87
|
it "returns a user" do
|
88
88
|
user = @client.update_profile_background_image(fixture("we_concept_bg2.png"))
|
89
89
|
expect(user).to be_a Twitter::User
|
90
|
-
expect(user.id).to eq
|
90
|
+
expect(user.id).to eq(7505382)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -102,7 +102,7 @@ describe Twitter::API::Users do
|
|
102
102
|
it "returns a user" do
|
103
103
|
user = @client.update_profile_colors(:profile_background_color => "000000")
|
104
104
|
expect(user).to be_a Twitter::User
|
105
|
-
expect(user.id).to eq
|
105
|
+
expect(user.id).to eq(7505382)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -117,7 +117,7 @@ describe Twitter::API::Users do
|
|
117
117
|
it "returns a user" do
|
118
118
|
user = @client.update_profile_image(fixture("me.jpeg"))
|
119
119
|
expect(user).to be_a Twitter::User
|
120
|
-
expect(user.id).to eq
|
120
|
+
expect(user.id).to eq(7505382)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
@@ -133,7 +133,7 @@ describe Twitter::API::Users do
|
|
133
133
|
it "returns the users in a given category of the Twitter suggested user list" do
|
134
134
|
suggestion = @client.suggestions("art-design")
|
135
135
|
expect(suggestion).to be_a Twitter::Suggestion
|
136
|
-
expect(suggestion.name).to eq
|
136
|
+
expect(suggestion.name).to eq("Art & Design")
|
137
137
|
expect(suggestion.users).to be_an Array
|
138
138
|
expect(suggestion.users.first).to be_a Twitter::User
|
139
139
|
end
|
@@ -150,7 +150,7 @@ describe Twitter::API::Users do
|
|
150
150
|
suggestions = @client.suggestions
|
151
151
|
expect(suggestions).to be_an Array
|
152
152
|
expect(suggestions.first).to be_a Twitter::Suggestion
|
153
|
-
expect(suggestions.first.name).to eq
|
153
|
+
expect(suggestions.first.name).to eq("Art & Design")
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
@@ -167,7 +167,7 @@ describe Twitter::API::Users do
|
|
167
167
|
suggest_users = @client.suggest_users("art-design")
|
168
168
|
expect(suggest_users).to be_an Array
|
169
169
|
expect(suggest_users.first).to be_a Twitter::User
|
170
|
-
expect(suggest_users.first.id).to eq
|
170
|
+
expect(suggest_users.first.id).to eq(13)
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
@@ -182,16 +182,15 @@ describe Twitter::API::Users do
|
|
182
182
|
it "returns an array of user objects that the authenticating user is blocking" do
|
183
183
|
blocking = @client.blocking
|
184
184
|
expect(blocking).to be_a Twitter::Cursor
|
185
|
-
expect(blocking.
|
186
|
-
expect(blocking.
|
187
|
-
expect(blocking.users.first.id).to eq 7505382
|
185
|
+
expect(blocking.first).to be_a Twitter::User
|
186
|
+
expect(blocking.first.id).to eq(7505382)
|
188
187
|
end
|
189
|
-
context "with
|
188
|
+
context "with each" do
|
190
189
|
before do
|
191
190
|
stub_get("/1.1/blocks/list.json").with(:query => {:cursor => "1322801608223717003"}).to_return(:body => fixture("users_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
192
191
|
end
|
193
192
|
it "requests the correct resource" do
|
194
|
-
@client.blocking.
|
193
|
+
@client.blocking.each{}
|
195
194
|
expect(a_get("/1.1/blocks/list.json").with(:query => {:cursor => "-1"})).to have_been_made
|
196
195
|
expect(a_get("/1.1/blocks/list.json").with(:query => {:cursor => "1322801608223717003"})).to have_been_made
|
197
196
|
end
|
@@ -209,15 +208,14 @@ describe Twitter::API::Users do
|
|
209
208
|
it "returns an array of numeric user IDs the authenticating user is blocking" do
|
210
209
|
blocked_ids = @client.blocked_ids
|
211
210
|
expect(blocked_ids).to be_a Twitter::Cursor
|
212
|
-
expect(blocked_ids.
|
213
|
-
expect(blocked_ids.ids.first).to eq 14100886
|
211
|
+
expect(blocked_ids.first).to eq(20009713)
|
214
212
|
end
|
215
|
-
context "with
|
213
|
+
context "with each" do
|
216
214
|
before do
|
217
215
|
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"})
|
218
216
|
end
|
219
217
|
it "requests the correct resource" do
|
220
|
-
@client.blocked_ids.
|
218
|
+
@client.blocked_ids.each{}
|
221
219
|
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
|
222
220
|
expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"})).to have_been_made
|
223
221
|
end
|
@@ -284,7 +282,7 @@ describe Twitter::API::Users do
|
|
284
282
|
users = @client.block("sferik")
|
285
283
|
expect(users).to be_an Array
|
286
284
|
expect(users.first).to be_a Twitter::User
|
287
|
-
expect(users.first.id).to eq
|
285
|
+
expect(users.first.id).to eq(7505382)
|
288
286
|
end
|
289
287
|
end
|
290
288
|
|
@@ -300,7 +298,7 @@ describe Twitter::API::Users do
|
|
300
298
|
users = @client.unblock("sferik")
|
301
299
|
expect(users).to be_an Array
|
302
300
|
expect(users.first).to be_a Twitter::User
|
303
|
-
expect(users.first.id).to eq
|
301
|
+
expect(users.first.id).to eq(7505382)
|
304
302
|
end
|
305
303
|
end
|
306
304
|
|
@@ -318,7 +316,21 @@ describe Twitter::API::Users do
|
|
318
316
|
users = @client.users("sferik", "pengwynn")
|
319
317
|
expect(users).to be_an Array
|
320
318
|
expect(users.first).to be_a Twitter::User
|
321
|
-
expect(users.first.id).to eq
|
319
|
+
expect(users.first.id).to eq(7505382)
|
320
|
+
end
|
321
|
+
context "with URI objects passed" do
|
322
|
+
it "requests the correct resource" do
|
323
|
+
sferik = URI.parse("https://twitter.com/sferik")
|
324
|
+
pengwynn = URI.parse("https://twitter.com/pengwynn")
|
325
|
+
@client.users(sferik, pengwynn)
|
326
|
+
expect(a_post("/1.1/users/lookup.json").with(:body => {:screen_name => "sferik,pengwynn"})).to have_been_made
|
327
|
+
end
|
328
|
+
end
|
329
|
+
context "with URI strings passed" do
|
330
|
+
it "requests the correct resource" do
|
331
|
+
@client.users("https://twitter.com/sferik", "https://twitter.com/pengwynn")
|
332
|
+
expect(a_post("/1.1/users/lookup.json").with(:body => {:screen_name => "sferik,pengwynn"})).to have_been_made
|
333
|
+
end
|
322
334
|
end
|
323
335
|
end
|
324
336
|
context "with numeric screen names passed" do
|
@@ -360,7 +372,6 @@ describe Twitter::API::Users do
|
|
360
372
|
end
|
361
373
|
end
|
362
374
|
end
|
363
|
-
|
364
375
|
context "using a get request" do
|
365
376
|
context "with screen names passed" do
|
366
377
|
before do
|
@@ -374,7 +385,21 @@ describe Twitter::API::Users do
|
|
374
385
|
users = @client.users("sferik", "pengwynn", :method => :get)
|
375
386
|
expect(users).to be_an Array
|
376
387
|
expect(users.first).to be_a Twitter::User
|
377
|
-
expect(users.first.id).to eq
|
388
|
+
expect(users.first.id).to eq(7505382)
|
389
|
+
end
|
390
|
+
context "with URI objects passed" do
|
391
|
+
it "requests the correct resource" do
|
392
|
+
sferik = URI.parse("https://twitter.com/sferik")
|
393
|
+
pengwynn = URI.parse("https://twitter.com/pengwynn")
|
394
|
+
@client.users(sferik, pengwynn, :method => :get)
|
395
|
+
expect(a_get("/1.1/users/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"})).to have_been_made
|
396
|
+
end
|
397
|
+
end
|
398
|
+
context "with URI objects passed" do
|
399
|
+
it "requests the correct resource" do
|
400
|
+
@client.users("https://twitter.com/sferik", "https://twitter.com/pengwynn", :method => :get)
|
401
|
+
expect(a_get("/1.1/users/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"})).to have_been_made
|
402
|
+
end
|
378
403
|
end
|
379
404
|
end
|
380
405
|
context "with numeric screen names passed" do
|
@@ -430,7 +455,7 @@ describe Twitter::API::Users do
|
|
430
455
|
it "returns extended information of a given user" do
|
431
456
|
user = @client.user("sferik")
|
432
457
|
expect(user).to be_a Twitter::User
|
433
|
-
expect(user.id).to eq
|
458
|
+
expect(user.id).to eq(7505382)
|
434
459
|
end
|
435
460
|
end
|
436
461
|
context "with a screen name including '@' passed" do
|
@@ -523,7 +548,7 @@ describe Twitter::API::Users do
|
|
523
548
|
user_search = @client.user_search("Erik Michaels-Ober")
|
524
549
|
expect(user_search).to be_an Array
|
525
550
|
expect(user_search.first).to be_a Twitter::User
|
526
|
-
expect(user_search.first.id).to eq
|
551
|
+
expect(user_search.first.id).to eq(7505382)
|
527
552
|
end
|
528
553
|
end
|
529
554
|
|
@@ -540,7 +565,7 @@ describe Twitter::API::Users do
|
|
540
565
|
contributees = @client.contributees("sferik")
|
541
566
|
expect(contributees).to be_an Array
|
542
567
|
expect(contributees.first).to be_a Twitter::User
|
543
|
-
expect(contributees.first.name).to eq
|
568
|
+
expect(contributees.first.name).to eq("Twitter API")
|
544
569
|
end
|
545
570
|
end
|
546
571
|
context "with a user ID passed" do
|
@@ -565,7 +590,7 @@ describe Twitter::API::Users do
|
|
565
590
|
contributees = @client.contributees
|
566
591
|
expect(contributees).to be_an Array
|
567
592
|
expect(contributees.first).to be_a Twitter::User
|
568
|
-
expect(contributees.first.name).to eq
|
593
|
+
expect(contributees.first.name).to eq("Twitter API")
|
569
594
|
end
|
570
595
|
end
|
571
596
|
end
|
@@ -583,7 +608,7 @@ describe Twitter::API::Users do
|
|
583
608
|
contributors = @client.contributors("sferik")
|
584
609
|
expect(contributors).to be_an Array
|
585
610
|
expect(contributors.first).to be_a Twitter::User
|
586
|
-
expect(contributors.first.id).to eq
|
611
|
+
expect(contributors.first.id).to eq(13)
|
587
612
|
end
|
588
613
|
end
|
589
614
|
context "with a user ID passed" do
|
@@ -608,7 +633,7 @@ describe Twitter::API::Users do
|
|
608
633
|
contributors = @client.contributors
|
609
634
|
expect(contributors).to be_an Array
|
610
635
|
expect(contributors.first).to be_a Twitter::User
|
611
|
-
expect(contributors.first.id).to eq
|
636
|
+
expect(contributors.first.id).to eq(13)
|
612
637
|
end
|
613
638
|
end
|
614
639
|
end
|
@@ -654,7 +679,7 @@ describe Twitter::API::Users do
|
|
654
679
|
banner = @client.profile_banner("sferik")
|
655
680
|
expect(banner).to be_a Twitter::ProfileBanner
|
656
681
|
expect(banner.sizes).to be_a Hash
|
657
|
-
expect(banner.sizes[:mobile].height).to eq
|
682
|
+
expect(banner.sizes[:mobile].height).to eq(160)
|
658
683
|
end
|
659
684
|
end
|
660
685
|
context "with a user ID passed" do
|
@@ -680,7 +705,7 @@ describe Twitter::API::Users do
|
|
680
705
|
banner = @client.profile_banner
|
681
706
|
expect(banner).to be_a Twitter::ProfileBanner
|
682
707
|
expect(banner.sizes).to be_a Hash
|
683
|
-
expect(banner.sizes[:mobile].height).to eq
|
708
|
+
expect(banner.sizes[:mobile].height).to eq(160)
|
684
709
|
end
|
685
710
|
end
|
686
711
|
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::REST::Client do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".new" do
|
10
|
+
context "when invalid credentials are provided" do
|
11
|
+
it "raises a ConfigurationError exception" do
|
12
|
+
expect {
|
13
|
+
Twitter::REST::Client.new(:consumer_key => [12345, 54321])
|
14
|
+
}.to raise_exception(Twitter::Error::ConfigurationError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when no credentials are provided" do
|
19
|
+
it "does not raise an exception" do
|
20
|
+
expect {
|
21
|
+
Twitter::REST::Client.new
|
22
|
+
}.not_to raise_error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".credentials?" do
|
28
|
+
it "returns true if only bearer_token is supplied" do
|
29
|
+
client = Twitter::REST::Client.new(:bearer_token => "BT")
|
30
|
+
expect(client.credentials?).to be_true
|
31
|
+
end
|
32
|
+
it "returns true if all OAuth credentials are present" do
|
33
|
+
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
34
|
+
expect(client.credentials?).to be_true
|
35
|
+
end
|
36
|
+
it "returns false if any credentials are missing" do
|
37
|
+
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT")
|
38
|
+
expect(client.credentials?).to be_false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not cache the screen name across clients" do
|
43
|
+
stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
44
|
+
user1 = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS").current_user
|
45
|
+
stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("pengwynn.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
46
|
+
user2 = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS").current_user
|
47
|
+
expect(user1).not_to eq(user2)
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#delete" do
|
51
|
+
before do
|
52
|
+
stub_delete("/custom/delete").with(:query => {:deleted => "object"})
|
53
|
+
end
|
54
|
+
it "allows custom delete requests" do
|
55
|
+
@client.delete("/custom/delete", {:deleted => "object"})
|
56
|
+
expect(a_delete("/custom/delete").with(:query => {:deleted => "object"})).to have_been_made
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#put" do
|
61
|
+
before do
|
62
|
+
stub_put("/custom/put").with(:body => {:updated => "object"})
|
63
|
+
end
|
64
|
+
it "allows custom put requests" do
|
65
|
+
@client.put("/custom/put", {:updated => "object"})
|
66
|
+
expect(a_put("/custom/put").with(:body => {:updated => "object"})).to have_been_made
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#user_token?" do
|
71
|
+
it "returns true if the user token/secret are present" do
|
72
|
+
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
73
|
+
expect(client.user_token?).to be_true
|
74
|
+
end
|
75
|
+
it "returns false if the user token/secret are not completely present" do
|
76
|
+
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT")
|
77
|
+
expect(client.user_token?).to be_false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#bearer_token?" do
|
82
|
+
it "returns true if the app token is present" do
|
83
|
+
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :bearer_token => "BT")
|
84
|
+
expect(client.bearer_token?).to be_true
|
85
|
+
end
|
86
|
+
it "returns false if the bearer_token is not present" do
|
87
|
+
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS")
|
88
|
+
expect(client.bearer_token?).to be_false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#credentials?" do
|
93
|
+
it "returns true if all credentials are present" do
|
94
|
+
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
95
|
+
expect(client.credentials?).to be_true
|
96
|
+
end
|
97
|
+
it "returns false if any credentials are missing" do
|
98
|
+
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT")
|
99
|
+
expect(client.credentials?).to be_false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#connection" do
|
104
|
+
it "looks like Faraday connection" do
|
105
|
+
expect(@client.send(:connection)).to respond_to(:run_request)
|
106
|
+
end
|
107
|
+
it "memoizes the connection" do
|
108
|
+
c1, c2 = @client.send(:connection), @client.send(:connection)
|
109
|
+
expect(c1.object_id).to eq(c2.object_id)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#request" do
|
114
|
+
it "encodes the entire body when no uploaded media is present" do
|
115
|
+
stub_post("/1.1/statuses/update.json").with(:body => {:status => "Update"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
116
|
+
@client.update("Update")
|
117
|
+
expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "Update"})).to have_been_made
|
118
|
+
end
|
119
|
+
it "encodes none of the body when uploaded media is present" do
|
120
|
+
stub_post("/1.1/statuses/update_with_media.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
121
|
+
@client.update_with_media("Update", fixture("pbjt.gif"))
|
122
|
+
expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
|
123
|
+
end
|
124
|
+
it "catches Faraday errors" do
|
125
|
+
allow(@client).to receive(:connection).and_raise(Faraday::Error::ClientError.new("Oops"))
|
126
|
+
expect{@client.send(:request, :get, "/path")}.to raise_error Twitter::Error
|
127
|
+
end
|
128
|
+
it "catches JSON::ParserError errors" do
|
129
|
+
allow(@client).to receive(:connection).and_raise(JSON::ParserError.new("unexpected token"))
|
130
|
+
expect{@client.send(:request, :get, "/path")}.to raise_error Twitter::Error
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#oauth_auth_header" do
|
135
|
+
it "creates the correct auth headers" do
|
136
|
+
uri = Twitter::REST::Client::ENDPOINT + "/1.1/direct_messages.json"
|
137
|
+
authorization = @client.send(:oauth_auth_header, :get, uri)
|
138
|
+
expect(authorization.options[:signature_method]).to eq("HMAC-SHA1")
|
139
|
+
expect(authorization.options[:version]).to eq("1.0")
|
140
|
+
expect(authorization.options[:consumer_key]).to eq("CK")
|
141
|
+
expect(authorization.options[:consumer_secret]).to eq("CS")
|
142
|
+
expect(authorization.options[:token]).to eq("AT")
|
143
|
+
expect(authorization.options[:token_secret]).to eq("AS")
|
144
|
+
end
|
145
|
+
it "submits the correct auth header when no media is present" do
|
146
|
+
# We use static values for nounce and timestamp to get a stable signature
|
147
|
+
secret = {:consumer_key => "CK", :consumer_secret => "CS",
|
148
|
+
:token => "OT", :token_secret => "OS",
|
149
|
+
:nonce => "b6ebe4c2a11af493f8a2290fe1296965", :timestamp => "1370968658"}
|
150
|
+
header = {"Authorization" => /oauth_signature="FbthwmgGq02iQw%2FuXGEWaL6V6eM%3D"/}
|
151
|
+
|
152
|
+
allow(@client).to receive(:credentials).and_return(secret)
|
153
|
+
stub_post("/1.1/statuses/update.json").with(:body => {:status => "Just a test"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
154
|
+
@client.update("Just a test")
|
155
|
+
expect(a_post("/1.1/statuses/update.json").
|
156
|
+
with(:headers => header)).to have_been_made
|
157
|
+
end
|
158
|
+
it "submits the correct auth header when media is present" do
|
159
|
+
# We use static values for nounce and timestamp to get a stable signature
|
160
|
+
secret = {:consumer_key => "CK", :consumer_secret => "CS",
|
161
|
+
:token => "OT", :token_secret => "OS",
|
162
|
+
:nonce => "e08201ad0dab4897c99445056feefd95", :timestamp => "1370967652"}
|
163
|
+
header = {"Authorization" => /oauth_signature="9ziouUPwZT9IWWRbJL8r0BerKYA%3D"/}
|
164
|
+
|
165
|
+
allow(@client).to receive(:credentials).and_return(secret)
|
166
|
+
stub_post("/1.1/statuses/update_with_media.json").to_return(:body => fixture("status.json"), :headers => header)
|
167
|
+
@client.update_with_media("Just a test", fixture("pbjt.gif"))
|
168
|
+
expect(a_post("/1.1/statuses/update_with_media.json").
|
169
|
+
with(:headers => header)).to have_been_made
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "#bearer_auth_header" do
|
174
|
+
it "creates the correct auth headers with supplied bearer_token" do
|
175
|
+
client = Twitter::REST::Client.new(:bearer_token => "BT")
|
176
|
+
authorization = client.send(:bearer_auth_header)
|
177
|
+
expect(authorization).to eq("Bearer BT")
|
178
|
+
end
|
179
|
+
it "creates the correct auth headers with supplied bearer token" do
|
180
|
+
token = Twitter::Token.new(:token_type => "bearer", :access_token => "BT")
|
181
|
+
client = Twitter::REST::Client.new(:bearer_token => token)
|
182
|
+
authorization = client.send(:bearer_auth_header)
|
183
|
+
expect(authorization).to eq("Bearer BT")
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "#bearer_token_credentials_auth_header" do
|
188
|
+
it "creates the correct auth header with supplied consumer_key and consumer_secret" do
|
189
|
+
authorization = @client.send(:bearer_token_credentials_auth_header)
|
190
|
+
expect(authorization).to eq("Basic Q0s6Q1M=")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|