twitter 5.1.0 → 5.2.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 (139) hide show
  1. data/.yardopts +2 -0
  2. data/CHANGELOG.md +14 -1
  3. data/CONTRIBUTING.md +2 -2
  4. data/README.md +30 -20
  5. data/Rakefile +26 -5
  6. data/lib/twitter/arguments.rb +0 -1
  7. data/lib/twitter/base.rb +13 -16
  8. data/lib/twitter/basic_user.rb +3 -3
  9. data/lib/twitter/client.rb +7 -8
  10. data/lib/twitter/configuration.rb +5 -5
  11. data/lib/twitter/core_ext/enumerable.rb +0 -2
  12. data/lib/twitter/core_ext/kernel.rb +0 -2
  13. data/lib/twitter/creatable.rb +0 -1
  14. data/lib/twitter/cursor.rb +7 -10
  15. data/lib/twitter/direct_message.rb +1 -1
  16. data/lib/twitter/entity/uri.rb +2 -2
  17. data/lib/twitter/enumerable.rb +1 -2
  18. data/lib/twitter/error/already_favorited.rb +1 -1
  19. data/lib/twitter/error/already_posted.rb +1 -1
  20. data/lib/twitter/error/already_retweeted.rb +1 -1
  21. data/lib/twitter/error/too_many_requests.rb +2 -2
  22. data/lib/twitter/error.rb +4 -6
  23. data/lib/twitter/factory.rb +2 -6
  24. data/lib/twitter/geo/point.rb +3 -5
  25. data/lib/twitter/geo.rb +1 -1
  26. data/lib/twitter/geo_factory.rb +1 -5
  27. data/lib/twitter/geo_results.rb +5 -8
  28. data/lib/twitter/identity.rb +1 -2
  29. data/lib/twitter/list.rb +4 -5
  30. data/lib/twitter/media/photo.rb +1 -2
  31. data/lib/twitter/media_factory.rb +1 -5
  32. data/lib/twitter/null_object.rb +4 -6
  33. data/lib/twitter/oembed.rb +1 -1
  34. data/lib/twitter/place.rb +17 -6
  35. data/lib/twitter/profile_banner.rb +1 -3
  36. data/lib/twitter/rate_limit.rb +1 -3
  37. data/lib/twitter/relationship.rb +1 -2
  38. data/lib/twitter/rest/api/direct_messages.rb +13 -14
  39. data/lib/twitter/rest/api/favorites.rb +10 -11
  40. data/lib/twitter/rest/api/friends_and_followers.rb +36 -36
  41. data/lib/twitter/rest/api/help.rb +8 -9
  42. data/lib/twitter/rest/api/lists.rb +62 -63
  43. data/lib/twitter/rest/api/oauth.rb +3 -4
  44. data/lib/twitter/rest/api/places_and_geo.rb +9 -10
  45. data/lib/twitter/rest/api/saved_searches.rb +5 -6
  46. data/lib/twitter/rest/api/search.rb +2 -3
  47. data/lib/twitter/rest/api/spam_reporting.rb +1 -2
  48. data/lib/twitter/rest/api/suggested_users.rb +4 -5
  49. data/lib/twitter/rest/api/timelines.rb +17 -18
  50. data/lib/twitter/rest/api/trends.rb +10 -11
  51. data/lib/twitter/rest/api/tweets.rb +15 -16
  52. data/lib/twitter/rest/api/undocumented.rb +6 -7
  53. data/lib/twitter/rest/api/users.rb +51 -52
  54. data/lib/twitter/rest/api/utils.rb +23 -30
  55. data/lib/twitter/rest/client.rb +8 -9
  56. data/lib/twitter/rest/request/multipart_with_file.rb +0 -1
  57. data/lib/twitter/rest/response/parse_error_json.rb +0 -2
  58. data/lib/twitter/rest/response/parse_json.rb +0 -2
  59. data/lib/twitter/rest/response/raise_error.rb +1 -3
  60. data/lib/twitter/search_results.rb +12 -15
  61. data/lib/twitter/settings.rb +2 -2
  62. data/lib/twitter/size.rb +2 -2
  63. data/lib/twitter/source_user.rb +1 -1
  64. data/lib/twitter/streaming/client.rb +71 -18
  65. data/lib/twitter/streaming/connection.rb +1 -3
  66. data/lib/twitter/streaming/deleted_tweet.rb +8 -0
  67. data/lib/twitter/streaming/event.rb +8 -8
  68. data/lib/twitter/streaming/friend_list.rb +2 -9
  69. data/lib/twitter/streaming/message_parser.rb +13 -7
  70. data/lib/twitter/streaming/response.rb +0 -2
  71. data/lib/twitter/streaming/stall_warning.rb +7 -0
  72. data/lib/twitter/suggestion.rb +0 -1
  73. data/lib/twitter/token.rb +2 -3
  74. data/lib/twitter/trend_results.rb +5 -8
  75. data/lib/twitter/tweet.rb +16 -24
  76. data/lib/twitter/user.rb +30 -32
  77. data/lib/twitter/version.rb +1 -4
  78. data/spec/fixtures/track_streaming_user.json +2 -1
  79. data/spec/helper.rb +6 -2
  80. data/spec/twitter/base_spec.rb +9 -9
  81. data/spec/twitter/basic_user_spec.rb +6 -6
  82. data/spec/twitter/configuration_spec.rb +4 -4
  83. data/spec/twitter/cursor_spec.rb +27 -27
  84. data/spec/twitter/direct_message_spec.rb +36 -36
  85. data/spec/twitter/entity/uri_spec.rb +27 -27
  86. data/spec/twitter/error_spec.rb +21 -21
  87. data/spec/twitter/geo/point_spec.rb +9 -9
  88. data/spec/twitter/geo/polygon_spec.rb +5 -5
  89. data/spec/twitter/geo_factory_spec.rb +7 -7
  90. data/spec/twitter/geo_results_spec.rb +11 -11
  91. data/spec/twitter/geo_spec.rb +5 -5
  92. data/spec/twitter/identifiable_spec.rb +9 -9
  93. data/spec/twitter/list_spec.rb +38 -38
  94. data/spec/twitter/media/photo_spec.rb +54 -54
  95. data/spec/twitter/media_factory_spec.rb +5 -5
  96. data/spec/twitter/null_object_spec.rb +6 -6
  97. data/spec/twitter/oembed_spec.rb +65 -65
  98. data/spec/twitter/place_spec.rb +89 -60
  99. data/spec/twitter/profile_banner_spec.rb +3 -3
  100. data/spec/twitter/rate_limit_spec.rb +18 -18
  101. data/spec/twitter/relationship_spec.rb +16 -16
  102. data/spec/twitter/rest/api/direct_messages_spec.rb +61 -61
  103. data/spec/twitter/rest/api/favorites_spec.rb +93 -93
  104. data/spec/twitter/rest/api/friends_and_followers_spec.rb +349 -349
  105. data/spec/twitter/rest/api/geo_spec.rb +33 -33
  106. data/spec/twitter/rest/api/help_spec.rb +24 -24
  107. data/spec/twitter/rest/api/lists_spec.rb +487 -487
  108. data/spec/twitter/rest/api/oauth_spec.rb +30 -30
  109. data/spec/twitter/rest/api/saved_searches_spec.rb +40 -40
  110. data/spec/twitter/rest/api/search_spec.rb +16 -16
  111. data/spec/twitter/rest/api/spam_reporting_spec.rb +9 -9
  112. data/spec/twitter/rest/api/suggested_users_spec.rb +23 -23
  113. data/spec/twitter/rest/api/timelines_spec.rb +58 -58
  114. data/spec/twitter/rest/api/trends_spec.rb +26 -26
  115. data/spec/twitter/rest/api/tweets_spec.rb +284 -284
  116. data/spec/twitter/rest/api/undocumented_spec.rb +51 -51
  117. data/spec/twitter/rest/api/users_spec.rb +360 -360
  118. data/spec/twitter/rest/client_spec.rb +99 -103
  119. data/spec/twitter/saved_search_spec.rb +16 -16
  120. data/spec/twitter/search_results_spec.rb +44 -44
  121. data/spec/twitter/settings_spec.rb +8 -8
  122. data/spec/twitter/size_spec.rb +5 -5
  123. data/spec/twitter/source_user_spec.rb +6 -6
  124. data/spec/twitter/streaming/client_spec.rb +53 -49
  125. data/spec/twitter/streaming/deleted_tweet_spec.rb +23 -0
  126. data/spec/twitter/streaming/event_spec.rb +20 -22
  127. data/spec/twitter/streaming/friend_list_spec.rb +11 -0
  128. data/spec/twitter/streaming/message_parser_spec.rb +54 -0
  129. data/spec/twitter/suggestion_spec.rb +11 -11
  130. data/spec/twitter/target_user_spec.rb +6 -6
  131. data/spec/twitter/token_spec.rb +4 -4
  132. data/spec/twitter/trend_results_spec.rb +30 -30
  133. data/spec/twitter/trend_spec.rb +20 -20
  134. data/spec/twitter/tweet_spec.rb +170 -173
  135. data/spec/twitter/user_spec.rb +179 -179
  136. data/twitter.gemspec +2 -2
  137. data.tar.gz.sig +0 -0
  138. metadata +21 -4
  139. metadata.gz.sig +2 -3
