twitter 5.5.1 → 5.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bfdd02a5944df78afbf1124d926c9091e45664b
4
- data.tar.gz: 0d13ee7c160b20d5b6574e124695ee1ea11303d1
3
+ metadata.gz: dda8dd395f86366d6a6afb036d588f96fee8d48a
4
+ data.tar.gz: 2d90bbbeef08919eea3c8274800a9086eb72fab1
5
5
  SHA512:
6
- metadata.gz: c17c71d6fa3c510d6891ddf7005bf0c3e035261a8b9b9d807e5c049b318cf1dfe0f2bb26e5a9a9857e3be988876eadce3fb3c5d848c972bfb2868e55423652f1
7
- data.tar.gz: c94ba75414df2d149705bfc83a1e38372336505dd4caa4b38232797e90e72c000a0651a662ead16032a51d3c0fd1b56b72f02aeaf5cac246c48f6afe7469cbd7
6
+ metadata.gz: 1c5cdf8e00944217c80803067e3dc46b547a448943b1ffab6fd7636bfb2e039b18e791e487865fd1d86d97b14abab7537407e9ccffb385c30996748cdf93bc6f
7
+ data.tar.gz: 0d20f6820ee2d37ae35a28ede0123fb7a27ef090217cbff427e4df86f447323b63c013017a08b55a6c955a36050cbef185bda2df902f45ab778dc3d9bd080cc2
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,15 @@
1
+ 5.6.0
2
+ -----
3
+ * [Replace custom `Twitter::NullObject` with `Naught`](https://github.com/sferik/twitter/commit/bc3990e3588f889569f1c92e465c329c508ce32e)
4
+ * [Use `URI` and `CGI` to convert query string into a hash](https://github.com/sferik/twitter/commit/6dd9d97aaef3917868b870e01896ab937cbacfbb)
5
+ * [Increase default timeout values](https://github.com/sferik/twitter/commit/350536926d1c2c0656fdc79948c5f543e306e14e)
6
+ * [Add `Twitter::Error::RequestTimeout`](https://github.com/sferik/twitter/commit/3179537af41b2e2f85c0bc74be799faea0817e48)
7
+ * [Remove unused methods `#put` and `#delete` in `Twitter::REST::Client`](https://github.com/sferik/twitter/commit/eaaf234b84a6e2e1f7695f73befaf11f30664f4a)
8
+ * [Deprecate `retweeters_count` in favor of `retweet_count`](https://github.com/sferik/twitter/commit/ea39bd013364dc24f02e9a1eb25b4b48b99a5480)
9
+ * [Deprecate `favorites_count`/`favoriters_count` in favor of `favorite_count`](https://github.com/sferik/twitter/commit/ea39bd013364dc24f02e9a1eb25b4b48b99a5480)
10
+ * [Deprecate `to_hash`/`to_hsh` in favor of `to_h` or `attrs`](https://github.com/sferik/twitter/commit/63e2cdd693aece2912564988d06786cd23a2cad5)
11
+ * [Deprecate `oauth_token` and `oauth_token_secret` accessors](https://github.com/sferik/twitter/commit/ac246717557ea02565a1d93b3f9a975e7fd39874)
12
+
1
13
  5.5.1
2
14
  -----
3
15
  * [Fix bug where `Twitter::Error::AlreadyFavorited` would never be raised](https://github.com/sferik/twitter/issues/512) ([@polestarw](https://twitter.com/polestarw))
data/README.md CHANGED
@@ -5,14 +5,14 @@
5
5
  [![Dependency Status](https://gemnasium.com/sferik/twitter.png?travis)][gemnasium]
6
6
  [![Code Climate](https://codeclimate.com/github/sferik/twitter.png)][codeclimate]
7
7
  [![Coverage Status](https://coveralls.io/repos/sferik/twitter/badge.png?branch=master)][coveralls]
8
- [![Gittip](http://img.shields.io/gittip/sferik.png)][gittip]
8
+ [![Gittip](http://img.shields.io/gittip/gems.png)][gittip]
9
9
 
10
10
  [gem]: https://rubygems.org/gems/twitter
11
11
  [travis]: http://travis-ci.org/sferik/twitter
12
12
  [gemnasium]: https://gemnasium.com/sferik/twitter
13
13
  [codeclimate]: https://codeclimate.com/github/sferik/twitter
14
14
  [coveralls]: https://coveralls.io/r/sferik/twitter
15
- [gittip]: https://www.gittip.com/sferik/
15
+ [gittip]: https://www.gittip.com/gems/
16
16
 
17
17
  A Ruby interface to the Twitter API.
18
18
 
@@ -469,7 +469,7 @@ client.update("I'm tweeting with @gem!")
469
469
 
470
470
  ### Middleware
471
471
  The Faraday middleware stack is fully configurable and is exposed as a
472
- `Faraday::Builder` object. You can modify the default middleware in-place:
472
+ `Faraday::RackBuilder` object. You can modify the default middleware in-place:
473
473
 
474
474
  ```ruby
475
475
  client.middleware.insert_after Twitter::Response::RaiseError, CustomMiddleware
@@ -478,12 +478,10 @@ client.middleware.insert_after Twitter::Response::RaiseError, CustomMiddleware
478
478
  A custom adapter may be set as part of a custom middleware stack:
479
479
 
480
480
  ```ruby
481
- client.middleware = Faraday::Builder.new(
482
- &Proc.new do |builder|
483
- # Specify a middleware stack here
484
- builder.adapter :some_other_adapter
485
- end
486
- )
481
+ client.middleware = Faraday::RackBuilder.new do |faraday|
482
+ # Specify a middleware stack here
483
+ faraday.adapter :some_other_adapter
484
+ end
487
485
  ```
488
486
 
489
487
  ## Usage Examples
@@ -552,7 +550,7 @@ client.status(27558893223)
552
550
  **Collect the 3 most recent marriage proposals to @justinbieber**
553
551
 
554
552
  ```ruby
555
- client.search("to:justinbieber marry me", :count => 3, :result_type => "recent").collect do |tweet|
553
+ client.search("to:justinbieber marry me", :count => 3, :result_type => "recent").take(3).collect do |tweet|
556
554
  "#{tweet.user.screen_name}: #{tweet.text}"
557
555
  end
558
556
  ```
@@ -2,15 +2,17 @@ require 'addressable/uri'
2
2
  require 'forwardable'
3
3
  require 'memoizable'
4
4
  require 'twitter/null_object'
5
+ require 'twitter/utils'
5
6
 
6
7
  module Twitter
7
8
  class Base
8
9
  extend Forwardable
9
10
  include Memoizable
11
+ include Twitter::Utils
10
12
  attr_reader :attrs
11
13
  alias_method :to_h, :attrs
12
- alias_method :to_hash, :attrs
13
- alias_method :to_hsh, :attrs
14
+ deprecate_alias :to_hash, :to_h
15
+ deprecate_alias :to_hsh, :to_h
14
16
 
15
17
  class << self
16
18
  # Construct an object from a response hash
@@ -1,14 +1,16 @@
1
1
  require 'addressable/uri'
2
2
  require 'simple_oauth'
3
+ require 'twitter/utils'
3
4
  require 'twitter/version'
4
5
 
5
6
  module Twitter
6
7
  class Client
8
+ include Twitter::Utils
7
9
  attr_accessor :access_token, :access_token_secret, :consumer_key, :consumer_secret
8
- alias_method :oauth_token, :access_token
9
- alias_method :oauth_token=, :access_token=
10
- alias_method :oauth_token_secret, :access_token_secret
11
- alias_method :oauth_token_secret=, :access_token_secret=
10
+ deprecate_alias :oauth_token, :access_token
11
+ deprecate_alias :oauth_token=, :access_token=
12
+ deprecate_alias :oauth_token_secret, :access_token_secret
13
+ deprecate_alias :oauth_token_secret=, :access_token_secret=
12
14
 
13
15
  # Initializes a new Client object
14
16
  #
@@ -57,7 +59,7 @@ module Twitter
57
59
  def validate_credential_type!
58
60
  credentials.each do |credential, value|
59
61
  next if value.nil?
60
- fail(Error::ConfigurationError, "Invalid #{credential} specified: #{value.inspect} must be a string or symbol.") unless value.is_a?(String) || value.is_a?(Symbol)
62
+ fail(Error::ConfigurationError.new("Invalid #{credential} specified: #{value.inspect} must be a string or symbol.")) unless value.is_a?(String) || value.is_a?(Symbol)
61
63
  end
62
64
  end
63
65
 
@@ -12,7 +12,7 @@ module Twitter
12
12
  #
13
13
  # @return [Array<Twitter::Size>]
14
14
  def photo_sizes
15
- Array(@attrs[:photo_sizes]).reduce({}) do |object, (key, value)|
15
+ Array(@attrs[:photo_sizes]).inject({}) do |object, (key, value)|
16
16
  object[key] = Size.new(value)
17
17
  object
18
18
  end
@@ -1,12 +1,14 @@
1
1
  require 'twitter/enumerable'
2
+ require 'twitter/utils'
2
3
 
3
4
  module Twitter
4
5
  class Cursor
5
6
  include Twitter::Enumerable
7
+ include Twitter::Utils
6
8
  attr_reader :attrs
7
9
  alias_method :to_h, :attrs
8
- alias_method :to_hash, :attrs
9
- alias_method :to_hsh, :attrs
10
+ deprecate_alias :to_hash, :to_h
11
+ deprecate_alias :to_hsh, :to_h
10
12
 
11
13
  class << self
12
14
  # Construct a new Cursor object from a response hash
@@ -14,13 +16,10 @@ module Twitter
14
16
  # @param response [Hash]
15
17
  # @param key [String, Symbol] The key to fetch the data from the response
16
18
  # @param klass [Class] The class to instantiate objects in the response
17
- # @param client [Twitter::REST::Client]
18
- # @param request_method [String, Symbol]
19
- # @param path [String]
20
- # @param options [Hash]
19
+ # @param request [Twitter::Request]
21
20
  # @return [Twitter::Cursor]
22
- def from_response(response, key, klass, client, request_method, path, options) # rubocop:disable ParameterLists
23
- new(response[:body], key, klass, client, request_method, path, options)
21
+ def from_response(response, key, klass, request)
22
+ new(response[:body], key, klass, request)
24
23
  end
25
24
  end
26
25
 
@@ -29,24 +28,22 @@ module Twitter
29
28
  # @param attrs [Hash]
30
29
  # @param key [String, Symbol] The key to fetch the data from the response
31
30
  # @param klass [Class] The class to instantiate objects in the response
32
- # @param client [Twitter::REST::Client]
33
- # @param request_method [String, Symbol]
34
- # @param path [String]
35
- # @param options [Hash]
31
+ # @param request [Twitter::Request]
36
32
  # @return [Twitter::Cursor]
37
- def initialize(attrs, key, klass, client, request_method, path, options = {}) # rubocop:disable ParameterLists
33
+ def initialize(attrs, key, klass, request)
38
34
  @key = key.to_sym
39
35
  @klass = klass
40
- @client = client
41
- @request_method = request_method.to_sym
42
- @path = path
43
- @options = options
36
+ @client = request.client
37
+ @request_method = request.verb
38
+ @path = request.path
39
+ @options = request.options
44
40
  @collection = []
45
41
  self.attrs = attrs
46
42
  end
47
43
 
48
44
  private
49
45
 
46
+ # @return [Integer]
50
47
  def next_cursor
51
48
  @attrs[:next_cursor] || -1
52
49
  end
@@ -57,16 +54,20 @@ module Twitter
57
54
  next_cursor.zero?
58
55
  end
59
56
 
57
+ # @return [Hash]
60
58
  def fetch_next_page
61
59
  response = @client.send(@request_method, @path, @options.merge(:cursor => next_cursor))
62
60
  self.attrs = response[:body]
63
61
  end
64
62
 
63
+ # @param attrs [Hash]
64
+ # @return [Hash]
65
65
  def attrs=(attrs)
66
66
  @attrs = attrs
67
67
  Array(attrs[@key]).each do |element|
68
68
  @collection << (@klass ? @klass.new(element) : element)
69
69
  end
70
+ @attrs
70
71
  end
71
72
  end
72
73
  end
@@ -22,6 +22,11 @@ module Twitter
22
22
  end
23
23
  memoize :hashtags
24
24
 
25
+ # @return [Boolean]
26
+ def hashtags?
27
+ hashtags.any?
28
+ end
29
+
25
30
  # @note Must include entities in your request for this method to work
26
31
  # @return [Array<Twitter::Media>]
27
32
  def media
@@ -29,6 +34,11 @@ module Twitter
29
34
  end
30
35
  memoize :media
31
36
 
37
+ # @return [Boolean]
38
+ def media?
39
+ media.any?
40
+ end
41
+
32
42
  # @note Must include entities in your request for this method to work
33
43
  # @return [Array<Twitter::Entity::Symbol>]
34
44
  def symbols
@@ -36,6 +46,11 @@ module Twitter
36
46
  end
37
47
  memoize :symbols
38
48
 
49
+ # @return [Boolean]
50
+ def symbols?
51
+ symbols.any?
52
+ end
53
+
39
54
  # @note Must include entities in your request for this method to work
40
55
  # @return [Array<Twitter::Entity::URI>]
41
56
  def uris
@@ -44,6 +59,12 @@ module Twitter
44
59
  memoize :uris
45
60
  alias_method :urls, :uris
46
61
 
62
+ # @return [Boolean]
63
+ def uris?
64
+ uris.any?
65
+ end
66
+ alias_method :urls?, :uris?
67
+
47
68
  # @note Must include entities in your request for this method to work
48
69
  # @return [Array<Twitter::Entity::UserMention>]
49
70
  def user_mentions
@@ -51,13 +72,18 @@ module Twitter
51
72
  end
52
73
  memoize :user_mentions
53
74
 
75
+ # @return [Boolean]
76
+ def user_mentions?
77
+ user_mentions.any?
78
+ end
79
+
54
80
  private
55
81
 
56
82
  # @param klass [Class]
57
83
  # @param key [Symbol]
58
84
  def entities(klass, key)
59
85
  if entities?
60
- Array(@attrs[:entities][key.to_sym]).map do |entity|
86
+ Array(@attrs[:entities][key.to_sym]).collect do |entity|
61
87
  klass.new(entity)
62
88
  end
63
89
  else
@@ -42,7 +42,7 @@ module Twitter
42
42
 
43
43
  # @return [Hash]
44
44
  def errors
45
- @errors ||= descendants.reduce({}) do |hash, klass|
45
+ @errors ||= descendants.inject({}) do |hash, klass|
46
46
  hash[klass::HTTP_STATUS_CODE] = klass
47
47
  hash
48
48
  end
@@ -0,0 +1,10 @@
1
+ require 'twitter/error'
2
+
3
+ module Twitter
4
+ class Error
5
+ # Raised when the Faraday connection times out
6
+ class RequestTimeout < Twitter::Error
7
+ HTTP_STATUS_CODE = 408
8
+ end
9
+ end
10
+ end
@@ -1,12 +1,14 @@
1
1
  require 'twitter/enumerable'
2
+ require 'twitter/utils'
2
3
 
3
4
  module Twitter
4
5
  class GeoResults
5
6
  include Twitter::Enumerable
7
+ include Twitter::Utils
6
8
  attr_reader :attrs
7
9
  alias_method :to_h, :attrs
8
- alias_method :to_hash, :attrs
9
- alias_method :to_hsh, :attrs
10
+ deprecate_alias :to_hash, :to_h
11
+ deprecate_alias :to_hsh, :to_h
10
12
 
11
13
  class << self
12
14
  # Construct a new GeoResults object from a response hash
@@ -24,7 +26,7 @@ module Twitter
24
26
  # @return [Twitter::GeoResults]
25
27
  def initialize(attrs = {})
26
28
  @attrs = attrs
27
- @collection = Array(@attrs[:result][:places]).map do |place|
29
+ @collection = Array(@attrs[:result][:places]).collect do |place|
28
30
  Place.new(place)
29
31
  end
30
32
  end
@@ -11,7 +11,7 @@ module Twitter
11
11
  #
12
12
  # @return [Array<Twitter::Size>]
13
13
  def sizes
14
- Array(@attrs[:sizes]).reduce({}) do |object, (key, value)|
14
+ Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
15
15
  object[key] = Size.new(value)
16
16
  object
17
17
  end
@@ -1,26 +1,14 @@
1
- require 'forwardable'
1
+ require 'naught'
2
2
 
3
3
  module Twitter
4
- class NullObject
5
- extend Forwardable
6
- def_instance_delegators :nil, :nil?, :to_a, :to_c, :to_c, :to_f, :to_h,
7
- :to_i, :to_r, :to_s
8
- alias_method :to_ary, :to_a
9
- alias_method :to_str, :to_s
4
+ NullObject = Naught.build do |config|
5
+ config.black_hole
6
+ config.define_explicit_conversions
7
+ config.define_implicit_conversions
8
+ config.predicates_return false
10
9
 
11
- # @return [Twitter::NullObject] This method always returns self.
12
- def method_missing(*args, &block)
13
- self
14
- end
15
-
16
- # @return [TrueClass] This method always returns true.
17
- def respond_to?(method_name, include_private = false)
10
+ def nil?
18
11
  true
19
- end if RUBY_VERSION < '1.9'
20
-
21
- # @return [TrueClass] This method always returns true.
22
- def respond_to_missing?(method_name, include_private = false)
23
- true
24
- end if RUBY_VERSION >= '1.9'
12
+ end
25
13
  end
26
14
  end
@@ -6,7 +6,7 @@ module Twitter
6
6
  #
7
7
  # @return [Array<Twitter::Size>]
8
8
  def sizes
9
- Array(@attrs[:sizes]).reduce({}) do |object, (key, value)|
9
+ Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
10
10
  object[key] = Size.new(value)
11
11
  object
12
12
  end
@@ -0,0 +1,47 @@
1
+ require 'twitter/cursor'
2
+
3
+ module Twitter
4
+ class Request
5
+ attr_accessor :client, :request_method, :path, :options
6
+ alias_method :verb, :request_method
7
+
8
+ # @param client [Twitter::Client]
9
+ # @param request_method [String, Symbol]
10
+ # @param path [String]
11
+ # @param options [Hash]
12
+ # @return [Twitter::Request]
13
+ def initialize(client, request_method, path, options = {})
14
+ @client = client
15
+ @request_method = request_method.to_sym
16
+ @path = path
17
+ @options = options
18
+ end
19
+
20
+ # @return [Hash]
21
+ def perform
22
+ @client.send(@request_method, @path, @options)
23
+ end
24
+
25
+ # @param klass [Class]
26
+ # @param request [Twitter::Request]
27
+ # @return [Object]
28
+ def perform_with_object(klass)
29
+ klass.from_response(perform)
30
+ end
31
+
32
+ # @param collection_name [Symbol]
33
+ # @param klass [Class]
34
+ # @return [Twitter::Cursor]
35
+ def perform_with_cursor(collection_name, klass = nil)
36
+ Twitter::Cursor.from_response(perform, collection_name.to_sym, klass, self)
37
+ end
38
+
39
+ # @param klass [Class]
40
+ # @return [Array]
41
+ def perform_with_objects(klass)
42
+ perform[:body].collect do |element|
43
+ klass.new(element)
44
+ end
45
+ end
46
+ end
47
+ end