twitter 4.8.1 → 5.0.0
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/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +13 -15
- data/LICENSE.md +1 -1
- data/README.md +401 -261
- data/Rakefile +6 -0
- data/lib/twitter/arguments.rb +14 -0
- data/lib/twitter/base.rb +109 -89
- data/lib/twitter/client.rb +38 -115
- data/lib/twitter/configuration.rb +5 -2
- data/lib/twitter/core_ext/kernel.rb +5 -1
- data/lib/twitter/creatable.rb +7 -4
- data/lib/twitter/cursor.rb +57 -45
- data/lib/twitter/direct_message.rb +2 -11
- data/lib/twitter/entity/uri.rb +14 -0
- data/lib/twitter/enumerable.rb +15 -0
- 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/error.rb +65 -14
- data/lib/twitter/factory.rb +13 -12
- data/lib/twitter/geo.rb +2 -7
- data/lib/twitter/geo_factory.rb +11 -7
- data/lib/twitter/geo_results.rb +40 -0
- data/lib/twitter/identity.rb +4 -34
- data/lib/twitter/list.rb +21 -4
- data/lib/twitter/media/photo.rb +6 -4
- data/lib/twitter/media_factory.rb +11 -7
- data/lib/twitter/null_object.rb +25 -0
- data/lib/twitter/oembed.rb +3 -2
- data/lib/twitter/place.rb +15 -15
- data/lib/twitter/profile_banner.rb +3 -2
- data/lib/twitter/rate_limit.rb +4 -17
- data/lib/twitter/relationship.rb +2 -19
- data/lib/twitter/rest/api/direct_messages.rb +138 -0
- data/lib/twitter/rest/api/favorites.rb +115 -0
- data/lib/twitter/rest/api/friends_and_followers.rb +287 -0
- data/lib/twitter/rest/api/help.rb +58 -0
- data/lib/twitter/rest/api/lists.rb +498 -0
- data/lib/twitter/rest/api/oauth.rb +62 -0
- data/lib/twitter/rest/api/places_and_geo.rb +86 -0
- data/lib/twitter/rest/api/saved_searches.rb +93 -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 +291 -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 +246 -0
- data/lib/twitter/rest/client.rb +175 -0
- data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
- data/lib/twitter/rest/response/parse_error_json.rb +15 -0
- data/lib/twitter/rest/response/parse_json.rb +31 -0
- data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
- data/lib/twitter/search_results.rb +37 -21
- data/lib/twitter/settings.rb +1 -6
- data/lib/twitter/size.rb +2 -15
- data/lib/twitter/streaming/client.rb +89 -0
- data/lib/twitter/streaming/connection.rb +22 -0
- data/lib/twitter/streaming/event.rb +35 -0
- data/lib/twitter/streaming/friend_list.rb +13 -0
- data/lib/twitter/streaming/message_parser.rb +18 -0
- data/lib/twitter/streaming/response.rb +34 -0
- data/lib/twitter/suggestion.rb +5 -8
- data/lib/twitter/token.rb +11 -1
- data/lib/twitter/trend.rb +4 -8
- data/lib/twitter/trend_results.rb +65 -0
- data/lib/twitter/tweet.rb +43 -92
- data/lib/twitter/user.rb +72 -47
- data/lib/twitter/version.rb +4 -4
- data/lib/twitter.rb +4 -39
- 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/request_token.txt +6 -0
- 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/fixtures/track_streaming_user.json +5 -0
- data/spec/helper.rb +8 -13
- data/spec/twitter/base_spec.rb +13 -103
- data/spec/twitter/basic_user_spec.rb +3 -3
- data/spec/twitter/configuration_spec.rb +1 -1
- data/spec/twitter/cursor_spec.rb +17 -35
- data/spec/twitter/direct_message_spec.rb +44 -11
- data/spec/twitter/entity/uri_spec.rb +75 -0
- data/spec/twitter/error_spec.rb +59 -11
- data/spec/twitter/geo/point_spec.rb +6 -6
- data/spec/twitter/geo/polygon_spec.rb +5 -5
- data/spec/twitter/geo_factory_spec.rb +4 -4
- data/spec/twitter/geo_results_spec.rb +35 -0
- data/spec/twitter/geo_spec.rb +6 -6
- data/spec/twitter/identifiable_spec.rb +5 -26
- data/spec/twitter/list_spec.rb +54 -11
- data/spec/twitter/media/photo_spec.rb +122 -6
- data/spec/twitter/media_factory_spec.rb +3 -3
- data/spec/twitter/null_object_spec.rb +27 -0
- data/spec/twitter/oembed_spec.rb +69 -45
- data/spec/twitter/place_spec.rb +84 -28
- data/spec/twitter/profile_banner_spec.rb +1 -1
- data/spec/twitter/rate_limit_spec.rb +8 -25
- data/spec/twitter/relationship_spec.rb +26 -12
- data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +28 -15
- data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
- data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +121 -152
- data/spec/twitter/{api → rest/api}/geo_spec.rb +9 -23
- data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
- data/spec/twitter/{api → rest/api}/lists_spec.rb +116 -95
- data/spec/twitter/{api → rest/api}/oauth_spec.rb +21 -10
- data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +13 -13
- 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 +64 -39
- data/spec/twitter/rest/client_spec.rb +193 -0
- data/spec/twitter/saved_search_spec.rb +14 -3
- data/spec/twitter/search_results_spec.rb +32 -45
- data/spec/twitter/settings_spec.rb +17 -6
- data/spec/twitter/size_spec.rb +5 -15
- data/spec/twitter/source_user_spec.rb +3 -3
- data/spec/twitter/streaming/client_spec.rb +92 -0
- data/spec/twitter/streaming/event_spec.rb +45 -0
- data/spec/twitter/suggestion_spec.rb +5 -15
- data/spec/twitter/target_user_spec.rb +3 -3
- data/spec/twitter/token_spec.rb +16 -0
- data/spec/twitter/trend_results_spec.rb +89 -0
- data/spec/twitter/trend_spec.rb +26 -13
- data/spec/twitter/tweet_spec.rb +137 -124
- data/spec/twitter/user_spec.rb +139 -80
- data/spec/twitter_spec.rb +0 -119
- data/twitter.gemspec +12 -6
- data.tar.gz.sig +0 -0
- metadata +197 -138
- 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
data/spec/twitter/place_spec.rb
CHANGED
|
@@ -3,73 +3,129 @@ require 'helper'
|
|
|
3
3
|
describe Twitter::Place do
|
|
4
4
|
|
|
5
5
|
describe "#==" do
|
|
6
|
-
it "returns true when objects IDs are the same" do
|
|
7
|
-
place = Twitter::Place.new(:
|
|
8
|
-
other = Twitter::Place.new(:
|
|
9
|
-
expect(place == other).to
|
|
6
|
+
it "returns true when objects WOE IDs are the same" do
|
|
7
|
+
place = Twitter::Place.new(:woeid => 1, :name => "foo")
|
|
8
|
+
other = Twitter::Place.new(:woeid => 1, :name => "bar")
|
|
9
|
+
expect(place == other).to be true
|
|
10
10
|
end
|
|
11
|
-
it "returns false when objects IDs are different" do
|
|
12
|
-
place = Twitter::Place.new(:
|
|
13
|
-
other = Twitter::Place.new(:
|
|
14
|
-
expect(place == other).to
|
|
11
|
+
it "returns false when objects WOE IDs are different" do
|
|
12
|
+
place = Twitter::Place.new(:woeid => 1)
|
|
13
|
+
other = Twitter::Place.new(:woeid => 2)
|
|
14
|
+
expect(place == other).to be false
|
|
15
15
|
end
|
|
16
16
|
it "returns false when classes are different" do
|
|
17
|
-
place = Twitter::Place.new(:
|
|
18
|
-
other = Twitter::
|
|
19
|
-
expect(place == other).to
|
|
17
|
+
place = Twitter::Place.new(:woeid => 1)
|
|
18
|
+
other = Twitter::Base.new(:woeid => 1)
|
|
19
|
+
expect(place == other).to be false
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
describe "#bounding_box" do
|
|
24
|
-
it "returns a Twitter::
|
|
25
|
-
place = Twitter::Place.new(:
|
|
24
|
+
it "returns a Twitter::Geo when bounding_box is set" do
|
|
25
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
|
|
26
26
|
expect(place.bounding_box).to be_a Twitter::Geo::Polygon
|
|
27
27
|
end
|
|
28
|
-
it "returns nil when not set" do
|
|
29
|
-
place = Twitter::Place.new(:
|
|
28
|
+
it "returns nil when not bounding_box is not set" do
|
|
29
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
30
30
|
expect(place.bounding_box).to be_nil
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
describe "#bounding_box?" do
|
|
35
|
+
it "returns true when bounding_box is set" do
|
|
36
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
|
|
37
|
+
expect(place.bounding_box?).to be true
|
|
38
|
+
end
|
|
39
|
+
it "returns false when bounding_box is not set" do
|
|
40
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
41
|
+
expect(place.bounding_box?).to be false
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "#contained_within" do
|
|
46
|
+
it "returns a Twitter::Place when contained_within is set" do
|
|
47
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :contained_within => {:woeid => "247f43d441defc04"})
|
|
48
|
+
expect(place.contained_within).to be_a Twitter::Place
|
|
49
|
+
end
|
|
50
|
+
it "returns nil when not contained_within is not set" do
|
|
51
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
52
|
+
expect(place.contained_within).to be_nil
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "#contained_within?" do
|
|
57
|
+
it "returns true when contained_within is set" do
|
|
58
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :contained_within => {:woeid => "247f43d441defc04"})
|
|
59
|
+
expect(place.contained?).to be true
|
|
60
|
+
end
|
|
61
|
+
it "returns false when contained_within is not set" do
|
|
62
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
63
|
+
expect(place.contained?).to be false
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
34
67
|
describe "#country_code" do
|
|
35
68
|
it "returns a country code when set with country_code" do
|
|
36
|
-
place = Twitter::Place.new(:
|
|
37
|
-
expect(place.country_code).to eq
|
|
69
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :country_code => "US")
|
|
70
|
+
expect(place.country_code).to eq("US")
|
|
38
71
|
end
|
|
39
72
|
it "returns a country code when set with countryCode" do
|
|
40
|
-
place = Twitter::Place.new(:
|
|
41
|
-
expect(place.country_code).to eq
|
|
73
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :countryCode => "US")
|
|
74
|
+
expect(place.country_code).to eq("US")
|
|
42
75
|
end
|
|
43
76
|
it "returns nil when not set" do
|
|
44
|
-
place = Twitter::Place.new(:
|
|
77
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
45
78
|
expect(place.country_code).to be_nil
|
|
46
79
|
end
|
|
47
80
|
end
|
|
48
81
|
|
|
49
82
|
describe "#parent_id" do
|
|
50
83
|
it "returns a parent ID when set with parentid" do
|
|
51
|
-
place = Twitter::Place.new(:
|
|
52
|
-
expect(place.parent_id).to eq
|
|
84
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :parentid => 1)
|
|
85
|
+
expect(place.parent_id).to eq(1)
|
|
53
86
|
end
|
|
54
87
|
it "returns nil when not set" do
|
|
55
|
-
place = Twitter::Place.new(:
|
|
88
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
56
89
|
expect(place.parent_id).to be_nil
|
|
57
90
|
end
|
|
58
91
|
end
|
|
59
92
|
|
|
60
93
|
describe "#place_type" do
|
|
61
94
|
it "returns a place type when set with place_type" do
|
|
62
|
-
place = Twitter::Place.new(:
|
|
63
|
-
expect(place.place_type).to eq
|
|
95
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :place_type => "city")
|
|
96
|
+
expect(place.place_type).to eq("city")
|
|
64
97
|
end
|
|
65
98
|
it "returns a place type when set with placeType[name]" do
|
|
66
|
-
place = Twitter::Place.new(:
|
|
67
|
-
expect(place.place_type).to eq
|
|
99
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :placeType => {:name => "Town"})
|
|
100
|
+
expect(place.place_type).to eq("Town")
|
|
68
101
|
end
|
|
69
102
|
it "returns nil when not set" do
|
|
70
|
-
place = Twitter::Place.new(:
|
|
103
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
71
104
|
expect(place.place_type).to be_nil
|
|
72
105
|
end
|
|
73
106
|
end
|
|
74
107
|
|
|
108
|
+
describe "#uri" do
|
|
109
|
+
it "returns a URI when the url is set" do
|
|
110
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :url => "https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
|
|
111
|
+
expect(place.uri).to be_a URI
|
|
112
|
+
expect(place.uri.to_s).to eq("https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
|
|
113
|
+
end
|
|
114
|
+
it "returns nil when the url is not set" do
|
|
115
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
116
|
+
expect(place.uri).to be_nil
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe "#uri?" do
|
|
121
|
+
it "returns true when the url is set" do
|
|
122
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03", :url => "https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
|
|
123
|
+
expect(place.uri?).to be true
|
|
124
|
+
end
|
|
125
|
+
it "returns false when the url is not set" do
|
|
126
|
+
place = Twitter::Place.new(:woeid => "247f43d441defc03")
|
|
127
|
+
expect(place.uri?).to be false
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
75
131
|
end
|
|
@@ -4,7 +4,7 @@ describe Twitter::ProfileBanner do
|
|
|
4
4
|
|
|
5
5
|
describe "#sizes" do
|
|
6
6
|
it "returns a hash of Sizes when sizes is set" do
|
|
7
|
-
sizes = Twitter::ProfileBanner.new(:sizes => {:small => {:h => 226, :w => 340, :resize =>
|
|
7
|
+
sizes = Twitter::ProfileBanner.new(:sizes => {:small => {:h => 226, :w => 340, :resize => "fit"}, :large => {:h => 466, :w => 700, :resize => "fit"}, :medium => {:h => 399, :w => 600, :resize => "fit"}, :thumb => {:h => 150, :w => 150, :resize => "crop"}}).sizes
|
|
8
8
|
expect(sizes).to be_a Hash
|
|
9
9
|
expect(sizes[:small]).to be_a Twitter::Size
|
|
10
10
|
end
|
|
@@ -4,9 +4,9 @@ describe Twitter::RateLimit do
|
|
|
4
4
|
|
|
5
5
|
describe "#limit" do
|
|
6
6
|
it "returns an Integer when x-rate-limit-limit header is set" do
|
|
7
|
-
rate_limit = Twitter::RateLimit.new(
|
|
7
|
+
rate_limit = Twitter::RateLimit.new("x-rate-limit-limit" => "150")
|
|
8
8
|
expect(rate_limit.limit).to be_an Integer
|
|
9
|
-
expect(rate_limit.limit).to eq
|
|
9
|
+
expect(rate_limit.limit).to eq(150)
|
|
10
10
|
end
|
|
11
11
|
it "returns nil when x-rate-limit-limit header is not set" do
|
|
12
12
|
rate_limit = Twitter::RateLimit.new
|
|
@@ -16,9 +16,9 @@ describe Twitter::RateLimit do
|
|
|
16
16
|
|
|
17
17
|
describe "#remaining" do
|
|
18
18
|
it "returns an Integer when x-rate-limit-remaining header is set" do
|
|
19
|
-
rate_limit = Twitter::RateLimit.new(
|
|
19
|
+
rate_limit = Twitter::RateLimit.new("x-rate-limit-remaining" => "149")
|
|
20
20
|
expect(rate_limit.remaining).to be_an Integer
|
|
21
|
-
expect(rate_limit.remaining).to eq
|
|
21
|
+
expect(rate_limit.remaining).to eq(149)
|
|
22
22
|
end
|
|
23
23
|
it "returns nil when x-rate-limit-remaining header is not set" do
|
|
24
24
|
rate_limit = Twitter::RateLimit.new
|
|
@@ -28,9 +28,9 @@ describe Twitter::RateLimit do
|
|
|
28
28
|
|
|
29
29
|
describe "#reset_at" do
|
|
30
30
|
it "returns a Time when x-rate-limit-reset header is set" do
|
|
31
|
-
rate_limit = Twitter::RateLimit.new(
|
|
31
|
+
rate_limit = Twitter::RateLimit.new("x-rate-limit-reset" => "1339019097")
|
|
32
32
|
expect(rate_limit.reset_at).to be_a Time
|
|
33
|
-
expect(rate_limit.reset_at).to eq
|
|
33
|
+
expect(rate_limit.reset_at).to eq(Time.at(1339019097))
|
|
34
34
|
end
|
|
35
35
|
it "returns nil when x-rate-limit-reset header is not set" do
|
|
36
36
|
rate_limit = Twitter::RateLimit.new
|
|
@@ -46,9 +46,9 @@ describe Twitter::RateLimit do
|
|
|
46
46
|
Timecop.return
|
|
47
47
|
end
|
|
48
48
|
it "returns an Integer when x-rate-limit-reset header is set" do
|
|
49
|
-
rate_limit = Twitter::RateLimit.new(
|
|
49
|
+
rate_limit = Twitter::RateLimit.new("x-rate-limit-reset" => "1339019097")
|
|
50
50
|
expect(rate_limit.reset_in).to be_an Integer
|
|
51
|
-
expect(rate_limit.reset_in).to eq
|
|
51
|
+
expect(rate_limit.reset_in).to eq(15777)
|
|
52
52
|
end
|
|
53
53
|
it "returns nil when x-rate-limit-reset header is not set" do
|
|
54
54
|
rate_limit = Twitter::RateLimit.new
|
|
@@ -56,21 +56,4 @@ describe Twitter::RateLimit do
|
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
describe "#update" do
|
|
60
|
-
before do
|
|
61
|
-
Timecop.freeze(Time.utc(2012, 6, 6, 17, 22, 0))
|
|
62
|
-
end
|
|
63
|
-
after do
|
|
64
|
-
Timecop.return
|
|
65
|
-
end
|
|
66
|
-
it "updates a rate limit" do
|
|
67
|
-
rate_limit = Twitter::RateLimit.new('x-rate-limit-reset' => "1339019097")
|
|
68
|
-
expect(rate_limit.reset_in).to be_an Integer
|
|
69
|
-
expect(rate_limit.reset_in).to eq 15777
|
|
70
|
-
rate_limit.update({'x-rate-limit-reset' => "1339019098"})
|
|
71
|
-
expect(rate_limit.reset_in).to be_an Integer
|
|
72
|
-
expect(rate_limit.reset_in).to eq 15778
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
59
|
end
|
|
@@ -4,31 +4,45 @@ describe Twitter::Relationship do
|
|
|
4
4
|
|
|
5
5
|
describe "#source" do
|
|
6
6
|
it "returns a User when source is set" do
|
|
7
|
-
|
|
8
|
-
expect(source).to be_a Twitter::SourceUser
|
|
7
|
+
relationship = Twitter::Relationship.new(:relationship => {:source => {:id => 7505382}})
|
|
8
|
+
expect(relationship.source).to be_a Twitter::SourceUser
|
|
9
9
|
end
|
|
10
10
|
it "returns nil when source is not set" do
|
|
11
|
-
|
|
12
|
-
expect(source).to be_nil
|
|
11
|
+
relationship = Twitter::Relationship.new(:relationship => {})
|
|
12
|
+
expect(relationship.source).to be_nil
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#source?" do
|
|
17
|
+
it "returns true when source is set" do
|
|
18
|
+
relationship = Twitter::Relationship.new(:relationship => {:source => {:id => 7505382}})
|
|
19
|
+
expect(relationship.source?).to be true
|
|
20
|
+
end
|
|
21
|
+
it "returns false when source is not set" do
|
|
22
|
+
relationship = Twitter::Relationship.new(:relationship => {})
|
|
23
|
+
expect(relationship.source?).to be false
|
|
13
24
|
end
|
|
14
25
|
end
|
|
15
26
|
|
|
16
27
|
describe "#target" do
|
|
17
28
|
it "returns a User when target is set" do
|
|
18
|
-
|
|
19
|
-
expect(target).to be_a Twitter::TargetUser
|
|
29
|
+
relationship = Twitter::Relationship.new(:relationship => {:target => {:id => 7505382}})
|
|
30
|
+
expect(relationship.target).to be_a Twitter::TargetUser
|
|
20
31
|
end
|
|
21
32
|
it "returns nil when target is not set" do
|
|
22
|
-
|
|
23
|
-
expect(target).to be_nil
|
|
33
|
+
relationship = Twitter::Relationship.new(:relationship => {})
|
|
34
|
+
expect(relationship.target).to be_nil
|
|
24
35
|
end
|
|
25
36
|
end
|
|
26
37
|
|
|
27
|
-
describe "#
|
|
28
|
-
it "
|
|
38
|
+
describe "#target?" do
|
|
39
|
+
it "returns true when target is set" do
|
|
29
40
|
relationship = Twitter::Relationship.new(:relationship => {:target => {:id => 7505382}})
|
|
30
|
-
relationship.
|
|
31
|
-
|
|
41
|
+
expect(relationship.target?).to be true
|
|
42
|
+
end
|
|
43
|
+
it "returns false when target is not set" do
|
|
44
|
+
relationship = Twitter::Relationship.new(:relationship => {})
|
|
45
|
+
expect(relationship.target?).to be false
|
|
32
46
|
end
|
|
33
47
|
end
|
|
34
48
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
require 'helper'
|
|
2
2
|
|
|
3
|
-
describe Twitter::API::DirectMessages do
|
|
3
|
+
describe Twitter::REST::API::DirectMessages 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 "#direct_messages_received" do
|
|
@@ -18,7 +18,7 @@ describe Twitter::API::DirectMessages do
|
|
|
18
18
|
direct_messages = @client.direct_messages_received
|
|
19
19
|
expect(direct_messages).to be_an Array
|
|
20
20
|
expect(direct_messages.first).to be_a Twitter::DirectMessage
|
|
21
|
-
expect(direct_messages.first.sender.id).to eq
|
|
21
|
+
expect(direct_messages.first.sender.id).to eq(7505382)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -34,7 +34,7 @@ describe Twitter::API::DirectMessages do
|
|
|
34
34
|
direct_messages = @client.direct_messages_sent
|
|
35
35
|
expect(direct_messages).to be_an Array
|
|
36
36
|
expect(direct_messages.first).to be_a Twitter::DirectMessage
|
|
37
|
-
expect(direct_messages.first.sender.id).to eq
|
|
37
|
+
expect(direct_messages.first.sender.id).to eq(7505382)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -49,7 +49,7 @@ describe Twitter::API::DirectMessages do
|
|
|
49
49
|
it "returns the specified direct message" do
|
|
50
50
|
direct_message = @client.direct_message(1825786345)
|
|
51
51
|
expect(direct_message).to be_a Twitter::DirectMessage
|
|
52
|
-
expect(direct_message.sender.id).to eq
|
|
52
|
+
expect(direct_message.sender.id).to eq(7505382)
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
@@ -66,7 +66,7 @@ describe Twitter::API::DirectMessages do
|
|
|
66
66
|
direct_messages = @client.direct_messages(1825786345)
|
|
67
67
|
expect(direct_messages).to be_an Array
|
|
68
68
|
expect(direct_messages.first).to be_a Twitter::DirectMessage
|
|
69
|
-
expect(direct_messages.first.sender.id).to eq
|
|
69
|
+
expect(direct_messages.first.sender.id).to eq(7505382)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
context "without ids passed" do
|
|
@@ -81,39 +81,52 @@ describe Twitter::API::DirectMessages do
|
|
|
81
81
|
direct_messages = @client.direct_messages
|
|
82
82
|
expect(direct_messages).to be_an Array
|
|
83
83
|
expect(direct_messages.first).to be_a Twitter::DirectMessage
|
|
84
|
-
expect(direct_messages.first.sender.id).to eq
|
|
84
|
+
expect(direct_messages.first.sender.id).to eq(7505382)
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
describe "#
|
|
89
|
+
describe "#destroy_direct_message" do
|
|
90
90
|
before do
|
|
91
91
|
stub_post("/1.1/direct_messages/destroy.json").with(:body => {:id => "1825785544"}).to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
|
92
92
|
end
|
|
93
93
|
it "requests the correct resource" do
|
|
94
|
-
@client.
|
|
94
|
+
@client.destroy_direct_message(1825785544)
|
|
95
95
|
expect(a_post("/1.1/direct_messages/destroy.json").with(:body => {:id => "1825785544"})).to have_been_made
|
|
96
96
|
end
|
|
97
97
|
it "returns an array of deleted messages" do
|
|
98
|
-
direct_messages = @client.
|
|
98
|
+
direct_messages = @client.destroy_direct_message(1825785544)
|
|
99
99
|
expect(direct_messages).to be_an Array
|
|
100
100
|
expect(direct_messages.first).to be_a Twitter::DirectMessage
|
|
101
|
-
expect(direct_messages.first.sender.id).to eq
|
|
101
|
+
expect(direct_messages.first.sender.id).to eq(7505382)
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
describe "#
|
|
105
|
+
describe "#create_direct_message" do
|
|
106
106
|
before do
|
|
107
107
|
stub_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"}).to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
|
108
108
|
end
|
|
109
109
|
it "requests the correct resource" do
|
|
110
|
-
@client.
|
|
110
|
+
@client.create_direct_message("pengwynn", "Creating a fixture for the Twitter gem")
|
|
111
111
|
expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made
|
|
112
112
|
end
|
|
113
113
|
it "returns the sent message" do
|
|
114
|
-
direct_message = @client.
|
|
114
|
+
direct_message = @client.create_direct_message("pengwynn", "Creating a fixture for the Twitter gem")
|
|
115
115
|
expect(direct_message).to be_a Twitter::DirectMessage
|
|
116
|
-
expect(direct_message.text).to eq
|
|
116
|
+
expect(direct_message.text).to eq("Creating a fixture for the Twitter gem")
|
|
117
|
+
end
|
|
118
|
+
context "with a URI object passed" do
|
|
119
|
+
it "requests the correct resource" do
|
|
120
|
+
user = URI.parse("https://twitter.com/pengwynn")
|
|
121
|
+
@client.create_direct_message(user, "Creating a fixture for the Twitter gem")
|
|
122
|
+
expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
context "with a URI string passed" do
|
|
126
|
+
it "requests the correct resource" do
|
|
127
|
+
@client.create_direct_message("https://twitter.com/pengwynn", "Creating a fixture for the Twitter gem")
|
|
128
|
+
expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made
|
|
129
|
+
end
|
|
117
130
|
end
|
|
118
131
|
end
|
|
119
132
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
require 'helper'
|
|
2
2
|
|
|
3
|
-
describe Twitter::API::Favorites do
|
|
3
|
+
describe Twitter::REST::API::Favorites 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 "#favorites" do
|
|
@@ -19,7 +19,20 @@ describe Twitter::API::Favorites do
|
|
|
19
19
|
favorites = @client.favorites("sferik")
|
|
20
20
|
expect(favorites).to be_an Array
|
|
21
21
|
expect(favorites.first).to be_a Twitter::Tweet
|
|
22
|
-
expect(favorites.first.user.id).to eq
|
|
22
|
+
expect(favorites.first.user.id).to eq(7505382)
|
|
23
|
+
end
|
|
24
|
+
context "with a URI object passed" do
|
|
25
|
+
it "requests the correct resource" do
|
|
26
|
+
user = URI.parse("https://twitter.com/sferik")
|
|
27
|
+
@client.favorites(user)
|
|
28
|
+
expect(a_get("/1.1/favorites/list.json").with(:query => {:screen_name => "sferik"})).to have_been_made
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
context "with a URI string passed" do
|
|
32
|
+
it "requests the correct resource" do
|
|
33
|
+
@client.favorites("https://twitter.com/sferik")
|
|
34
|
+
expect(a_get("/1.1/favorites/list.json").with(:query => {:screen_name => "sferik"})).to have_been_made
|
|
35
|
+
end
|
|
23
36
|
end
|
|
24
37
|
end
|
|
25
38
|
context "without arguments passed" do
|
|
@@ -34,7 +47,7 @@ describe Twitter::API::Favorites do
|
|
|
34
47
|
favorites = @client.favorites
|
|
35
48
|
expect(favorites).to be_an Array
|
|
36
49
|
expect(favorites.first).to be_a Twitter::Tweet
|
|
37
|
-
expect(favorites.first.user.id).to eq
|
|
50
|
+
expect(favorites.first.user.id).to eq(7505382)
|
|
38
51
|
end
|
|
39
52
|
end
|
|
40
53
|
end
|
|
@@ -51,7 +64,27 @@ describe Twitter::API::Favorites do
|
|
|
51
64
|
tweets = @client.unfavorite(25938088801)
|
|
52
65
|
expect(tweets).to be_an Array
|
|
53
66
|
expect(tweets.first).to be_a Twitter::Tweet
|
|
54
|
-
expect(tweets.first.text).to eq
|
|
67
|
+
expect(tweets.first.text).to eq("The problem with your code is that it's doing exactly what you told it to do.")
|
|
68
|
+
end
|
|
69
|
+
context "with a URI object passed" do
|
|
70
|
+
it "requests the correct resource" do
|
|
71
|
+
tweet = URI.parse("https://twitter.com/sferik/status/25938088801")
|
|
72
|
+
@client.unfavorite(tweet)
|
|
73
|
+
expect(a_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
context "with a URI string passed" do
|
|
77
|
+
it "requests the correct resource" do
|
|
78
|
+
@client.unfavorite("https://twitter.com/sferik/status/25938088801")
|
|
79
|
+
expect(a_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
context "with a Tweet passed" do
|
|
83
|
+
it "requests the correct resource" do
|
|
84
|
+
tweet = Twitter::Tweet.new(:id => 25938088801)
|
|
85
|
+
@client.unfavorite(tweet)
|
|
86
|
+
expect(a_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
87
|
+
end
|
|
55
88
|
end
|
|
56
89
|
end
|
|
57
90
|
|
|
@@ -67,7 +100,7 @@ describe Twitter::API::Favorites do
|
|
|
67
100
|
tweets = @client.favorite(25938088801)
|
|
68
101
|
expect(tweets).to be_an Array
|
|
69
102
|
expect(tweets.first).to be_a Twitter::Tweet
|
|
70
|
-
expect(tweets.first.text).to eq
|
|
103
|
+
expect(tweets.first.text).to eq("The problem with your code is that it's doing exactly what you told it to do.")
|
|
71
104
|
end
|
|
72
105
|
context "already favorited" do
|
|
73
106
|
before do
|
|
@@ -77,6 +110,26 @@ describe Twitter::API::Favorites do
|
|
|
77
110
|
expect{@client.favorite(25938088801)}.not_to raise_error
|
|
78
111
|
end
|
|
79
112
|
end
|
|
113
|
+
context "with a URI object passed" do
|
|
114
|
+
it "requests the correct resource" do
|
|
115
|
+
tweet = URI.parse("https://twitter.com/sferik/status/25938088801")
|
|
116
|
+
@client.favorite(tweet)
|
|
117
|
+
expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
context "with a URI string passed" do
|
|
121
|
+
it "requests the correct resource" do
|
|
122
|
+
@client.favorite("https://twitter.com/sferik/status/25938088801")
|
|
123
|
+
expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
context "with a Tweet passed" do
|
|
127
|
+
it "requests the correct resource" do
|
|
128
|
+
tweet = Twitter::Tweet.new(:id => 25938088801)
|
|
129
|
+
@client.favorite(tweet)
|
|
130
|
+
expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
131
|
+
end
|
|
132
|
+
end
|
|
80
133
|
end
|
|
81
134
|
|
|
82
135
|
describe "#favorite!" do
|
|
@@ -91,7 +144,7 @@ describe Twitter::API::Favorites do
|
|
|
91
144
|
tweets = @client.favorite!(25938088801)
|
|
92
145
|
expect(tweets).to be_an Array
|
|
93
146
|
expect(tweets.first).to be_a Twitter::Tweet
|
|
94
|
-
expect(tweets.first.text).to eq
|
|
147
|
+
expect(tweets.first.text).to eq("The problem with your code is that it's doing exactly what you told it to do.")
|
|
95
148
|
end
|
|
96
149
|
context "forbidden" do
|
|
97
150
|
before do
|
|
@@ -109,6 +162,26 @@ describe Twitter::API::Favorites do
|
|
|
109
162
|
expect{@client.favorite!(25938088801)}.to raise_error Twitter::Error::AlreadyFavorited
|
|
110
163
|
end
|
|
111
164
|
end
|
|
165
|
+
context "with a URI object passed" do
|
|
166
|
+
it "requests the correct resource" do
|
|
167
|
+
tweet = URI.parse("https://twitter.com/sferik/status/25938088801")
|
|
168
|
+
@client.favorite!(tweet)
|
|
169
|
+
expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
context "with a URI string passed" do
|
|
173
|
+
it "requests the correct resource" do
|
|
174
|
+
@client.favorite!("https://twitter.com/sferik/status/25938088801")
|
|
175
|
+
expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
context "with a Tweet passed" do
|
|
179
|
+
it "requests the correct resource" do
|
|
180
|
+
tweet = Twitter::Tweet.new(:id => 25938088801)
|
|
181
|
+
@client.favorite!(tweet)
|
|
182
|
+
expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
|
|
183
|
+
end
|
|
184
|
+
end
|
|
112
185
|
end
|
|
113
186
|
|
|
114
187
|
end
|