@@ -3,8 +3,8 @@ require 'twitter/base'
3
3
  module Twitter
4
4
  class Settings < Twitter::Base
5
5
  attr_reader :always_use_https, :discoverable_by_email, :geo_enabled,
6
- :language, :protected, :screen_name, :show_all_inline_media, :sleep_time,
7
- :time_zone
6
+ :language, :protected, :screen_name, :show_all_inline_media,
7
+ :sleep_time, :time_zone
8
8
  object_attr_reader :Place, :trend_location
9
9
  end
10
10
  end
data/lib/twitter/size.rb CHANGED
@@ -5,7 +5,7 @@ module Twitter
5
5
  class Size < Twitter::Base
6
6
  include Equalizer.new(:h, :w)
7
7
  attr_reader :h, :resize, :w
8
- alias height h
9
- alias width w
8
+ alias_method :height, :h
9
+ alias_method :width, :w
10
10
  end
11
11
  end
@@ -3,6 +3,6 @@ require 'twitter/basic_user'
3
3
  module Twitter
4
4
  class SourceUser < Twitter::BasicUser
5
5
  attr_reader :all_replies, :blocking, :can_dm, :followed_by, :marked_spam,
6
- :notifications_enabled, :want_retweets
6
+ :notifications_enabled, :want_retweets
7
7
  end
