twitter 5.0.0 → 5.4.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/.yardopts +4 -0
- data/CHANGELOG.md +47 -0
- data/CONTRIBUTING.md +5 -5
- data/README.md +57 -56
- data/Rakefile +26 -5
- data/lib/twitter/arguments.rb +1 -2
- data/lib/twitter/base.rb +15 -18
- data/lib/twitter/basic_user.rb +3 -3
- data/lib/twitter/client.rb +9 -10
- data/lib/twitter/configuration.rb +5 -5
- data/lib/twitter/creatable.rb +0 -1
- data/lib/twitter/cursor.rb +9 -36
- data/lib/twitter/direct_message.rb +1 -1
- data/lib/twitter/entity/uri.rb +2 -2
- data/lib/twitter/enumerable.rb +10 -1
- data/lib/twitter/error/already_favorited.rb +1 -1
- data/lib/twitter/error/already_posted.rb +1 -1
- data/lib/twitter/error/already_retweeted.rb +1 -1
- data/lib/twitter/error/too_many_requests.rb +2 -2
- data/lib/twitter/error.rb +6 -6
- data/lib/twitter/factory.rb +2 -6
- data/lib/twitter/geo/point.rb +3 -5
- data/lib/twitter/geo.rb +1 -1
- data/lib/twitter/geo_factory.rb +1 -5
- data/lib/twitter/geo_results.rb +5 -8
- data/lib/twitter/identity.rb +1 -2
- data/lib/twitter/list.rb +10 -11
- data/lib/twitter/media/photo.rb +1 -2
- data/lib/twitter/media_factory.rb +1 -5
- data/lib/twitter/null_object.rb +4 -6
- data/lib/twitter/oembed.rb +1 -1
- data/lib/twitter/place.rb +17 -6
- data/lib/twitter/profile_banner.rb +1 -3
- data/lib/twitter/rate_limit.rb +1 -3
- data/lib/twitter/relationship.rb +1 -2
- data/lib/twitter/rest/api/direct_messages.rb +15 -15
- data/lib/twitter/rest/api/favorites.rb +15 -15
- data/lib/twitter/rest/api/friends_and_followers.rb +37 -42
- data/lib/twitter/rest/api/help.rb +8 -9
- data/lib/twitter/rest/api/lists.rb +69 -69
- data/lib/twitter/rest/api/oauth.rb +3 -4
- data/lib/twitter/rest/api/places_and_geo.rb +9 -10
- data/lib/twitter/rest/api/saved_searches.rb +8 -8
- data/lib/twitter/rest/api/search.rb +10 -2
- data/lib/twitter/rest/api/spam_reporting.rb +1 -2
- data/lib/twitter/rest/api/suggested_users.rb +4 -5
- data/lib/twitter/rest/api/timelines.rb +17 -18
- data/lib/twitter/rest/api/trends.rb +10 -11
- data/lib/twitter/rest/api/tweets.rb +31 -20
- data/lib/twitter/rest/api/undocumented.rb +6 -7
- data/lib/twitter/rest/api/users.rb +53 -54
- data/lib/twitter/rest/api/utils.rb +28 -34
- data/lib/twitter/rest/client.rb +8 -9
- data/lib/twitter/rest/request/multipart_with_file.rb +7 -5
- data/lib/twitter/rest/response/parse_error_json.rb +0 -2
- data/lib/twitter/rest/response/parse_json.rb +2 -2
- data/lib/twitter/rest/response/raise_error.rb +1 -3
- data/lib/twitter/search_results.rb +38 -56
- data/lib/twitter/settings.rb +2 -2
- data/lib/twitter/size.rb +2 -2
- data/lib/twitter/source_user.rb +1 -1
- data/lib/twitter/streaming/client.rb +69 -18
- data/lib/twitter/streaming/connection.rb +1 -3
- data/lib/twitter/streaming/deleted_tweet.rb +8 -0
- data/lib/twitter/streaming/event.rb +8 -8
- data/lib/twitter/streaming/friend_list.rb +2 -9
- data/lib/twitter/streaming/message_parser.rb +13 -3
- data/lib/twitter/streaming/response.rb +0 -2
- data/lib/twitter/streaming/stall_warning.rb +7 -0
- data/lib/twitter/suggestion.rb +0 -1
- data/lib/twitter/token.rb +2 -3
- data/lib/twitter/trend_results.rb +5 -8
- data/lib/twitter/tweet.rb +17 -18
- data/lib/twitter/user.rb +33 -35
- data/lib/twitter/utils.rb +14 -0
- data/lib/twitter/version.rb +2 -5
- data/lib/twitter.rb +1 -1
- data/spec/fixtures/forbidden.json +1 -0
- data/spec/fixtures/search.json +1 -1
- data/spec/fixtures/search2.json +1 -0
- data/spec/fixtures/track_streaming_user.json +2 -1
- data/spec/helper.rb +6 -2
- data/spec/twitter/base_spec.rb +9 -9
- data/spec/twitter/basic_user_spec.rb +6 -6
- data/spec/twitter/configuration_spec.rb +4 -4
- data/spec/twitter/cursor_spec.rb +13 -51
- data/spec/twitter/direct_message_spec.rb +36 -36
- data/spec/twitter/entity/uri_spec.rb +29 -29
- data/spec/twitter/error_spec.rb +21 -21
- data/spec/twitter/geo/point_spec.rb +9 -9
- data/spec/twitter/geo/polygon_spec.rb +5 -5
- data/spec/twitter/geo_factory_spec.rb +7 -7
- data/spec/twitter/geo_results_spec.rb +11 -11
- data/spec/twitter/geo_spec.rb +5 -5
- data/spec/twitter/identifiable_spec.rb +9 -9
- data/spec/twitter/list_spec.rb +38 -38
- data/spec/twitter/media/photo_spec.rb +58 -58
- data/spec/twitter/media_factory_spec.rb +5 -5
- data/spec/twitter/null_object_spec.rb +6 -6
- data/spec/twitter/oembed_spec.rb +68 -68
- data/spec/twitter/place_spec.rb +91 -62
- data/spec/twitter/profile_banner_spec.rb +3 -3
- data/spec/twitter/rate_limit_spec.rb +18 -18
- data/spec/twitter/relationship_spec.rb +16 -16
- data/spec/twitter/rest/api/direct_messages_spec.rb +61 -61
- data/spec/twitter/rest/api/favorites_spec.rb +93 -93
- data/spec/twitter/rest/api/friends_and_followers_spec.rb +357 -349
- data/spec/twitter/rest/api/geo_spec.rb +33 -33
- data/spec/twitter/rest/api/help_spec.rb +24 -24
- data/spec/twitter/rest/api/lists_spec.rb +487 -487
- data/spec/twitter/rest/api/oauth_spec.rb +30 -30
- data/spec/twitter/rest/api/saved_searches_spec.rb +50 -40
- data/spec/twitter/rest/api/search_spec.rb +27 -26
- data/spec/twitter/rest/api/spam_reporting_spec.rb +9 -9
- data/spec/twitter/rest/api/suggested_users_spec.rb +23 -23
- data/spec/twitter/rest/api/timelines_spec.rb +58 -58
- data/spec/twitter/rest/api/trends_spec.rb +26 -26
- data/spec/twitter/rest/api/tweets_spec.rb +304 -266
- data/spec/twitter/rest/api/undocumented_spec.rb +51 -51
- data/spec/twitter/rest/api/users_spec.rb +360 -360
- data/spec/twitter/rest/client_spec.rb +99 -103
- data/spec/twitter/saved_search_spec.rb +16 -16
- data/spec/twitter/search_results_spec.rb +14 -110
- data/spec/twitter/settings_spec.rb +8 -8
- data/spec/twitter/size_spec.rb +5 -5
- data/spec/twitter/source_user_spec.rb +6 -6
- data/spec/twitter/streaming/client_spec.rb +85 -54
- data/spec/twitter/streaming/deleted_tweet_spec.rb +23 -0
- data/spec/twitter/streaming/event_spec.rb +20 -22
- data/spec/twitter/streaming/friend_list_spec.rb +11 -0
- data/spec/twitter/streaming/message_parser_spec.rb +54 -0
- data/spec/twitter/suggestion_spec.rb +11 -11
- data/spec/twitter/target_user_spec.rb +6 -6
- data/spec/twitter/token_spec.rb +4 -4
- data/spec/twitter/trend_results_spec.rb +30 -30
- data/spec/twitter/trend_spec.rb +21 -21
- data/spec/twitter/tweet_spec.rb +178 -164
- data/spec/twitter/user_spec.rb +190 -190
- data/twitter.gemspec +6 -6
- data.tar.gz.sig +0 -0
- metadata +44 -16
- metadata.gz.sig +0 -0
- data/lib/twitter/core_ext/enumerable.rb +0 -10
- data/lib/twitter/core_ext/kernel.rb +0 -10
- data/spec/twitter_spec.rb +0 -0
data/spec/twitter/place_spec.rb
CHANGED
|
@@ -2,128 +2,157 @@ require 'helper'
|
|
|
2
2
|
|
|
3
3
|
describe Twitter::Place do
|
|
4
4
|
|
|
5
|
-
describe
|
|
6
|
-
it
|
|
7
|
-
place = Twitter::Place.new(:woeid => 1, :name =>
|
|
8
|
-
other = Twitter::Place.new(:woeid => 1, :name =>
|
|
5
|
+
describe '#eql?' do
|
|
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).to eql(other)
|
|
10
|
+
end
|
|
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).not_to eql(other)
|
|
15
|
+
end
|
|
16
|
+
it 'returns false when classes are different' do
|
|
17
|
+
place = Twitter::Place.new(:woeid => 1)
|
|
18
|
+
other = Twitter::Base.new(:woeid => 1)
|
|
19
|
+
expect(place).not_to eql(other)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe '#bounding_box' do
|
|
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
|
+
expect(place.bounding_box).to be_a Twitter::Geo::Polygon
|
|
27
|
+
end
|
|
28
|
+
it 'returns nil when not bounding_box is not set' do
|
|
29
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
30
|
+
expect(place.bounding_box).to be_nil
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#==' do
|
|
35
|
+
it 'returns true when objects WOE IDs are the same' do
|
|
36
|
+
place = Twitter::Place.new(:woeid => 1, :name => 'foo')
|
|
37
|
+
other = Twitter::Place.new(:woeid => 1, :name => 'bar')
|
|
9
38
|
expect(place == other).to be true
|
|
10
39
|
end
|
|
11
|
-
it
|
|
40
|
+
it 'returns false when objects WOE IDs are different' do
|
|
12
41
|
place = Twitter::Place.new(:woeid => 1)
|
|
13
42
|
other = Twitter::Place.new(:woeid => 2)
|
|
14
43
|
expect(place == other).to be false
|
|
15
44
|
end
|
|
16
|
-
it
|
|
45
|
+
it 'returns false when classes are different' do
|
|
17
46
|
place = Twitter::Place.new(:woeid => 1)
|
|
18
47
|
other = Twitter::Base.new(:woeid => 1)
|
|
19
48
|
expect(place == other).to be false
|
|
20
49
|
end
|
|
21
50
|
end
|
|
22
51
|
|
|
23
|
-
describe
|
|
24
|
-
it
|
|
25
|
-
place = Twitter::Place.new(:woeid =>
|
|
52
|
+
describe '#bounding_box' do
|
|
53
|
+
it 'returns a Twitter::Geo when bounding_box is set' do
|
|
54
|
+
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
55
|
expect(place.bounding_box).to be_a Twitter::Geo::Polygon
|
|
27
56
|
end
|
|
28
|
-
it
|
|
29
|
-
place = Twitter::Place.new(:woeid =>
|
|
57
|
+
it 'returns nil when not bounding_box is not set' do
|
|
58
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
30
59
|
expect(place.bounding_box).to be_nil
|
|
31
60
|
end
|
|
32
61
|
end
|
|
33
62
|
|
|
34
|
-
describe
|
|
35
|
-
it
|
|
36
|
-
place = Twitter::Place.new(:woeid =>
|
|
63
|
+
describe '#bounding_box?' do
|
|
64
|
+
it 'returns true when bounding_box is set' do
|
|
65
|
+
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
66
|
expect(place.bounding_box?).to be true
|
|
38
67
|
end
|
|
39
|
-
it
|
|
40
|
-
place = Twitter::Place.new(:woeid =>
|
|
68
|
+
it 'returns false when bounding_box is not set' do
|
|
69
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
41
70
|
expect(place.bounding_box?).to be false
|
|
42
71
|
end
|
|
43
72
|
end
|
|
44
73
|
|
|
45
|
-
describe
|
|
46
|
-
it
|
|
47
|
-
place = Twitter::Place.new(:woeid =>
|
|
74
|
+
describe '#contained_within' do
|
|
75
|
+
it 'returns a Twitter::Place when contained_within is set' do
|
|
76
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :contained_within => {:woeid => '247f43d441defc04'})
|
|
48
77
|
expect(place.contained_within).to be_a Twitter::Place
|
|
49
78
|
end
|
|
50
|
-
it
|
|
51
|
-
place = Twitter::Place.new(:woeid =>
|
|
79
|
+
it 'returns nil when not contained_within is not set' do
|
|
80
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
52
81
|
expect(place.contained_within).to be_nil
|
|
53
82
|
end
|
|
54
83
|
end
|
|
55
84
|
|
|
56
|
-
describe
|
|
57
|
-
it
|
|
58
|
-
place = Twitter::Place.new(:woeid =>
|
|
85
|
+
describe '#contained_within?' do
|
|
86
|
+
it 'returns true when contained_within is set' do
|
|
87
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :contained_within => {:woeid => '247f43d441defc04'})
|
|
59
88
|
expect(place.contained?).to be true
|
|
60
89
|
end
|
|
61
|
-
it
|
|
62
|
-
place = Twitter::Place.new(:woeid =>
|
|
90
|
+
it 'returns false when contained_within is not set' do
|
|
91
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
63
92
|
expect(place.contained?).to be false
|
|
64
93
|
end
|
|
65
94
|
end
|
|
66
95
|
|
|
67
|
-
describe
|
|
68
|
-
it
|
|
69
|
-
place = Twitter::Place.new(:woeid =>
|
|
70
|
-
expect(place.country_code).to eq(
|
|
96
|
+
describe '#country_code' do
|
|
97
|
+
it 'returns a country code when set with country_code' do
|
|
98
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :country_code => 'US')
|
|
99
|
+
expect(place.country_code).to eq('US')
|
|
71
100
|
end
|
|
72
|
-
it
|
|
73
|
-
place = Twitter::Place.new(:woeid =>
|
|
74
|
-
expect(place.country_code).to eq(
|
|
101
|
+
it 'returns a country code when set with countryCode' do
|
|
102
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :countryCode => 'US') # rubocop:disable SymbolName
|
|
103
|
+
expect(place.country_code).to eq('US')
|
|
75
104
|
end
|
|
76
|
-
it
|
|
77
|
-
place = Twitter::Place.new(:woeid =>
|
|
105
|
+
it 'returns nil when not set' do
|
|
106
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
78
107
|
expect(place.country_code).to be_nil
|
|
79
108
|
end
|
|
80
109
|
end
|
|
81
110
|
|
|
82
|
-
describe
|
|
83
|
-
it
|
|
84
|
-
place = Twitter::Place.new(:woeid =>
|
|
111
|
+
describe '#parent_id' do
|
|
112
|
+
it 'returns a parent ID when set with parentid' do
|
|
113
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :parentid => 1)
|
|
85
114
|
expect(place.parent_id).to eq(1)
|
|
86
115
|
end
|
|
87
|
-
it
|
|
88
|
-
place = Twitter::Place.new(:woeid =>
|
|
116
|
+
it 'returns nil when not set' do
|
|
117
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
89
118
|
expect(place.parent_id).to be_nil
|
|
90
119
|
end
|
|
91
120
|
end
|
|
92
121
|
|
|
93
|
-
describe
|
|
94
|
-
it
|
|
95
|
-
place = Twitter::Place.new(:woeid =>
|
|
96
|
-
expect(place.place_type).to eq(
|
|
122
|
+
describe '#place_type' do
|
|
123
|
+
it 'returns a place type when set with place_type' do
|
|
124
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :place_type => 'city')
|
|
125
|
+
expect(place.place_type).to eq('city')
|
|
97
126
|
end
|
|
98
|
-
it
|
|
99
|
-
place = Twitter::Place.new(:woeid =>
|
|
100
|
-
expect(place.place_type).to eq(
|
|
127
|
+
it 'returns a place type when set with placeType[name]' do
|
|
128
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :placeType => {:name => 'Town'}) # rubocop:disable SymbolName
|
|
129
|
+
expect(place.place_type).to eq('Town')
|
|
101
130
|
end
|
|
102
|
-
it
|
|
103
|
-
place = Twitter::Place.new(:woeid =>
|
|
131
|
+
it 'returns nil when not set' do
|
|
132
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
104
133
|
expect(place.place_type).to be_nil
|
|
105
134
|
end
|
|
106
135
|
end
|
|
107
136
|
|
|
108
|
-
describe
|
|
109
|
-
it
|
|
110
|
-
place = Twitter::Place.new(:woeid =>
|
|
111
|
-
expect(place.uri).to be_a URI
|
|
112
|
-
expect(place.uri.to_s).to eq(
|
|
113
|
-
end
|
|
114
|
-
it
|
|
115
|
-
place = Twitter::Place.new(:woeid =>
|
|
137
|
+
describe '#uri' do
|
|
138
|
+
it 'returns a URI when the url is set' do
|
|
139
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :url => 'https://api.twitter.com/1.1/geo/id/247f43d441defc03.json')
|
|
140
|
+
expect(place.uri).to be_a Addressable::URI
|
|
141
|
+
expect(place.uri.to_s).to eq('https://api.twitter.com/1.1/geo/id/247f43d441defc03.json')
|
|
142
|
+
end
|
|
143
|
+
it 'returns nil when the url is not set' do
|
|
144
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
116
145
|
expect(place.uri).to be_nil
|
|
117
146
|
end
|
|
118
147
|
end
|
|
119
148
|
|
|
120
|
-
describe
|
|
121
|
-
it
|
|
122
|
-
place = Twitter::Place.new(:woeid =>
|
|
149
|
+
describe '#uri?' do
|
|
150
|
+
it 'returns true when the url is set' do
|
|
151
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03', :url => 'https://api.twitter.com/1.1/geo/id/247f43d441defc03.json')
|
|
123
152
|
expect(place.uri?).to be true
|
|
124
153
|
end
|
|
125
|
-
it
|
|
126
|
-
place = Twitter::Place.new(:woeid =>
|
|
154
|
+
it 'returns false when the url is not set' do
|
|
155
|
+
place = Twitter::Place.new(:woeid => '247f43d441defc03')
|
|
127
156
|
expect(place.uri?).to be false
|
|
128
157
|
end
|
|
129
158
|
end
|
|
@@ -2,9 +2,9 @@ require 'helper'
|
|
|
2
2
|
|
|
3
3
|
describe Twitter::ProfileBanner do
|
|
4
4
|
|
|
5
|
-
describe
|
|
6
|
-
it
|
|
7
|
-
sizes = Twitter::ProfileBanner.new(:sizes => {:small => {:h => 226, :w => 340, :resize =>
|
|
5
|
+
describe '#sizes' do
|
|
6
|
+
it 'returns a hash of Sizes when sizes is set' do
|
|
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
|
|
@@ -2,55 +2,55 @@ require 'helper'
|
|
|
2
2
|
|
|
3
3
|
describe Twitter::RateLimit do
|
|
4
4
|
|
|
5
|
-
describe
|
|
6
|
-
it
|
|
7
|
-
rate_limit = Twitter::RateLimit.new(
|
|
5
|
+
describe '#limit' do
|
|
6
|
+
it 'returns an Integer when x-rate-limit-limit header is set' do
|
|
7
|
+
rate_limit = Twitter::RateLimit.new('x-rate-limit-limit' => '150')
|
|
8
8
|
expect(rate_limit.limit).to be_an Integer
|
|
9
9
|
expect(rate_limit.limit).to eq(150)
|
|
10
10
|
end
|
|
11
|
-
it
|
|
11
|
+
it 'returns nil when x-rate-limit-limit header is not set' do
|
|
12
12
|
rate_limit = Twitter::RateLimit.new
|
|
13
13
|
expect(rate_limit.limit).to be_nil
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
describe
|
|
18
|
-
it
|
|
19
|
-
rate_limit = Twitter::RateLimit.new(
|
|
17
|
+
describe '#remaining' do
|
|
18
|
+
it 'returns an Integer when x-rate-limit-remaining header is set' do
|
|
19
|
+
rate_limit = Twitter::RateLimit.new('x-rate-limit-remaining' => '149')
|
|
20
20
|
expect(rate_limit.remaining).to be_an Integer
|
|
21
21
|
expect(rate_limit.remaining).to eq(149)
|
|
22
22
|
end
|
|
23
|
-
it
|
|
23
|
+
it 'returns nil when x-rate-limit-remaining header is not set' do
|
|
24
24
|
rate_limit = Twitter::RateLimit.new
|
|
25
25
|
expect(rate_limit.remaining).to be_nil
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
describe
|
|
30
|
-
it
|
|
31
|
-
rate_limit = Twitter::RateLimit.new(
|
|
29
|
+
describe '#reset_at' do
|
|
30
|
+
it 'returns a Time when x-rate-limit-reset header is set' do
|
|
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(Time.at(
|
|
33
|
+
expect(rate_limit.reset_at).to eq(Time.at(1_339_019_097))
|
|
34
34
|
end
|
|
35
|
-
it
|
|
35
|
+
it 'returns nil when x-rate-limit-reset header is not set' do
|
|
36
36
|
rate_limit = Twitter::RateLimit.new
|
|
37
37
|
expect(rate_limit.reset_at).to be_nil
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
describe
|
|
41
|
+
describe '#reset_in' do
|
|
42
42
|
before do
|
|
43
43
|
Timecop.freeze(Time.utc(2012, 6, 6, 17, 22, 0))
|
|
44
44
|
end
|
|
45
45
|
after do
|
|
46
46
|
Timecop.return
|
|
47
47
|
end
|
|
48
|
-
it
|
|
49
|
-
rate_limit = Twitter::RateLimit.new(
|
|
48
|
+
it 'returns an Integer when x-rate-limit-reset header is set' do
|
|
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(15_777)
|
|
52
52
|
end
|
|
53
|
-
it
|
|
53
|
+
it 'returns nil when x-rate-limit-reset header is not set' do
|
|
54
54
|
rate_limit = Twitter::RateLimit.new
|
|
55
55
|
expect(rate_limit.reset_in).to be_nil
|
|
56
56
|
end
|
|
@@ -2,45 +2,45 @@ require 'helper'
|
|
|
2
2
|
|
|
3
3
|
describe Twitter::Relationship do
|
|
4
4
|
|
|
5
|
-
describe
|
|
6
|
-
it
|
|
7
|
-
relationship = Twitter::Relationship.new(:relationship => {:source => {:id =>
|
|
5
|
+
describe '#source' do
|
|
6
|
+
it 'returns a User when source is set' do
|
|
7
|
+
relationship = Twitter::Relationship.new(:relationship => {:source => {:id => 7_505_382}})
|
|
8
8
|
expect(relationship.source).to be_a Twitter::SourceUser
|
|
9
9
|
end
|
|
10
|
-
it
|
|
10
|
+
it 'returns nil when source is not set' do
|
|
11
11
|
relationship = Twitter::Relationship.new(:relationship => {})
|
|
12
12
|
expect(relationship.source).to be_nil
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
describe
|
|
17
|
-
it
|
|
18
|
-
relationship = Twitter::Relationship.new(:relationship => {:source => {:id =>
|
|
16
|
+
describe '#source?' do
|
|
17
|
+
it 'returns true when source is set' do
|
|
18
|
+
relationship = Twitter::Relationship.new(:relationship => {:source => {:id => 7_505_382}})
|
|
19
19
|
expect(relationship.source?).to be true
|
|
20
20
|
end
|
|
21
|
-
it
|
|
21
|
+
it 'returns false when source is not set' do
|
|
22
22
|
relationship = Twitter::Relationship.new(:relationship => {})
|
|
23
23
|
expect(relationship.source?).to be false
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
describe
|
|
28
|
-
it
|
|
29
|
-
relationship = Twitter::Relationship.new(:relationship => {:target => {:id =>
|
|
27
|
+
describe '#target' do
|
|
28
|
+
it 'returns a User when target is set' do
|
|
29
|
+
relationship = Twitter::Relationship.new(:relationship => {:target => {:id => 7_505_382}})
|
|
30
30
|
expect(relationship.target).to be_a Twitter::TargetUser
|
|
31
31
|
end
|
|
32
|
-
it
|
|
32
|
+
it 'returns nil when target is not set' do
|
|
33
33
|
relationship = Twitter::Relationship.new(:relationship => {})
|
|
34
34
|
expect(relationship.target).to be_nil
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
describe
|
|
39
|
-
it
|
|
40
|
-
relationship = Twitter::Relationship.new(:relationship => {:target => {:id =>
|
|
38
|
+
describe '#target?' do
|
|
39
|
+
it 'returns true when target is set' do
|
|
40
|
+
relationship = Twitter::Relationship.new(:relationship => {:target => {:id => 7_505_382}})
|
|
41
41
|
expect(relationship.target?).to be true
|
|
42
42
|
end
|
|
43
|
-
it
|
|
43
|
+
it 'returns false when target is not set' do
|
|
44
44
|
relationship = Twitter::Relationship.new(:relationship => {})
|
|
45
45
|
expect(relationship.target?).to be false
|
|
46
46
|
end
|
|
@@ -3,129 +3,129 @@ require 'helper'
|
|
|
3
3
|
describe Twitter::REST::API::DirectMessages do
|
|
4
4
|
|
|
5
5
|
before do
|
|
6
|
-
@client = Twitter::REST::Client.new(:consumer_key =>
|
|
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
|
-
describe
|
|
9
|
+
describe '#direct_messages_received' do
|
|
10
10
|
before do
|
|
11
|
-
stub_get(
|
|
11
|
+
stub_get('/1.1/direct_messages.json').to_return(:body => fixture('direct_messages.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
|
12
12
|
end
|
|
13
|
-
it
|
|
13
|
+
it 'requests the correct resource' do
|
|
14
14
|
@client.direct_messages_received
|
|
15
|
-
expect(a_get(
|
|
15
|
+
expect(a_get('/1.1/direct_messages.json')).to have_been_made
|
|
16
16
|
end
|
|
17
|
-
it
|
|
17
|
+
it 'returns the 20 most recent direct messages sent to the authenticating user' 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(7_505_382)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
describe
|
|
25
|
+
describe '#direct_messages_sent' do
|
|
26
26
|
before do
|
|
27
|
-
stub_get(
|
|
27
|
+
stub_get('/1.1/direct_messages/sent.json').to_return(:body => fixture('direct_messages.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
|
28
28
|
end
|
|
29
|
-
it
|
|
29
|
+
it 'requests the correct resource' do
|
|
30
30
|
@client.direct_messages_sent
|
|
31
|
-
expect(a_get(
|
|
31
|
+
expect(a_get('/1.1/direct_messages/sent.json')).to have_been_made
|
|
32
32
|
end
|
|
33
|
-
it
|
|
33
|
+
it 'returns the 20 most recent direct messages sent by the authenticating user' 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(7_505_382)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
describe
|
|
41
|
+
describe '#direct_message' do
|
|
42
42
|
before do
|
|
43
|
-
stub_get(
|
|
43
|
+
stub_get('/1.1/direct_messages/show.json').with(:query => {:id => '1825786345'}).to_return(:body => fixture('direct_message.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
|
44
44
|
end
|
|
45
|
-
it
|
|
46
|
-
@client.direct_message(
|
|
47
|
-
expect(a_get(
|
|
45
|
+
it 'requests the correct resource' do
|
|
46
|
+
@client.direct_message(1_825_786_345)
|
|
47
|
+
expect(a_get('/1.1/direct_messages/show.json').with(:query => {:id => '1825786345'})).to have_been_made
|
|
48
48
|
end
|
|
49
|
-
it
|
|
50
|
-
direct_message = @client.direct_message(
|
|
49
|
+
it 'returns the specified direct message' do
|
|
50
|
+
direct_message = @client.direct_message(1_825_786_345)
|
|
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(7_505_382)
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
describe
|
|
57
|
-
context
|
|
56
|
+
describe '#direct_messages' do
|
|
57
|
+
context 'with ids passed' do
|
|
58
58
|
before do
|
|
59
|
-
stub_get(
|
|
59
|
+
stub_get('/1.1/direct_messages/show.json').with(:query => {:id => '1825786345'}).to_return(:body => fixture('direct_message.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
|
60
60
|
end
|
|
61
|
-
it
|
|
62
|
-
@client.direct_messages(
|
|
63
|
-
expect(a_get(
|
|
61
|
+
it 'requests the correct resource' do
|
|
62
|
+
@client.direct_messages(1_825_786_345)
|
|
63
|
+
expect(a_get('/1.1/direct_messages/show.json').with(:query => {:id => '1825786345'})).to have_been_made
|
|
64
64
|
end
|
|
65
|
-
it
|
|
66
|
-
direct_messages = @client.direct_messages(
|
|
65
|
+
it 'returns an array of direct messages' do
|
|
66
|
+
direct_messages = @client.direct_messages(1_825_786_345)
|
|
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(7_505_382)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
|
-
context
|
|
72
|
+
context 'without ids passed' do
|
|
73
73
|
before do
|
|
74
|
-
stub_get(
|
|
74
|
+
stub_get('/1.1/direct_messages.json').to_return(:body => fixture('direct_messages.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
|
75
75
|
end
|
|
76
|
-
it
|
|
76
|
+
it 'requests the correct resource' do
|
|
77
77
|
@client.direct_messages
|
|
78
|
-
expect(a_get(
|
|
78
|
+
expect(a_get('/1.1/direct_messages.json')).to have_been_made
|
|
79
79
|
end
|
|
80
|
-
it
|
|
80
|
+
it 'returns the 20 most recent direct messages sent to the authenticating user' 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(7_505_382)
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
describe
|
|
89
|
+
describe '#destroy_direct_message' do
|
|
90
90
|
before do
|
|
91
|
-
stub_post(
|
|
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
|
-
it
|
|
94
|
-
@client.destroy_direct_message(
|
|
95
|
-
expect(a_post(
|
|
93
|
+
it 'requests the correct resource' do
|
|
94
|
+
@client.destroy_direct_message(1_825_785_544)
|
|
95
|
+
expect(a_post('/1.1/direct_messages/destroy.json').with(:body => {:id => '1825785544'})).to have_been_made
|
|
96
96
|
end
|
|
97
|
-
it
|
|
98
|
-
direct_messages = @client.destroy_direct_message(
|
|
97
|
+
it 'returns an array of deleted messages' do
|
|
98
|
+
direct_messages = @client.destroy_direct_message(1_825_785_544)
|
|
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(7_505_382)
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
describe
|
|
105
|
+
describe '#create_direct_message' do
|
|
106
106
|
before do
|
|
107
|
-
stub_post(
|
|
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
|
-
it
|
|
110
|
-
@client.create_direct_message(
|
|
111
|
-
expect(a_post(
|
|
109
|
+
it 'requests the correct resource' do
|
|
110
|
+
@client.create_direct_message('pengwynn', 'Creating a fixture for the Twitter gem')
|
|
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
|
-
it
|
|
114
|
-
direct_message = @client.create_direct_message(
|
|
113
|
+
it 'returns the sent message' do
|
|
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
117
|
end
|
|
118
|
-
context
|
|
119
|
-
it
|
|
120
|
-
user = URI.parse(
|
|
121
|
-
@client.create_direct_message(user,
|
|
122
|
-
expect(a_post(
|
|
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
123
|
end
|
|
124
124
|
end
|
|
125
|
-
context
|
|
126
|
-
it
|
|
127
|
-
@client.create_direct_message(
|
|
128
|
-
expect(a_post(
|
|
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
129
|
end
|
|
130
130
|
end
|
|
131
131
|
end
|