twitter 5.5.1 → 5.6.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +12 -0
  5. data/README.md +8 -10
  6. data/lib/twitter/base.rb +4 -2
  7. data/lib/twitter/client.rb +7 -5
  8. data/lib/twitter/configuration.rb +1 -1
  9. data/lib/twitter/cursor.rb +18 -17
  10. data/lib/twitter/entities.rb +27 -1
  11. data/lib/twitter/error.rb +1 -1
  12. data/lib/twitter/error/request_timeout.rb +10 -0
  13. data/lib/twitter/geo_results.rb +5 -3
  14. data/lib/twitter/media/photo.rb +1 -1
  15. data/lib/twitter/null_object.rb +8 -20
  16. data/lib/twitter/profile_banner.rb +1 -1
  17. data/lib/twitter/request.rb +47 -0
  18. data/lib/twitter/rest/api/direct_messages.rb +7 -5
  19. data/lib/twitter/rest/api/favorites.rb +7 -7
  20. data/lib/twitter/rest/api/friends_and_followers.rb +11 -9
  21. data/lib/twitter/rest/api/help.rb +4 -3
  22. data/lib/twitter/rest/api/lists.rb +9 -7
  23. data/lib/twitter/rest/api/oauth.rb +11 -5
  24. data/lib/twitter/rest/api/places_and_geo.rb +6 -5
  25. data/lib/twitter/rest/api/saved_searches.rb +8 -6
  26. data/lib/twitter/rest/api/search.rb +4 -10
  27. data/lib/twitter/rest/api/spam_reporting.rb +1 -0
  28. data/lib/twitter/rest/api/suggested_users.rb +4 -3
  29. data/lib/twitter/rest/api/timelines.rb +5 -4
  30. data/lib/twitter/rest/api/trends.rb +5 -4
  31. data/lib/twitter/rest/api/tweets.rb +19 -24
  32. data/lib/twitter/rest/api/users.rb +17 -16
  33. data/lib/twitter/rest/api/utils.rb +45 -73
  34. data/lib/twitter/rest/client.rb +34 -34
  35. data/lib/twitter/rest/request/multipart_with_file.rb +2 -0
  36. data/lib/twitter/rest/response/parse_json.rb +2 -0
  37. data/lib/twitter/rest/response/raise_error.rb +2 -0
  38. data/lib/twitter/search_results.rb +28 -60
  39. data/lib/twitter/streaming/client.rb +4 -4
  40. data/lib/twitter/suggestion.rb +1 -1
  41. data/lib/twitter/trend_results.rb +6 -4
  42. data/lib/twitter/tweet.rb +3 -3
  43. data/lib/twitter/user.rb +1 -1
  44. data/lib/twitter/utils.rb +18 -3
  45. data/lib/twitter/version.rb +2 -2
  46. data/spec/helper.rb +1 -1
  47. data/spec/twitter/error_spec.rb +1 -1
  48. data/spec/twitter/geo_factory_spec.rb +1 -1
  49. data/spec/twitter/identifiable_spec.rb +1 -1
  50. data/spec/twitter/media_factory_spec.rb +1 -1
  51. data/spec/twitter/rest/api/favorites_spec.rb +2 -2
  52. data/spec/twitter/rest/api/tweets_spec.rb +4 -4
  53. data/spec/twitter/rest/client_spec.rb +13 -25
  54. data/spec/twitter/tweet_spec.rb +69 -0
  55. data/twitter.gemspec +2 -1
  56. metadata +23 -15
  57. metadata.gz.sig +0 -0
  58. data/spec/twitter/null_object_spec.rb +0 -90
@@ -12,7 +12,7 @@ describe Twitter::GeoFactory do
12
12
  expect(geo).to be_a Twitter::Geo::Polygon
13
13
  end
14
14
  it 'raises an IndexError when type is not specified' do
15
- expect { Twitter::GeoFactory.new }.to raise_error IndexError
15
+ expect { Twitter::GeoFactory.new }.to raise_error(IndexError)
16
16
  end
17
17
  end
18
18
 
@@ -4,7 +4,7 @@ describe Twitter::Identity do
4
4
 
5
5
  describe '#initialize' do
6
6
  it 'raises an IndexError when id is not specified' do
7
- expect { Twitter::Identity.new }.to raise_error IndexError
7
+ expect { Twitter::Identity.new }.to raise_error(IndexError)
8
8
  end
9
9
  end
10
10
 
@@ -8,7 +8,7 @@ describe Twitter::MediaFactory do
8
8
  expect(media).to be_a Twitter::Media::Photo