8
8
  end
@@ -4,8 +4,6 @@ require 'twitter/client'
4
4
  require 'twitter/streaming/connection'
5
5
  require 'twitter/streaming/response'
6
6
  require 'twitter/streaming/message_parser'
7
- require 'twitter/streaming/event'
8
- require 'twitter/streaming/friend_list'
9
7
 
10
8
  module Twitter
11
9
  module Streaming
@@ -15,34 +13,74 @@ module Twitter
15
13
  # Initializes a new Client object
16
14
  #
17
15
  # @return [Twitter::Streaming::Client]
18
- def initialize(options={}, &block)
16
+ def initialize(options = {}, &block)
19
17
  super
20
18
  @connection = Streaming::Connection.new
21
19
  end
22
20
 
23
- # @yield [Twitter::Tweet] A stream of tweets.
24
- def filter(options={}, &block)
21
+ # Returns public statuses that match one or more filter predicates
22
+ #
23
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/filter
24
+ # @see https://dev.twitter.com/docs/streaming-apis/parameters
25
+ # @note At least one predicate parameter (follow, locations, or track) must be specified.
26
+ # @param options [Hash] A customizable set of options.
27
+ # @option options [String] :follow A comma separated list of user IDs, indicating the users to return statuses for in the stream.
28
+ # @option options [String] :track Includes additional Tweets matching the specified keywords. Phrases of keywords are specified by a comma-separated list.
29
+ # @option options [String] :locations Includes additional Tweets falling within the specified bounding boxes.
30
+ # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
31
+ def filter(options = {}, &block)
25
32
  request(:post, 'https://stream.twitter.com:443/1.1/statuses/filter.json', options, &block)
26
33
  end
27
34
 
28
- # @yield [Twitter::Tweet] A stream of tweets.
29
- def firehose(options={}, &block)
35
+ # Returns all public statuses
36
+ #
37
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/firehose
38
+ # @see https://dev.twitter.com/docs/streaming-apis/parameters
39
+ # @note This endpoint requires special permission to access.
40
+ # @param options [Hash] A customizable set of options.
41
+ # @option options [Integer] :count The number of messages to backfill.
42
+ # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
43
+ def firehose(options = {}, &block)
30
44
  request(:get, 'https://stream.twitter.com:443/1.1/statuses/firehose.json', options, &block)
31
45
  end
32
46
 
33
- # @yield [Twitter::Tweet] A stream of tweets.
34
- def sample(options={}, &block)
47
+ # Returns a small random sample of all public statuses
48
+ #
49
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/sample
50
+ # @see https://dev.twitter.com/docs/streaming-apis/parameters
51
+ # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
52
+ def sample(options = {}, &block)
35
53
  request(:get, 'https://stream.twitter.com:443/1.1/statuses/sample.json', options, &block)
