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.
Files changed (145) hide show
  1. data/.yardopts +4 -0
  2. data/CHANGELOG.md +47 -0
  3. data/CONTRIBUTING.md +5 -5
  4. data/README.md +57 -56
  5. data/Rakefile +26 -5
  6. data/lib/twitter/arguments.rb +1 -2
  7. data/lib/twitter/base.rb +15 -18
  8. data/lib/twitter/basic_user.rb +3 -3
  9. data/lib/twitter/client.rb +9 -10
  10. data/lib/twitter/configuration.rb +5 -5
  11. data/lib/twitter/creatable.rb +0 -1
  12. data/lib/twitter/cursor.rb +9 -36
  13. data/lib/twitter/direct_message.rb +1 -1
  14. data/lib/twitter/entity/uri.rb +2 -2
  15. data/lib/twitter/enumerable.rb +10 -1
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +1 -1
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/too_many_requests.rb +2 -2
  20. data/lib/twitter/error.rb +6 -6
  21. data/lib/twitter/factory.rb +2 -6
  22. data/lib/twitter/geo/point.rb +3 -5
  23. data/lib/twitter/geo.rb +1 -1
  24. data/lib/twitter/geo_factory.rb +1 -5
  25. data/lib/twitter/geo_results.rb +5 -8
  26. data/lib/twitter/identity.rb +1 -2
  27. data/lib/twitter/list.rb +10 -11
  28. data/lib/twitter/media/photo.rb +1 -2
  29. data/lib/twitter/media_factory.rb +1 -5
  30. data/lib/twitter/null_object.rb +4 -6
  31. data/lib/twitter/oembed.rb +1 -1
  32. data/lib/twitter/place.rb +17 -6
  33. data/lib/twitter/profile_banner.rb +1 -3
  34. data/lib/twitter/rate_limit.rb +1 -3
  35. data/lib/twitter/relationship.rb +1 -2
  36. data/lib/twitter/rest/api/direct_messages.rb +15 -15
  37. data/lib/twitter/rest/api/favorites.rb +15 -15
  38. data/lib/twitter/rest/api/friends_and_followers.rb +37 -42
  39. data/lib/twitter/rest/api/help.rb +8 -9
  40. data/lib/twitter/rest/api/lists.rb +69 -69
  41. data/lib/twitter/rest/api/oauth.rb +3 -4
  42. data/lib/twitter/rest/api/places_and_geo.rb +9 -10
  43. data/lib/twitter/rest/api/saved_searches.rb +8 -8
  44. data/lib/twitter/rest/api/search.rb +10 -2
  45. data/lib/twitter/rest/api/spam_reporting.rb +1 -2
  46. data/lib/twitter/rest/api/suggested_users.rb +4 -5
  47. data/lib/twitter/rest/api/timelines.rb +17 -18
  48. data/lib/twitter/rest/api/trends.rb +10 -11
  49. data/lib/twitter/rest/api/tweets.rb +31 -20
  50. data/lib/twitter/rest/api/undocumented.rb +6 -7
  51. data/lib/twitter/rest/api/users.rb +53 -54
  52. data/lib/twitter/rest/api/utils.rb +28 -34
  53. data/lib/twitter/rest/client.rb +8 -9
  54. data/lib/twitter/rest/request/multipart_with_file.rb +7 -5
  55. data/lib/twitter/rest/response/parse_error_json.rb +0 -2
  56. data/lib/twitter/rest/response/parse_json.rb +2 -2
  57. data/lib/twitter/rest/response/raise_error.rb +1 -3
  58. data/lib/twitter/search_results.rb +38 -56
  59. data/lib/twitter/settings.rb +2 -2
  60. data/lib/twitter/size.rb +2 -2
  61. data/lib/twitter/source_user.rb +1 -1
  62. data/lib/twitter/streaming/client.rb +69 -18
  63. data/lib/twitter/streaming/connection.rb +1 -3
  64. data/lib/twitter/streaming/deleted_tweet.rb +8 -0
  65. data/lib/twitter/streaming/event.rb +8 -8
  66. data/lib/twitter/streaming/friend_list.rb +2 -9
  67. data/lib/twitter/streaming/message_parser.rb +13 -3
  68. data/lib/twitter/streaming/response.rb +0 -2
  69. data/lib/twitter/streaming/stall_warning.rb +7 -0
  70. data/lib/twitter/suggestion.rb +0 -1
  71. data/lib/twitter/token.rb +2 -3
  72. data/lib/twitter/trend_results.rb +5 -8
  73. data/lib/twitter/tweet.rb +17 -18
  74. data/lib/twitter/user.rb +33 -35
  75. data/lib/twitter/utils.rb +14 -0
  76. data/lib/twitter/version.rb +2 -5
  77. data/lib/twitter.rb +1 -1
  78. data/spec/fixtures/forbidden.json +1 -0
  79. data/spec/fixtures/search.json +1 -1
  80. data/spec/fixtures/search2.json +1 -0
  81. data/spec/fixtures/track_streaming_user.json +2 -1
  82. data/spec/helper.rb +6 -2
  83. data/spec/twitter/base_spec.rb +9 -9
  84. data/spec/twitter/basic_user_spec.rb +6 -6
  85. data/spec/twitter/configuration_spec.rb +4 -4
  86. data/spec/twitter/cursor_spec.rb +13 -51
  87. data/spec/twitter/direct_message_spec.rb +36 -36
  88. data/spec/twitter/entity/uri_spec.rb +29 -29
  89. data/spec/twitter/error_spec.rb +21 -21
  90. data/spec/twitter/geo/point_spec.rb +9 -9
  91. data/spec/twitter/geo/polygon_spec.rb +5 -5
  92. data/spec/twitter/geo_factory_spec.rb +7 -7
  93. data/spec/twitter/geo_results_spec.rb +11 -11
  94. data/spec/twitter/geo_spec.rb +5 -5
  95. data/spec/twitter/identifiable_spec.rb +9 -9
  96. data/spec/twitter/list_spec.rb +38 -38
  97. data/spec/twitter/media/photo_spec.rb +58 -58
  98. data/spec/twitter/media_factory_spec.rb +5 -5
  99. data/spec/twitter/null_object_spec.rb +6 -6
  100. data/spec/twitter/oembed_spec.rb +68 -68
  101. data/spec/twitter/place_spec.rb +91 -62
  102. data/spec/twitter/profile_banner_spec.rb +3 -3
  103. data/spec/twitter/rate_limit_spec.rb +18 -18
  104. data/spec/twitter/relationship_spec.rb +16 -16
  105. data/spec/twitter/rest/api/direct_messages_spec.rb +61 -61
  106. data/spec/twitter/rest/api/favorites_spec.rb +93 -93
  107. data/spec/twitter/rest/api/friends_and_followers_spec.rb +357 -349
  108. data/spec/twitter/rest/api/geo_spec.rb +33 -33
  109. data/spec/twitter/rest/api/help_spec.rb +24 -24
  110. data/spec/twitter/rest/api/lists_spec.rb +487 -487
  111. data/spec/twitter/rest/api/oauth_spec.rb +30 -30
  112. data/spec/twitter/rest/api/saved_searches_spec.rb +50 -40
  113. data/spec/twitter/rest/api/search_spec.rb +27 -26
  114. data/spec/twitter/rest/api/spam_reporting_spec.rb +9 -9
  115. data/spec/twitter/rest/api/suggested_users_spec.rb +23 -23
  116. data/spec/twitter/rest/api/timelines_spec.rb +58 -58
  117. data/spec/twitter/rest/api/trends_spec.rb +26 -26
  118. data/spec/twitter/rest/api/tweets_spec.rb +304 -266
  119. data/spec/twitter/rest/api/undocumented_spec.rb +51 -51
  120. data/spec/twitter/rest/api/users_spec.rb +360 -360
  121. data/spec/twitter/rest/client_spec.rb +99 -103
  122. data/spec/twitter/saved_search_spec.rb +16 -16
  123. data/spec/twitter/search_results_spec.rb +14 -110
  124. data/spec/twitter/settings_spec.rb +8 -8
  125. data/spec/twitter/size_spec.rb +5 -5
  126. data/spec/twitter/source_user_spec.rb +6 -6
  127. data/spec/twitter/streaming/client_spec.rb +85 -54
  128. data/spec/twitter/streaming/deleted_tweet_spec.rb +23 -0
  129. data/spec/twitter/streaming/event_spec.rb +20 -22
  130. data/spec/twitter/streaming/friend_list_spec.rb +11 -0
  131. data/spec/twitter/streaming/message_parser_spec.rb +54 -0
  132. data/spec/twitter/suggestion_spec.rb +11 -11
  133. data/spec/twitter/target_user_spec.rb +6 -6
  134. data/spec/twitter/token_spec.rb +4 -4
  135. data/spec/twitter/trend_results_spec.rb +30 -30
  136. data/spec/twitter/trend_spec.rb +21 -21
  137. data/spec/twitter/tweet_spec.rb +178 -164
  138. data/spec/twitter/user_spec.rb +190 -190
  139. data/twitter.gemspec +6 -6
  140. data.tar.gz.sig +0 -0
  141. metadata +44 -16
  142. metadata.gz.sig +0 -0
  143. data/lib/twitter/core_ext/enumerable.rb +0 -10
  144. data/lib/twitter/core_ext/kernel.rb +0 -10
  145. data/spec/twitter_spec.rb +0 -0