9
9
  end
10
10
  it 'raises an IndexError when type is not specified' do
11
- expect { Twitter::MediaFactory.new }.to raise_error IndexError
11
+ expect { Twitter::MediaFactory.new }.to raise_error(IndexError)
12
12
  end
13
13
  end
14
14
 
@@ -151,7 +151,7 @@ describe Twitter::REST::API::Favorites do
151
151
  stub_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'}).to_return(:status => 403, :headers => {:content_type => 'application/json; charset=utf-8'})
152
152
  end
153
153
  it 'raises a Forbidden error' do
154
- expect { @client.favorite!(25_938_088_801) }.to raise_error Twitter::Error::Forbidden
154
+ expect { @client.favorite!(25_938_088_801) }.to raise_error(Twitter::Error::Forbidden)
155
155
  end
156
156
  end
157
157
  context 'already favorited' do
@@ -159,7 +159,7 @@ describe Twitter::REST::API::Favorites do
159
159
  stub_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'}).to_return(:status => 403, :body => fixture('already_favorited.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
160
160
  end
161
161
  it 'raises an AlreadyFavorited error' do
162
- expect { @client.favorite!(25_938_088_801) }.to raise_error Twitter::Error::AlreadyFavorited
162
+ expect { @client.favorite!(25_938_088_801) }.to raise_error(Twitter::Error::AlreadyFavorited)
163
163
  end
164
164
  end
165
165
  context 'with a URI object passed' do
@@ -223,7 +223,7 @@ describe Twitter::REST::API::Tweets do
223
223
  stub_post('/1.1/statuses/update.json').to_return(:status => 403, :body => fixture('already_posted.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
224
224
  end
225
225
  it 'raises an AlreadyPosted error' do
226
- expect { @client.update("The problem with your code is that it's doing exactly what you told it to do.") }.to raise_error Twitter::Error::AlreadyPosted
226
+ expect { @client.update("The problem with your code is that it's doing exactly what you told it to do.") }.to raise_error(Twitter::Error::AlreadyPosted)
227
227
  end
228
228
  end
229
229
  context 'with an in-reply-to status' do
@@ -333,7 +333,7 @@ describe Twitter::REST::API::Tweets do
333
333
  stub_post('/1.1/statuses/retweet/25938088801.json').to_return(:status => 403, :headers => {:content_type => 'application/json; charset=utf-8'})
334
334
  end
335
335
  it 'raises a Forbidden error' do
336
- expect { @client.retweet!(25_938_088_801) }.to raise_error Twitter::Error::Forbidden
336
+ expect { @client.retweet!(25_938_088_801) }.to raise_error(Twitter::Error::Forbidden)
337
337
  end
338
338
  end
339
339
  context 'already retweeted' do
@@ -341,7 +341,7 @@ describe Twitter::REST::API::Tweets do
341
341
  stub_post('/1.1/statuses/retweet/25938088801.json').to_return(:status => 403, :body => fixture('already_retweeted.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
342
342
  end
343
343
  it 'raises an AlreadyRetweeted error' do
344
- expect { @client.retweet!(25_938_088_801) }.to raise_error Twitter::Error::AlreadyRetweeted
344
+ expect { @client.retweet!(25_938_088_801) }.to raise_error(Twitter::Error::AlreadyRetweeted)
345
345
  end
346
346
  end
347
347
  context 'with a URI object passed' do
@@ -410,7 +410,7 @@ describe Twitter::REST::API::Tweets do
410
410
  stub_post('/1.1/statuses/update_with_media.json').to_return(:status => 403, :body => fixture('already_posted.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
411
411
  end
412
412
  it 'raises an AlreadyPosted error' do
413
- expect { @client.update_with_media("The problem with your code is that it's doing exactly what you told it to do.", fixture('pbjt.gif')) }.to raise_error Twitter::Error::AlreadyPosted
413
+ expect { @client.update_with_media("The problem with your code is that it's doing exactly what you told it to do.", fixture('pbjt.gif')) }.to raise_error(Twitter::Error::AlreadyPosted)
414
414
  end
415
415
  end
416
416
  end
@@ -43,26 +43,6 @@ describe Twitter::REST::Client do
43
43
  expect(user1).not_to eq(user2)
44
44
  end
45
45
 
46
- describe '#delete' do
47
- before do
48
- stub_delete('/custom/delete').with(:query => {:deleted => 'object'})
49
- end
50
- it 'allows custom delete requests' do
51
- @client.delete('/custom/delete', :deleted => 'object')
52
- expect(a_delete('/custom/delete').with(:query => {:deleted => 'object'})).to have_been_made
53
- end
54
- end
55
-
56
- describe '#put' do
57
- before do
58
- stub_put('/custom/put').with(:body => {:updated => 'object'})
59
- end
60
- it 'allows custom put requests' do
61
- @client.put('/custom/put', :updated => 'object')
62
- expect(a_put('/custom/put').with(:body => {:updated => 'object'})).to have_been_made
63
- end
64
- end
65
-
66
46
  describe '#user_token?' do
67
47
  it 'returns true if the user token/secret are present' do
68
48
  client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
@@ -117,13 +97,21 @@ describe Twitter::REST::Client do
117
97
  @client.update_with_media('Update', fixture('pbjt.gif'))
118
98
  expect(a_post('/1.1/statuses/update_with_media.json')).to have_been_made
119
99
  end
120
- it 'catches Faraday errors' do
121
- allow(@client).to receive(:connection).and_raise(Faraday::Error::ClientError.new('Oops'))
122
- expect { @client.send(:request, :get, '/path') }.to raise_error Twitter::Error
100
+ it 'catches and reraises Faraday timeout errors' do
101
+ allow(@client).to receive(:connection).and_raise(Faraday::Error::TimeoutError.new('execution expired'))
102
+ expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error::RequestTimeout)
103
+ end
104
+ it 'catches and reraises Timeout errors' do
105
+ allow(@client).to receive(:connection).and_raise(Timeout::Error.new('execution expired'))
106
+ expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error::RequestTimeout)
107
+ end
108
+ it 'catches and reraises Faraday client errors' do
109
+ allow(@client).to receive(:connection).and_raise(Faraday::Error::ClientError.new('connection failed'))
110
+ expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error)
123
111
  end
124
- it 'catches JSON::ParserError errors' do
112
+ it 'catches and reraises JSON::ParserError errors' do
125
113
  allow(@client).to receive(:connection).and_raise(JSON::ParserError.new('unexpected token'))
126
- expect { @client.send(:request, :get, '/path') }.to raise_error Twitter::Error
114
+ expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error)
127
115
  end
128
116
  end
129
117
 
@@ -156,6 +156,20 @@ describe Twitter::Tweet do
156
156
  end
157
157
  end
158
158
 
159
+ describe '#hashtags?' do
160
+ it 'returns true when the tweet includes hashtags entities' do
161
+ entities = {
162
+ :hashtags => [{:text => 'twitter', :indices => [10, 33]}]
163
+ }
164
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014, :entities => entities)
165
+ expect(tweet.hashtags?).to be_true
166
+ end
167
+ it 'returns false when no entities are present' do
168
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014)
169
+ expect(tweet.hashtags?).to be_false
170
+ end
171
+ end
172
+
159
173
  describe '#media' do