36
54
  end
37
55
 
38
- # @yield [Twitter::Tweet] A stream of tweets.
56
+ # Streams messages for a set of user
57
+ #
58
+ # @see https://dev.twitter.com/docs/api/1.1/get/site
59
+ # @see https://dev.twitter.com/docs/streaming-apis/streams/site
60
+ # @see https://dev.twitter.com/docs/streaming-apis/parameters
61
+ # @param follow [Enumerable<Integer, String, Twitter::User>] A list of user IDs, indicating the users to return statuses for in the stream.
62
+ # @param options [Hash] A customizable set of options.
63
+ # @option options [String] :with Specifies whether to return information for just the users specified in the follow parameter, or include messages from accounts they follow.
64
+ # @option options [String] :replies Specifies whether stall warnings should be delivered.
65
+ # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
39
66
  def site(*args, &block)
40
67
  arguments = Arguments.new(args)
41
- request(:get, 'https://sitestream.twitter.com:443/1.1/site.json', arguments.options.merge(:follow => arguments.join(',')), &block)
68
+ user_ids = collect_user_ids(arguments)
69
+ request(:get, 'https://sitestream.twitter.com:443/1.1/site.json', arguments.options.merge(:follow => user_ids.join(',')), &block)
42
70
  end
43
71
 
44
- # @yield [Twitter::Tweet] A stream of tweets.
45
- def user(options={}, &block)
72
+ # Streams messages for a single user
73
+ #
74
+ # @see https://dev.twitter.com/docs/api/1.1/get/user
75
+ # @see https://dev.twitter.com/docs/streaming-apis/streams/user
76
+ # @see https://dev.twitter.com/docs/streaming-apis/parameters
77
+ # @param options [Hash] A customizable set of options.
78
+ # @option options [String] :with Specifies whether to return information for just the users specified in the follow parameter, or include messages from accounts they follow.
79
+ # @option options [String] :replies Specifies whether stall warnings should be delivered.
80
+ # @option options [String] :track Includes additional Tweets matching the specified keywords. Phrases of keywords are specified by a comma-separated list.
81
+ # @option options [String] :locations Includes additional Tweets falling within the specified bounding boxes.
82
+ # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
83
+ def user(options = {}, &block)
46
84
  request(:get, 'https://userstream.twitter.com:443/1.1/user.json', options, &block)
47
85
  end
48
86
 
@@ -54,19 +92,19 @@ module Twitter
54
92
  elsif instance_variable_defined?(:@before_request)
55
93
  @before_request
56
94
  else
57
- Proc.new {}
95
+ proc {}
58
96
  end
59
97
  end
60
98
 
61
99
  private
62
100
 
63
- def request(method, uri, params, &block)
101
+ def request(method, uri, params, &block) # rubocop:disable ParameterLists
64
102
  before_request.call
65
103
  headers = default_headers.merge(:authorization => oauth_auth_header(method, uri, params).to_s)
66
104
  request = HTTP::Request.new(method, uri + '?' + to_url_params(params), headers)
67
105
  response = Streaming::Response.new do |data|
68
- if item = Streaming::MessageParser.parse(data)
69
- yield item
106
+ if item = Streaming::MessageParser.parse(data) # rubocop:disable AssignmentInCondition, IfUnlessModifier
107
+ block.call(item)
70
108
  end
71
109
  end
72
110
  @connection.stream(request, response)
@@ -74,7 +112,7 @@ module Twitter
74
112
 
75
113
  def to_url_params(params)
76
114
  params.map do |param, value|
77
- [param, URI.encode(value)].join("=")
115
+ [param, URI.encode(value)].join('=')
78
116
  end.sort.join('&')
79
117
  end
80
118
 
@@ -84,6 +122,21 @@ module Twitter
84
122
  :user_agent => user_agent,
85
123
  }
86
124
  end
125
+
126
+ def collect_user_ids(users)
127
+ user_ids = []
128
+ users.flatten.each do |user|
129
+ case user
130
+ when Integer
131
+ user_ids << user
132
+ when String
133
+ user_ids << user.to_i
134
+ when Twitter::User
135
+ user_ids << user.id
136
+ end
137
+ end
138
+ user_ids
139
+ end
87
140
  end
88
141
  end
89
142
  end
@@ -5,18 +5,16 @@ require 'resolv'
5
5
  module Twitter
6
6
  module Streaming
7
7
  class Connection
8
-
9
8
  def stream(request, response)