@@ -4,70 +4,52 @@ module Twitter
4
4
  class SearchResults
5
5
  include Twitter::Enumerable
6
6
  attr_reader :attrs
7
- alias to_h attrs
8
- alias to_hash attrs
9
- alias to_hsh attrs
7
+ alias_method :to_h, :attrs
8
+ alias_method :to_hash, :attrs
9
+ alias_method :to_hsh, :attrs
10
10
 
11
11
  class << self
12
-
13
12
  # Construct a new SearchResults object from a response hash
14
13
  #
15
14
  # @param response [Hash]
16
- # @return [Twitter::Base]
17
- def from_response(response={})
18
- new(response[:body])
15
+ # @param client [Twitter::REST::Client]
16
+ # @param path [String]
17
+ # @return [Twitter::SearchResults]
18
+ def from_response(response, client, request_method, path, options) # rubocop:disable ParameterLists
19
+ new(response[:body], client, request_method, path, options)
19
20
  end
20
-
21
21
  end
22
22
 
23
23
  # Initializes a new SearchResults object
24
24
  #
25
25
  # @param attrs [Hash]
26
+ # @param client [Twitter::REST::Client]
27
+ # @param request_method [String, Symbol]
28
+ # @param path [String]
29
+ # @param options [Hash]
26
30
  # @return [Twitter::SearchResults]