160
174
  it 'returns media' do
161
175
  media = Twitter::Tweet.new(:id => 28_669_546_014, :entities => {:media => [{:id => 1, :type => 'photo'}]}).media
@@ -172,6 +186,20 @@ describe Twitter::Tweet do
172
186
  end
173
187
  end
174
188
 
189
+ describe '#media?' do
190
+ it 'returns true when the tweet includes media entities' do
191
+ entities = {
192
+ :media => [{:id => '1', :type => 'photo'}]
193
+ }
194
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014, :entities => entities)
195
+ expect(tweet.media?).to be_true
196
+ end
197
+ it 'returns false when no entities are present' do
198
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014)
199
+ expect(tweet.media?).to be_false
200
+ end
201
+ end
202
+
175
203
  describe '#metadata' do
176
204
  it 'returns a Twitter::Metadata when metadata is set' do
177
205
  tweet = Twitter::Tweet.new(:id => 28_669_546_014, :metadata => {})
@@ -284,6 +312,20 @@ describe Twitter::Tweet do
284
312
  end
285
313
  end
286
314
 
315
+ describe '#symbols?' do
316
+ it 'returns true when the tweet includes symbols entities' do
317
+ entities = {
318
+ :symbols => [{:text => 'PEP'}]
319
+ }
320
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014, :entities => entities)
321
+ expect(tweet.symbols?).to be_true
322
+ end
323
+ it 'returns false when no entities are present' do
324
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014)
325
+ expect(tweet.symbols?).to be_false
326
+ end
327
+ end
328
+
287
329
  describe '#uris' do
288
330
  it 'returns an array of Entity::URIs when entities are set' do