10
9
  client_context = OpenSSL::SSL::SSLContext.new
11
10
  client = TCPSocket.new(Resolv.getaddress(request.uri.host), request.uri.port)
12
11
  ssl_client = OpenSSL::SSL::SSLSocket.new(client, client_context)
13
12
  ssl_client.connect
14
13
  request.stream(ssl_client)
15
- while body = ssl_client.readpartial(1024)
14
+ while body = ssl_client.readpartial(1024) # rubocop:disable AssignmentInCondition, WhileUntilModifier
16
15
  response << body
17
16
  end
18
17
  end
19
-
20
18
  end
21
19
  end
22
20
  end
@@ -0,0 +1,8 @@
1
+ module Twitter
2
+ module Streaming
3
+ class DeletedTweet < Twitter::Identity
4
+ attr_reader :user_id
5
+ end
6
+ DeletedStatus = DeletedTweet # rubocop:disable ConstantName
7
+ end
8
+ end
@@ -1,28 +1,28 @@
1
1
  module Twitter
2
2
  module Streaming
3
3
  class Event
4
-
5
4
  LIST_EVENTS = [
6
- :list_created, :list_destroyed, :list_updated, :list_member_added,
7
- :list_member_added, :list_member_removed, :list_user_subscribed,
8
- :list_user_subscribed, :list_user_unsubscribed, :list_user_unsubscribed
5
+ :list_created, :list_destroyed, :list_updated, :list_member_added,
6
+ :list_member_added, :list_member_removed, :list_user_subscribed,
7
+ :list_user_subscribed, :list_user_unsubscribed, :list_user_unsubscribed,
9
8
  ]
10
9
 
11
10
  TWEET_EVENTS = [
12
- :favorite, :unfavorite
11
+ :favorite, :unfavorite,
13
12
  ]
14
-
13
+
15
14
  attr_reader :name, :source, :target, :target_object
16
15
 
17
16
  # @param data [Hash]
18
17
  def initialize(data)
19
- @name = data[:event].intern
18
+ @name = data[:event].to_sym
20
19
  @source = Twitter::User.new(data[:source])
21
20
  @target = Twitter::User.new(data[:target])
22
21
  @target_object = target_object_factory(@name, data[:target_object])
23
22
  end
24
23
 
25
24
  private
25
+
26
26
  def target_object_factory(event_name, data)
27
27
  if LIST_EVENTS.include?(event_name)
28
28
  Twitter::List.new(data)
@@ -32,4 +32,4 @@ module Twitter
32
32
  end
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -1,13 +1,6 @@
1
1
  module Twitter
2
2
  module Streaming
3
- class FriendList
4
-
5
- attr_reader :friend_ids
6
-
7
- # @param friend_ids [Array]
8
- def initialize(friend_ids)
9
- @friend_ids = friend_ids
10
- end
3
+ class FriendList < Array
11
4
  end
12
5
  end
13
- end
6
+ end
@@ -1,8 +1,14 @@
1
+ require 'twitter/direct_message'
2
+ require 'twitter/streaming/deleted_tweet'
3
+ require 'twitter/streaming/event'
4
+ require 'twitter/streaming/friend_list'
5
+ require 'twitter/streaming/stall_warning'
6
+ require 'twitter/tweet'
7
+
1
8
  module Twitter
2
9
  module Streaming
3
10
  class MessageParser
4
-
5
- def self.parse(data)
11
+ def self.parse(data) # rubocop:disable CyclomaticComplexity
6
12
  if data[:id]
7
13
  Tweet.new(data)
8
14
  elsif data[:event]
@@ -11,12 +17,12 @@ module Twitter
11
17
  DirectMessage.new(data[:direct_message])
12
18
  elsif data[:friends]
13
19
  FriendList.new(data[:friends])
14
- elsif data[:delete]
15
- if data[:delete][:status]
16
- Tweet.new(data[:delete][:status].merge(:deleted => true))
17
- end
20
+ elsif data[:delete] && data[:delete][:status]
21
+ DeletedTweet.new(data[:delete][:status])
22
+ elsif data[:warning]
23
+ StallWarning.new(data[:warning])
18
24
  end
19
25
  end
20
26
  end
21
27
  end
22
- end
28
+ end
@@ -3,7 +3,6 @@ require 'buftok'
3
3
  module Twitter
4
4
  module Streaming
5
5
  class Response
6
-
7
6
  # Initializes a new Response object
8
7
  #
9
8
  # @return [Twitter::Streaming::Response]