27
- def initialize(attrs={})
28
- @attrs = attrs
29
- @collection = Array(@attrs[:statuses]).map do |tweet|
30
- Tweet.new(tweet)
31
- end
32
- end
33
-
34
- # @return [Float]
35
- def completed_in
36
- @attrs[:search_metadata][:completed_in] if @attrs[:search_metadata]
31
+ def initialize(attrs, client, request_method, path, options = {}) # rubocop:disable ParameterLists
32
+ @client = client
33
+ @request_method = request_method.to_sym
34
+ @path = path
35
+ @options = options
36
+ @collection = []
37
+ set_attrs(attrs)
37
38
  end
38
39
 
39
- # @return [Integer]
40
- def max_id
41
- @attrs[:search_metadata][:max_id] if @attrs[:search_metadata]
42
- end
43
-
44
- # @return [Integer]
45
- def page
46
- @attrs[:search_metadata][:page] if @attrs[:search_metadata]
47
- end
48
-
49
- # @return [String]
50
- def query
51
- @attrs[:search_metadata][:query] if @attrs[:search_metadata]
52
- end
53
-
54
- # @return [Integer]
55
- def results_per_page
56
- @attrs[:search_metadata][:count] if @attrs[:search_metadata]
57
- end
58
- alias rpp results_per_page
59
- alias count results_per_page
40
+ private
60
41
 
61
- # @return [Integer]
62
- def since_id
63
- @attrs[:search_metadata][:since_id] if @attrs[:search_metadata]
42
+ # @return [Boolean]
43
+ def last?
44
+ !next_results?
64
45
  end
65
46
 
66
47
  # @return [Boolean]
67
48
  def next_results?
68
49
  !!(@attrs[:search_metadata] && @attrs[:search_metadata][:next_results])
69
50
  end
70
- alias next_page? next_results?
51
+ alias_method :next_page?, :next_results?
52
+ alias_method :next?, :next_results?
71
53
 
72
54
  # Returns a Hash of query parameters for the next result in the search
73
55
  #
@@ -79,19 +61,20 @@ module Twitter
79
61
  query_string_to_hash(query_string)
80
62
  end
81
63
  end
82
- alias next_page next_results
64
+ alias_method :next_page, :next_results
65
+ alias_method :next, :next_results
83
66
 