289
331
  urls_array = [
@@ -334,6 +376,20 @@ describe Twitter::Tweet do
334
376
  end
335
377
  end
336
378
 
379
+ describe '#uris?' do
380
+ it 'returns true when the tweet includes urls entities' do
381
+ entities = {
382
+ :urls => [{:url => 'http://with_underscore.example.com/t.co'}]
383
+ }
384
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014, :entities => entities)
385
+ expect(tweet.uris?).to be_true
386
+ end
387
+ it 'returns false when no entities are present' do
388
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014)
389
+ expect(tweet.uris?).to be_false
390
+ end
391
+ end
392
+
337
393
  describe '#user' do
338
394
  it 'returns a User when user is set' do
339
395
  tweet = Twitter::Tweet.new(:id => 28_669_546_014, :user => {:id => 7_505_382})
@@ -388,4 +444,17 @@ describe Twitter::Tweet do
388
444
  end
389
445
  end
390
446
 
447
+ describe '#user_mentions?' do
448
+ it 'returns true when the tweet includes user_mention entities' do
449
+ entities = {
450
+ :user_mentions => [{:screen_name => 'sferik'}]
451
+ }
452
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014, :entities => entities)
453
+ expect(tweet.user_mentions?).to be_true
454
+ end
455
+ it 'returns false when no entities are present' do
456
+ tweet = Twitter::Tweet.new(:id => 28_669_546_014)
457
+ expect(tweet.user_mentions?).to be_false
458
+ end
459
+ end
391
460
  end
@@ -7,11 +7,12 @@ Gem::Specification.new do |spec|
7
7
  spec.add_dependency 'buftok', '~> 0.2.0'
8
8
  spec.add_dependency 'descendants_tracker', '~> 0.0.3'
9
9
  spec.add_dependency 'equalizer', '~> 0.0.9'
10
- spec.add_dependency 'faraday', ['>= 0.8', '< 0.10']
10
+ spec.add_dependency 'faraday', '~> 0.9.0'
11
11
  spec.add_dependency 'http', '~> 0.5.0'
12
12
  spec.add_dependency 'http_parser.rb', '~> 0.6.0'
13
13
  spec.add_dependency 'json', '~> 1.8'
14
14
  spec.add_dependency 'memoizable', '~> 0.4.0'
15
+ spec.add_dependency 'naught', '~> 1.0'
15
16
  spec.add_dependency 'simple_oauth', '~> 0.2.0'
16
17
  spec.add_development_dependency 'bundler', '~> 1.0'
17
18
  spec.authors = ['Erik Michaels-Ober', 'John Nunemaker', 'Wynn Netherland', 'Steve Richert', 'Steve Agalloco']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.5.1
4
+ version: 5.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
@@ -33,7 +33,7 @@ cert_chain:
33
33
  Sf3lVKpBCWgRpGTvy45XVpB+59y33PJmEuQ1PTEOYvQyao9UKMAAaAN/7qWQtjl0
34
34
  hlw=
35
35
  -----END CERTIFICATE-----
36
- date: 2014-01-06 00:00:00.000000000 Z
36
+ date: 2014-01-26 00:00:00.000000000 Z
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: addressable
@@ -95,22 +95,16 @@ dependencies:
95
95
  name: faraday
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: '0.8'
101
- - - "<"
98
+ - - "~>"
102
99
  - !ruby/object:Gem::Version
103
- version: '0.10'
100
+ version: 0.9.0
104
101
  type: :runtime
105
102
  prerelease: false
106
103
  version_requirements: !ruby/object:Gem::Requirement
107
104
  requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0.8'
111
- - - "<"
105
+ - - "~>"
112
106
  - !ruby/object:Gem::Version
113
- version: '0.10'
107
+ version: 0.9.0
114
108
  - !ruby/object:Gem::Dependency
115
109
  name: http
116
110
  requirement: !ruby/object:Gem::Requirement
@@ -167,6 +161,20 @@ dependencies:
167
161
  - - "~>"
168
162
  - !ruby/object:Gem::Version
169
163
  version: 0.4.0
164
+ - !ruby/object:Gem::Dependency
165
+ name: naught
166
+ requirement: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - "~>"
169
+ - !ruby/object:Gem::Version
170
+ version: '1.0'
171
+ type: :runtime
172
+ prerelease: false
173
+ version_requirements: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - "~>"
176
+ - !ruby/object:Gem::Version
177
+ version: '1.0'
170
178
  - !ruby/object:Gem::Dependency
171
179
  name: simple_oauth
172
180
  requirement: !ruby/object:Gem::Requirement
@@ -236,6 +244,7 @@ files:
236
244
  - lib/twitter/error/internal_server_error.rb