@@ -28,7 +27,6 @@ module Twitter
28
27
  @block.call(JSON.parse(line, :symbolize_names => true))
29
28
  end
30
29
  end
31
-
32
30
  end
33
31
  end
34
32
  end
@@ -0,0 +1,7 @@
1
+ module Twitter
2
+ module Streaming
3
+ class StallWarning < Twitter::Base
4
+ attr_reader :code, :message, :percent_full
5
+ end
6
+ end
7
+ end
@@ -13,6 +13,5 @@ module Twitter
13
13
  end
14
14
  end
15
15
  memoize :users
16
-
17
16
  end
18
17
  end
data/lib/twitter/token.rb CHANGED
@@ -3,15 +3,14 @@ require 'twitter/base'
3
3
  module Twitter
4
4
  class Token < Twitter::Base
5
5
  attr_reader :access_token, :token_type
6
- alias to_s access_token
6
+ alias_method :to_s, :access_token
7
7
 
8
- BEARER_TYPE = "bearer"
8
+ BEARER_TYPE = 'bearer'
9
9
 
10
10
  # @return [Boolean]
11
11
  def bearer?
12
12
  @attrs[:token_type] == BEARER_TYPE
13
13
  end
14
14
  memoize :bearer?
15
-
16
15
  end
17
16
  end
@@ -9,27 +9,25 @@ module Twitter
9
9
  include Twitter::Enumerable
10
10
  include Memoizable
11
11
  attr_reader :attrs
12
- alias to_h attrs
13
- alias to_hash attrs
14
- alias to_hsh attrs
12
+ alias_method :to_h, :attrs
13
+ alias_method :to_hash, :attrs
14
+ alias_method :to_hsh, :attrs
15
15
 
16
16
  class << self
17
-
18
17
  # Construct a new TrendResults object from a response hash
19
18
  #
20
19
  # @param response [Hash]
21
20
  # @return [Twitter::Base]
22
- def from_response(response={})
21
+ def from_response(response = {})
23
22
  new(response[:body].first)
24
23
  end
25
-
26
24
  end
27
25
 
28
26
  # Initializes a new TrendResults object
29
27
  #
30
28
  # @param attrs [Hash]
31
29
  # @return [Twitter::TrendResults]
32
- def initialize(attrs={})
30
+ def initialize(attrs = {})
33
31
  @attrs = attrs
34
32
  @collection = Array(@attrs[:trends]).map do |trend|
35
33
  Trend.new(trend)
@@ -60,6 +58,5 @@ module Twitter
60
58
  !@attrs[:locations].nil? && !@attrs[:locations].first.nil?
61
59
  end
62
60
  memoize :location?
63
-
64
61
  end
65
62
  end
data/lib/twitter/tweet.rb CHANGED
@@ -4,39 +4,33 @@ module Twitter
4
4
  class Tweet < Twitter::Identity
5
5
  include Twitter::Creatable
6
6
  attr_reader :favorite_count, :favorited, :in_reply_to_screen_name,
7
- :in_reply_to_attrs_id, :in_reply_to_status_id, :in_reply_to_user_id,
8
- :lang, :retweet_count, :retweeted, :source, :text, :truncated
9
- alias favorites_count favorite_count
10
- alias favoriters_count favorite_count
11
- alias in_reply_to_tweet_id in_reply_to_status_id
12
- alias retweeters_count retweet_count
13
- attr_reader :deleted
7
+ :in_reply_to_attrs_id, :in_reply_to_status_id,
8
+ :in_reply_to_user_id, :lang, :retweet_count, :retweeted,
9
+ :source, :text, :truncated
10
+ alias_method :favorites_count, :favorite_count
11
+ alias_method :favoriters_count, :favorite_count
12
+ alias_method :in_reply_to_tweet_id, :in_reply_to_status_id
13
+ alias_method :retweeters_count, :retweet_count
14
14
  object_attr_reader :GeoFactory, :geo
15
15
  object_attr_reader :Metadata, :metadata
16
16
  object_attr_reader :Place, :place
17
17
  object_attr_reader :Tweet, :retweeted_status
18
- alias retweet retweeted_status
19
- alias retweeted_tweet retweeted_status
20
- alias retweet? retweeted_status?
21
- alias retweeted_tweet? retweeted_status?
18
+ alias_method :retweet, :retweeted_status
19
+ alias_method :retweeted_tweet, :retweeted_status
20
+ alias_method :retweet?, :retweeted_status?
21
+ alias_method :retweeted_tweet?, :retweeted_status?
22
22
  object_attr_reader :User, :user, :status