84
- # Returns a Hash of query parameters for the refresh URL in the search
85
- #
86
- # @note Returned Hash can be merged into the previous search options list to easily access the refresh page.
87
- # @return [Hash] The parameters needed to refresh the page.
88
- def refresh_results
89
- query_string = strip_first_character(@attrs[:search_metadata][:refresh_url])
90
- query_string_to_hash(query_string)
67
+ def fetch_next_page
68
+ response = @client.send(@request_method, @path, next_page)
69
+ set_attrs(response[:body])
91
70
  end
92
- alias refresh_page refresh_results
93
71
 
94
- private
72
+ def set_attrs(attrs)
73
+ @attrs = attrs
74
+ Array(@attrs[:statuses]).map do |tweet|
75
+ @collection << Tweet.new(tweet)
76
+ end
77
+ end
95
78
 
96
79
  # Returns the string with the first character removed
97
80
  #
@@ -110,7 +93,7 @@ module Twitter
110
93
  # @example Remove the first character from a query string
111
94
  # strip_first_character!("?foo=bar&baz=qux") #=> "foo=bar&baz=qux"
112
95
  def strip_first_character!(string)
113
- string[0] = ""
96
+ string[0] = ''
114
97
  string
115
98
  end
116
99
 
@@ -132,8 +115,7 @@ module Twitter
132
115
  # @example Convert hash's keys to symbols
133
116
  # symbolize_keys({"foo"=>"bar", "baz"=>"qux"}) #=> {:foo=>"bar", :baz=>"qux"}
134
117
  def symbolize_keys(hash)
135
- Hash[hash.map{|key, value| [key.to_sym, value]}]
118
+ Hash[hash.map { |key, value| [key.to_sym, value] }]
136
119
  end
137
-
138
120
  end
139
121
  end
@@ -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,19 @@ 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 Twitter::User
133
+ user_ids << user.id
134
+ end
135
+ end
136
+ user_ids
137
+ end
87
138
  end
88
139
  end
89
140
  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,8 +17,12 @@ module Twitter
11
17
  DirectMessage.new(data[:direct_message])
12
18
  elsif data[:friends]
13
19
  FriendList.new(data[:friends])
20
+ elsif data[:delete] && data[:delete][:status]
21
+ DeletedTweet.new(data[:delete][:status])
22
+ elsif data[:warning]
23
+ StallWarning.new(data[:warning])
14
24
  end
15
25
  end
16
26
  end
17
27
  end
18
- 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,30 +4,31 @@ 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
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
13
14
  object_attr_reader :GeoFactory, :geo
14
15
  object_attr_reader :Metadata, :metadata
15
16
  object_attr_reader :Place, :place
16
17
  object_attr_reader :Tweet, :retweeted_status
17
- alias retweet retweeted_status
18
- alias retweeted_tweet retweeted_status
19
- alias retweet? retweeted_status?
20
- 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?
21
22
  object_attr_reader :User, :user, :status
22
23
 
23
24
  # @return [Boolean]
24
25
  def entities?
25
- !@attrs[:entities].nil? && @attrs[:entities].any?{|_, array| !array.empty?}
26
+ !@attrs[:entities].nil? && @attrs[:entities].any? { |_, array| !array.empty? }
26
27
  end
27
28
  memoize :entities?
28
29
 
29
30
  def filter_level
30
- @attrs[:filter_level] || "none"
31
+ @attrs[:filter_level] || 'none'
31
32
  end
32
33
  memoize :filter_level
33
34
 
@@ -72,10 +73,10 @@ module Twitter
72
73
 
73
74
  # @return [String] The URL to the tweet.
74
75
  def uri
75
- URI.parse("https://twitter.com/#{user.screen_name}/status/#{id}")
76
+ Addressable::URI.parse("https://twitter.com/#{user.screen_name}/status/#{id}")
76
77
  end
77
78
  memoize :uri
78
- alias url uri
79
+ alias_method :url, :uri
79
80
 
80
81
  # @note Must include entities in your request for this method to work
81
82
  # @return [Array<Twitter::Entity::URI>]
@@ -83,7 +84,7 @@ module Twitter
83
84
  entities(Entity::URI, :urls)
84
85
  end
85
86
  memoize :uris
86
- alias urls uris
87
+ alias_method :urls, :uris
87
88
 
88
89
  # @note Must include entities in your request for this method to work
89
90
  # @return [Array<Twitter::Entity::UserMention>]
@@ -106,8 +107,6 @@ module Twitter
106
107
  []
107
108
  end
108
109
  end
109
-
110
110
  end
111
-
112
- Status = Tweet
111
+ Status = Tweet # rubocop:disable ConstantName
113
112
  end