237
245
  - lib/twitter/error/not_acceptable.rb
238
246
  - lib/twitter/error/not_found.rb
247
+ - lib/twitter/error/request_timeout.rb
239
248
  - lib/twitter/error/service_unavailable.rb
240
249
  - lib/twitter/error/too_many_requests.rb
241
250
  - lib/twitter/error/unauthorized.rb
@@ -259,6 +268,7 @@ files:
259
268
  - lib/twitter/profile_banner.rb
260
269
  - lib/twitter/rate_limit.rb
261
270
  - lib/twitter/relationship.rb
271
+ - lib/twitter/request.rb
262
272
  - lib/twitter/rest/api/direct_messages.rb
263
273
  - lib/twitter/rest/api/favorites.rb
264
274
  - lib/twitter/rest/api/friends_and_followers.rb
@@ -385,7 +395,6 @@ files:
385
395
  - spec/twitter/list_spec.rb
386
396
  - spec/twitter/media/photo_spec.rb
387
397
  - spec/twitter/media_factory_spec.rb
388
- - spec/twitter/null_object_spec.rb
389
398
  - spec/twitter/oembed_spec.rb
390
399
  - spec/twitter/place_spec.rb
391
400
  - spec/twitter/profile_banner_spec.rb
@@ -446,7 +455,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
446
455
  version: 1.3.5
447
456
  requirements: []
448
457
  rubyforge_project:
449
- rubygems_version: 2.2.0
458
+ rubygems_version: 2.2.1
450
459
  signing_key:
451
460
  specification_version: 4
452
461
  summary: A Ruby interface to the Twitter API.
@@ -533,7 +542,6 @@ test_files:
533
542
  - spec/twitter/list_spec.rb
534
543
  - spec/twitter/media/photo_spec.rb
535
544
  - spec/twitter/media_factory_spec.rb
536
- - spec/twitter/null_object_spec.rb
537
545
  - spec/twitter/oembed_spec.rb
538
546
  - spec/twitter/place_spec.rb
539
547
  - spec/twitter/profile_banner_spec.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,90 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::NullObject do
4
-
5
- describe '#nil?' do
6
- it 'returns true' do
7
- expect(subject.nil?).to be true
8
- end
9
- end
10
-
11
- describe '#to_a' do
12
- it 'returns an empty array' do
13
- expect(subject.to_a).to be_an Array
14
- expect(subject.to_a).to be_empty
15
- end
16
- end
17
-
18
- describe '#to_ary' do
19
- it 'returns an empty array' do
20
- expect(subject.to_ary).to be_an Array
21
- expect(subject.to_ary).to be_empty
22
- end
23
- end
24
-
25
- if RUBY_VERSION >= '1.9'
26
- describe '#to_c' do
27
- it 'returns zero as a complex number' do
28
- expect(subject.to_c).to be_a Complex
29
- expect(subject.to_c).to be_zero
30
- end
31
- end
32
-
33
- describe '#to_r' do
34
- it 'returns zero as a rational number' do
35
- expect(subject.to_r).to be_a Rational
36
- expect(subject.to_r).to be_zero
37
- end
38
- end
39
- end
40
-
41
- if RUBY_VERSION >= '2.0'
42
- describe '#to_h' do
43
- it 'returns an empty hash' do
44
- expect(subject.to_h).to be_a Hash
45
- expect(subject.to_h).to be_empty
46
- end
47
- end
48
- end
49
-
50
- describe '#to_f' do
51
- it 'returns zero as a floating point number' do
52
- expect(subject.to_f).to be_a Float
53
- expect(subject.to_f).to be_zero
54
- end
55
- end
56
-
57
- describe '#to_i' do
58
- it 'returns zero' do
59
- expect(subject.to_i).to be_an Integer
60
- expect(subject.to_i).to be_zero
61
- end
62
- end
63
-
64
- describe '#to_s' do
65
- it 'returns an empty string' do
66
- expect(subject.to_s).to be_a String
67
- expect(subject.to_s).to be_empty
68
- end
69
- end
70
-
71
- describe '#to_str' do
72
- it 'returns an empty string' do
73
- expect(subject.to_str).to be_a String
74
- expect(subject.to_str).to be_empty
75
- end
76
- end
77
-
78
- describe 'calling any method' do
79
- it 'returns self' do
80
- expect(subject.any).to equal subject
81
- end
82
- end
83
-
84
- describe '#respond_to?' do
85
- it 'returns true' do
86
- expect(subject.respond_to?(:any)).to be true
87
- end
88
- end
89
-
90
- end