23
23
 
24
24
  # @return [Boolean]
25
25
  def entities?
26
- !@attrs[:entities].nil? && @attrs[:entities].any?{|_, array| !array.empty?}
26
+ !@attrs[:entities].nil? && @attrs[:entities].any? { |_, array| !array.empty? }
27
27
  end
28
28
  memoize :entities?
29
29
 
30
30
  def filter_level
31
- @attrs[:filter_level] || "none"
31
+ @attrs[:filter_level] || 'none'
32
32
  end
33
33
  memoize :filter_level
34
-
35
- # @note Not a real entity
36
- # @return [Boolean]
37
- def deleted?
38
- deleted == true
39
- end
40
34
 
41
35
  # @return [String]
42
36
  # @note May be > 140 characters.
@@ -82,7 +76,7 @@ module Twitter
82
76
  Addressable::URI.parse("https://twitter.com/#{user.screen_name}/status/#{id}")
83
77
  end
84
78
  memoize :uri
85
- alias url uri
79
+ alias_method :url, :uri
86
80
 
87
81
  # @note Must include entities in your request for this method to work
88
82
  # @return [Array<Twitter::Entity::URI>]
@@ -90,7 +84,7 @@ module Twitter
90
84
  entities(Entity::URI, :urls)
91
85
  end
92
86
  memoize :uris
93
- alias urls uris
87
+ alias_method :urls, :uris
94
88
 
95
89
  # @note Must include entities in your request for this method to work
96
90
  # @return [Array<Twitter::Entity::UserMention>]
@@ -113,8 +107,6 @@ module Twitter
113
107
  []
114
108
  end
115
109
  end
116
-
117
110
  end
118
-
119
- Status = Tweet
111
+ Status = Tweet # rubocop:disable ConstantName
120
112
  end
data/lib/twitter/user.rb CHANGED
@@ -7,32 +7,32 @@ module Twitter
7
7
  PREDICATE_URI_METHOD_REGEX = /_uri\?$/
8
8
  include Twitter::Creatable
9
9
  attr_reader :connections, :contributors_enabled, :default_profile,
10
- :default_profile_image, :description, :favourites_count,
11
- :follow_request_sent, :followers_count, :friends_count, :geo_enabled,
12
- :is_translator, :lang, :listed_count, :location, :name, :notifications,
13
- :profile_background_color, :profile_background_image_url,
14
- :profile_background_image_url_https, :profile_background_tile,
15
- :profile_link_color, :profile_sidebar_border_color,
16
- :profile_sidebar_fill_color, :profile_text_color,
17
- :profile_use_background_image, :protected, :statuses_count, :time_zone,
18
- :utc_offset, :verified
19
- alias favorites_count favourites_count
10
+ :default_profile_image, :description, :favourites_count,
11
+ :follow_request_sent, :followers_count, :friends_count,
12
+ :geo_enabled, :is_translator, :lang, :listed_count, :location,
13
+ :name, :notifications, :profile_background_color,
14
+ :profile_background_image_url,
15
+ :profile_background_image_url_https, :profile_background_tile,
16
+ :profile_link_color, :profile_sidebar_border_color,
17
+ :profile_sidebar_fill_color, :profile_text_color,
18
+ :profile_use_background_image, :protected, :statuses_count,
19
+ :time_zone, :utc_offset, :verified
20
+ alias_method :favorites_count, :favourites_count
20
21
  remove_method :favourites_count
21
- alias profile_background_image_uri profile_background_image_url
22
- alias profile_background_image_uri_https profile_background_image_url_https
23
- alias translator? is_translator
24
- alias tweets_count statuses_count
22
+ alias_method :profile_background_image_uri, :profile_background_image_url
23
+ alias_method :profile_background_image_uri_https, :profile_background_image_url_https
24
+ alias_method :translator?, :is_translator
25
+ alias_method :tweets_count, :statuses_count
25
26
  object_attr_reader :Tweet, :status, :user
26
- alias tweet status
27
- alias tweet? status?
28
- alias tweeted? status?
27
+ alias_method :tweet, :status
28
+ alias_method :tweet?, :status?
29
+ alias_method :tweeted?, :status?
29
30
 
30
31
  class << self
31
-
32
32
  private
33
33
 
34
34
  def alias_predicate_uri_methods(method)
35
- for replacement in %w(_url? _uri_https? _url_https?)
35
+ %w(_url? _uri_https? _url_https?).each do |replacement|
36
36
  alias_method_sub(method, PREDICATE_URI_METHOD_REGEX, replacement)
37
37
  end
38
38
  end
@@ -40,7 +40,6 @@ module Twitter
40
40
  def alias_method_sub(method, pattern, replacement)
41
41
  alias_method(method.to_s.sub(pattern, replacement).to_sym, method)
42
42
  end
43
-
44
43
  end
45
44
 
46
45
  # @return [Array<Twitter::Entity::URI>]
@@ -50,25 +49,25 @@ module Twitter
50
49
  end
51
50
  end
52
51
  memoize :description_uris
53
- alias description_urls description_uris
52
+ alias_method :description_urls, :description_uris
54
53
 
55
54
  # Return the URL to the user's profile banner image
56
55
  #
57
56
  # @param size [String, Symbol] The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina'
58
57
  # @return [String]
59
- def profile_banner_uri(size=:web)
58
+ def profile_banner_uri(size = :web)
60
59
  parse_encoded_uri(insecure_uri([@attrs[:profile_banner_url], size].join('/'))) if @attrs[:profile_banner_url]
61
60
  end
62
- alias profile_banner_url profile_banner_uri
61
+ alias_method :profile_banner_url, :profile_banner_uri
63
62
 
64
63
  # Return the secure URL to the user's profile banner image
65
64
  #
66
65
  # @param size [String, Symbol] The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina'
67
66
  # @return [String]
68
- def profile_banner_uri_https(size=:web)
67
+ def profile_banner_uri_https(size = :web)
69
68
  parse_encoded_uri([@attrs[:profile_banner_url], size].join('/')) if @attrs[:profile_banner_url]
70
69
  end
71
- alias profile_banner_url_https profile_banner_uri_https
70
+ alias_method :profile_banner_url_https, :profile_banner_uri_https
72
71
 
73
72
  # @return [Boolean]
74
73
  def profile_banner_uri?
@@ -81,16 +80,16 @@ module Twitter
81
80
  #
82
81
  # @param size [String, Symbol] The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original'
83
82
  # @return [String]
84
- def profile_image_uri(size=:normal)
83
+ def profile_image_uri(size = :normal)
85
84
  parse_encoded_uri(insecure_uri(profile_image_uri_https(size))) if @attrs[:profile_image_url_https]
86
85
  end
87
- alias profile_image_url profile_image_uri
86
+ alias_method :profile_image_url, :profile_image_uri
88
87
 
89
88
  # Return the secure URL to the user's profile image
90
89
  #
91
90
  # @param size [String, Symbol] The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original'
92
91
  # @return [String]
93
- def profile_image_uri_https(size=:normal)
92
+ def profile_image_uri_https(size = :normal)
94
93
  # The profile image URL comes in looking like like this:
95
94
  # https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png
96
95
  # It can be converted to any of the following sizes:
@@ -99,7 +98,7 @@ module Twitter
99
98
  # https://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png
100
99
  parse_encoded_uri(@attrs[:profile_image_url_https].sub(PROFILE_IMAGE_SUFFIX_REGEX, profile_image_suffix(size))) if @attrs[:profile_image_url_https]
101
100
  end
102
- alias profile_image_url_https profile_image_uri_https
101
+ alias_method :profile_image_url_https, :profile_image_uri_https
103
102
 
104
103
  def profile_image_uri?
105
104
  !!@attrs[:profile_image_url_https]
@@ -112,7 +111,7 @@ module Twitter
112
111
  Addressable::URI.parse("https://twitter.com/#{screen_name}")
113
112
  end
114
113
  memoize :uri
115
- alias url uri
114
+ alias_method :url, :uri
116
115
 
117
116
  # @return [String] The URL to the user's website.
118
117
  def website
@@ -136,8 +135,7 @@ module Twitter
136
135
  end
137
136
 
138
137
  def profile_image_suffix(size)
139
- :original == size.to_sym ? "\\1" : "_#{size}\\1"
138
+ :original == size.to_sym ? '\\1' : "_#{size}\\1"
140
139
  end
141
-
142
140
  end
143
141
  end
@@ -1,18 +1,15 @@
1
1
  module Twitter
2
2
  class Version
3
3
  MAJOR = 5
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
  PRE = nil
7
7
 
8
8
  class << self
9
-
10
9
  # @return [String]
11
10
  def to_s
12
11
  [MAJOR, MINOR, PATCH, PRE].compact.join('.')
13
12
  end
14
-
15
13
  end
16
-
17
14
  end
18
15
  end