twitter 8.2.0 → 8.3.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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.md +172 -10
  4. data/lib/twitter/arguments.rb +14 -1
  5. data/lib/twitter/base.rb +72 -11
  6. data/lib/twitter/basic_user.rb +7 -1
  7. data/lib/twitter/client.rb +94 -3
  8. data/lib/twitter/creatable.rb +11 -2
  9. data/lib/twitter/cursor.rb +58 -11
  10. data/lib/twitter/direct_message.rb +32 -4
  11. data/lib/twitter/direct_message_event.rb +34 -10
  12. data/lib/twitter/direct_messages/welcome_message.rb +22 -1
  13. data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
  14. data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
  15. data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
  16. data/lib/twitter/entities.rb +84 -8
  17. data/lib/twitter/entity/hashtag.rb +7 -1
  18. data/lib/twitter/entity/symbol.rb +7 -1
  19. data/lib/twitter/entity/uri.rb +2 -1
  20. data/lib/twitter/entity/user_mention.rb +20 -1
  21. data/lib/twitter/entity.rb +7 -1
  22. data/lib/twitter/enumerable.rb +20 -3
  23. data/lib/twitter/error.rb +137 -61
  24. data/lib/twitter/factory.rb +9 -5
  25. data/lib/twitter/geo/point.rb +37 -5
  26. data/lib/twitter/geo/polygon.rb +1 -0
  27. data/lib/twitter/geo.rb +16 -2
  28. data/lib/twitter/geo_factory.rb +7 -3
  29. data/lib/twitter/geo_results.rb +39 -8
  30. data/lib/twitter/headers.rb +44 -7
  31. data/lib/twitter/identity.rb +13 -3
  32. data/lib/twitter/language.rb +21 -1
  33. data/lib/twitter/list.rb +101 -11
  34. data/lib/twitter/media/animated_gif.rb +1 -0
  35. data/lib/twitter/media/photo.rb +19 -3
  36. data/lib/twitter/media/video.rb +21 -3
  37. data/lib/twitter/media/video_info.rb +15 -1
  38. data/lib/twitter/media_factory.rb +7 -3
  39. data/lib/twitter/metadata.rb +14 -1
  40. data/lib/twitter/null_object.rb +16 -14
  41. data/lib/twitter/oembed.rb +56 -2
  42. data/lib/twitter/place.rb +74 -6
  43. data/lib/twitter/premium_search_results.rb +87 -18
  44. data/lib/twitter/profile.rb +100 -44
  45. data/lib/twitter/profile_banner.rb +9 -4
  46. data/lib/twitter/rate_limit.rb +32 -3
  47. data/lib/twitter/relationship.rb +8 -5
  48. data/lib/twitter/rest/account_activity.rb +55 -26
  49. data/lib/twitter/rest/api.rb +2 -0
  50. data/lib/twitter/rest/client.rb +18 -0
  51. data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
  52. data/lib/twitter/rest/direct_messages.rb +160 -96
  53. data/lib/twitter/rest/favorites.rb +58 -22
  54. data/lib/twitter/rest/form_encoder.rb +57 -17
  55. data/lib/twitter/rest/friends_and_followers.rb +101 -35
  56. data/lib/twitter/rest/help.rb +13 -3
  57. data/lib/twitter/rest/lists.rb +136 -47
  58. data/lib/twitter/rest/oauth.rb +21 -15
  59. data/lib/twitter/rest/places_and_geo.rb +44 -28
  60. data/lib/twitter/rest/premium_search.rb +17 -12
  61. data/lib/twitter/rest/request.rb +173 -55
  62. data/lib/twitter/rest/saved_searches.rb +22 -7
  63. data/lib/twitter/rest/search.rb +20 -16
  64. data/lib/twitter/rest/spam_reporting.rb +5 -1
  65. data/lib/twitter/rest/suggested_users.rb +15 -6
  66. data/lib/twitter/rest/timelines.rb +92 -52
  67. data/lib/twitter/rest/trends.rb +32 -13
  68. data/lib/twitter/rest/tweets.rb +147 -89
  69. data/lib/twitter/rest/undocumented.rb +10 -1
  70. data/lib/twitter/rest/upload_utils.rb +45 -29
  71. data/lib/twitter/rest/users.rb +151 -72
  72. data/lib/twitter/rest/utils.rb +135 -39
  73. data/lib/twitter/saved_search.rb +23 -2
  74. data/lib/twitter/search_results.rb +66 -18
  75. data/lib/twitter/settings.rb +37 -11
  76. data/lib/twitter/size.rb +37 -3
  77. data/lib/twitter/source_user.rb +4 -3
  78. data/lib/twitter/streaming/client.rb +61 -9
  79. data/lib/twitter/streaming/connection.rb +54 -6
  80. data/lib/twitter/streaming/deleted_tweet.rb +8 -0
  81. data/lib/twitter/streaming/event.rb +43 -1
  82. data/lib/twitter/streaming/friend_list.rb +1 -0
  83. data/lib/twitter/streaming/message_parser.rb +20 -10
  84. data/lib/twitter/streaming/response.rb +31 -5
  85. data/lib/twitter/streaming/stall_warning.rb +23 -0
  86. data/lib/twitter/suggestion.rb +25 -1
  87. data/lib/twitter/target_user.rb +2 -1
  88. data/lib/twitter/trend.rb +29 -1
  89. data/lib/twitter/trend_results.rb +50 -7
  90. data/lib/twitter/tweet.rb +180 -21
  91. data/lib/twitter/user.rb +289 -53
  92. data/lib/twitter/utils.rb +12 -13
  93. data/lib/twitter/variant.rb +12 -1
  94. data/lib/twitter/version.rb +66 -29
  95. data/lib/twitter.rb +6 -1
  96. metadata +23 -57
  97. data/.yardopts +0 -16
  98. data/CHANGELOG.md +0 -1040
  99. data/CONTRIBUTING.md +0 -49
  100. data/twitter.gemspec +0 -40
@@ -8,13 +8,28 @@ require "twitter/streaming/response"
8
8
  require "twitter/utils"
9
9
 
10
10
  module Twitter
11
+ # Streaming API modules for Twitter
11
12
  module Streaming
13
+ # Client for consuming the Twitter Streaming API
14
+ #
15
+ # @api public
12
16
  class Client < Twitter::Client
13
17
  include Twitter::Utils
18
+
19
+ # Sets the connection object
20
+ #
21
+ # @api public
22
+ # @example
23
+ # client.connection = connection
24
+ # @param value [Twitter::Streaming::Connection] The connection to use.
25
+ # @return [Twitter::Streaming::Connection]
14
26
  attr_writer :connection
15
27
 
16
28
  # Initializes a new Client object
17
29
  #
30
+ # @api public
31
+ # @example
32
+ # client = Twitter::Streaming::Client.new
18
33
  # @param options [Hash] A customizable set of options.
19
34
  # @option options [String] :tcp_socket_class A class that Connection will use to create a new TCP socket.
20
35
  # @option options [String] :ssl_socket_class A class that Connection will use to create a new SSL socket.
@@ -26,6 +41,9 @@ module Twitter
26
41
 
27
42
  # Returns public statuses that match one or more filter predicates
28
43
  #
44
+ # @api public
45
+ # @example
46
+ # client.filter(track: 'twitter')
29
47
  # @see https://dev.twitter.com/streaming/reference/post/statuses/filter
30
48
  # @see https://dev.twitter.com/streaming/overview/request-parameters
31
49
  # @note At least one predicate parameter (follow, locations, or track) must be specified.
@@ -34,33 +52,45 @@ module Twitter
34
52
  # @option options [String] :track Includes additional Tweets matching the specified keywords. Phrases of keywords are specified by a comma-separated list.
35
53
  # @option options [String] :locations Includes additional Tweets falling within the specified bounding boxes.
36
54
  # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
55
+ # @return [void]
37
56
  def filter(options = {}, &)
38
57
  request(:post, "https://stream.twitter.com:443/1.1/statuses/filter.json", options, &)
39
58
  end
40
59
 
41
60
  # Returns all public statuses
42
61
  #
62
+ # @api public
63
+ # @example
64
+ # client.firehose
43
65
  # @see https://dev.twitter.com/streaming/reference/get/statuses/firehose
44
66
  # @see https://dev.twitter.com/streaming/overview/request-parameters
45
67
  # @note This endpoint requires special permission to access.
46
68
  # @param options [Hash] A customizable set of options.
47
69
  # @option options [Integer] :count The number of messages to backfill.
48
70
  # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
71
+ # @return [void]
49
72
  def firehose(options = {}, &)
50
73
  request(:get, "https://stream.twitter.com:443/1.1/statuses/firehose.json", options, &)
51
74
  end
52
75
 
53
76
  # Returns a small random sample of all public statuses
54
77
  #
78
+ # @api public
79
+ # @example
80
+ # client.sample
55
81
  # @see https://dev.twitter.com/streaming/reference/get/statuses/sample
56
82
  # @see https://dev.twitter.com/streaming/overview/request-parameters
57
83
  # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
84
+ # @return [void]
58
85
  def sample(options = {}, &)
59
86
  request(:get, "https://stream.twitter.com:443/1.1/statuses/sample.json", options, &)
60
87
  end
61
88
 
62
89
  # Streams messages for a set of users
63
90
  #
91
+ # @api public
92
+ # @example
93
+ # client.site(7505382)
64
94
  # @see https://dev.twitter.com/streaming/reference/get/site
65
95
  # @see https://dev.twitter.com/streaming/sitestreams
66
96
  # @see https://dev.twitter.com/streaming/overview/request-parameters
@@ -71,6 +101,7 @@ module Twitter
71
101
  # @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.
72
102
  # @option options [String] :replies Specifies whether stall warnings should be delivered.
73
103
  # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
104
+ # @return [void]
74
105
  def site(*args, &)
75
106
  arguments = Arguments.new(args)
76
107
  user_ids = collect_user_ids(arguments)
@@ -79,6 +110,9 @@ module Twitter
79
110
 
80
111
  # Streams messages for a single user
81
112
  #
113
+ # @api public
114
+ # @example
115
+ # client.user
82
116
  # @see https://dev.twitter.com/streaming/reference/get/user
83
117
  # @see https://dev.twitter.com/streaming/userstreams
84
118
  # @see https://dev.twitter.com/streaming/overview/request-parameters
@@ -89,11 +123,17 @@ module Twitter
89
123
  # @option options [String] :track Includes additional Tweets matching the specified keywords. Phrases of keywords are specified by a comma-separated list.
90
124
  # @option options [String] :locations Includes additional Tweets falling within the specified bounding boxes.
91
125
  # @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
126
+ # @return [void]
92
127
  def user(options = {}, &)
93
128
  request(:get, "https://userstream.twitter.com:443/1.1/user.json", options, &)
94
129
  end
95
130
 
96
- # Set a Proc to be run when connection established.
131
+ # Set a Proc to be run when connection established
132
+ #
133
+ # @api public
134
+ # @example
135
+ # client.before_request { puts 'Connected!' }
136
+ # @return [Proc, Twitter::Streaming::Client]
97
137
  def before_request(&block)
98
138
  if block
99
139
  @before_request = block
@@ -105,16 +145,26 @@ module Twitter
105
145
  end
106
146
  end
107
147
 
148
+ # Closes the streaming connection
149
+ #
150
+ # @api public
151
+ # @example
152
+ # client.close
153
+ # @return [void]
108
154
  def close
109
155
  @connection.close
110
156
  end
111
157
 
112
- private
158
+ private
113
159
 
160
+ # Performs the streaming request
161
+ #
162
+ # @api private
163
+ # @return [void]
114
164
  def request(method, uri, params)
115
165
  before_request.call
116
166
  headers = Twitter::Headers.new(self, method, uri, params).request_headers
117
- request = HTTP::Request.new(verb: method, uri: "#{uri}?#{to_url_params(params)}", headers:, proxy:)
167
+ request = HTTP::Request.new(verb: method, uri: "#{uri}?#{to_url_params(params)}", headers:, proxy: proxy || {})
118
168
  response = Streaming::Response.new do |data|
119
169
  if item = Streaming::MessageParser.parse(data) # rubocop:disable Lint/AssignmentInCondition
120
170
  yield(item)
@@ -123,21 +173,23 @@ module Twitter
123
173
  @connection.stream(request, response)
124
174
  end
125
175
 
176
+ # Converts params to URL query string
177
+ #
178
+ # @api private
179
+ # @return [String]
126
180
  def to_url_params(params)
127
- uri = Addressable::URI.new
128
- uri.query_values = params
129
- uri.query
181
+ URI.encode_www_form(params)
130
182
  end
131
183
 
132
- # Takes a mixed array of Integers and Twitter::User objects and returns a
133
- # consistent array of Twitter user IDs.
184
+ # Takes a mixed array of Integers and Twitter::User objects
134
185
  #
186
+ # @api private
135
187
  # @param users [Array]
136
188
  # @return [Array<Integer>]
137
189
  def collect_user_ids(users)
138
190
  users.filter_map do |user|
139
191
  case user
140
- when Integer then user
192
+ when Integer then user
141
193
  when Twitter::User then user.id
142
194
  end
143
195
  end
@@ -3,23 +3,54 @@ require "resolv"
3
3
 
4
4
  module Twitter
5
5
  module Streaming
6
+ # Manages TCP/SSL connections for streaming
7
+ #
8
+ # @api public
6
9
  class Connection
10
+ # Returns the TCP socket class
11
+ #
12
+ # @api public
13
+ # @example
14
+ # connection.tcp_socket_class
15
+ # @return [Class]
16
+
17
+ # Returns the SSL socket class
18
+ #
19
+ # @api public
20
+ # @example
21
+ # connection.ssl_socket_class
22
+ # @return [Class]
7
23
  attr_reader :tcp_socket_class, :ssl_socket_class
8
24
 
25
+ # Initializes a new Connection object
26
+ #
27
+ # @api public
28
+ # @example
29
+ # connection = Twitter::Streaming::Connection.new
30
+ # @param options [Hash] A customizable set of options.
31
+ # @return [Twitter::Streaming::Connection]
9
32
  def initialize(options = {})
10
33
  @tcp_socket_class = options.fetch(:tcp_socket_class) { TCPSocket }
11
34
  @ssl_socket_class = options.fetch(:ssl_socket_class) { OpenSSL::SSL::SSLSocket }
12
- @using_ssl = options.fetch(:using_ssl, false)
13
- @write_pipe = nil
35
+ @using_ssl = options.fetch(:using_ssl, false)
14
36
  end
15
37
 
38
+ # Streams data from the connection
39
+ #
40
+ # @api public
41
+ # @example
42
+ # connection.stream(request, response)
43
+ # @param request [HTTP::Request] The HTTP request.
44
+ # @param response [Twitter::Streaming::Response] The response handler.
45
+ # @return [void]
16
46
  def stream(request, response) # rubocop:disable Metrics/MethodLength
17
47
  client = connect(request)
18
48
  request.stream(client)
19
49
  read_pipe, @write_pipe = IO.pipe
20
50
  loop do
21
51
  read_ios, _write_ios, _exception_ios = IO.select([read_pipe, client])
22
- case read_ios.first
52
+ first_io, = read_ios
53
+ case first_io
23
54
  when client
24
55
  response << client.readpartial(1024)
25
56
  when read_pipe
@@ -29,23 +60,40 @@ module Twitter
29
60
  client.close
30
61
  end
31
62
 
63
+ # Connects to the specified host and port
64
+ #
65
+ # @api public
66
+ # @example
67
+ # connection.connect(request)
68
+ # @param request [HTTP::Request] The HTTP request.
69
+ # @return [TCPSocket, OpenSSL::SSL::SSLSocket]
32
70
  def connect(request)
33
71
  client = new_tcp_socket(request.socket_host, request.socket_port)
34
72
  return client if !@using_ssl && request.using_proxy?
35
73
 
36
74
  client_context = OpenSSL::SSL::SSLContext.new
37
- ssl_client = @ssl_socket_class.new(client, client_context)
75
+ ssl_client = @ssl_socket_class.new(client, client_context)
38
76
  ssl_client.connect
39
77
  end
40
78
 
79
+ # Closes the connection
80
+ #
81
+ # @api public
82
+ # @example
83
+ # connection.close
84
+ # @return [Integer, nil]
41
85
  def close
42
86
  @write_pipe&.write("q")
43
87
  end
44
88
 
45
- private
89
+ private
46
90
 
91
+ # Creates a new TCP socket
92
+ #
93
+ # @api private
94
+ # @return [TCPSocket]
47
95
  def new_tcp_socket(host, port)
48
- @tcp_socket_class.new(Resolv.getaddress(host), port)
96
+ @tcp_socket_class.new(Resolv.getaddress(host), port) # steep:ignore UnknownConstant
49
97
  end
50
98
  end
51
99
  end
@@ -1,6 +1,14 @@
1
1
  module Twitter
2
2
  module Streaming
3
+ # Represents a deleted tweet from the streaming API
4
+ #
5
+ # @api public
3
6
  class DeletedTweet < Twitter::Identity
7
+ # Returns the user ID of the deleted tweet's author
8
+ #
9
+ # @api public
10
+ # @example
11
+ # deleted_tweet.user_id
4
12
  # @return [Integer]
5
13
  attr_reader :user_id
6
14
  end
@@ -1,19 +1,57 @@
1
1
  module Twitter
2
2
  module Streaming
3
+ # Represents a streaming event from the Twitter API
4
+ #
5
+ # @api public
3
6
  class Event
7
+ # Event names for list-related events
4
8
  LIST_EVENTS = %i[
5
9
  list_created list_destroyed list_updated list_member_added
6
10
  list_member_added list_member_removed list_user_subscribed
7
11
  list_user_subscribed list_user_unsubscribed list_user_unsubscribed
8
12
  ].freeze
9
13
 
14
+ # Event names for tweet-related events
10
15
  TWEET_EVENTS = %i[
11
16
  favorite unfavorite quoted_tweet
12
17
  ].freeze
13
18
 
19
+ # Returns the event name
20
+ #
21
+ # @api public
22
+ # @example
23
+ # event.name
24
+ # @return [Symbol]
25
+
26
+ # Returns the source user
27
+ #
28
+ # @api public
29
+ # @example
30
+ # event.source
31
+ # @return [Twitter::User]
32
+
33
+ # Returns the target user
34
+ #
35
+ # @api public
36
+ # @example
37
+ # event.target
38
+ # @return [Twitter::User]
39
+
40
+ # Returns the target object
41
+ #
42
+ # @api public
43
+ # @example
44
+ # event.target_object
45
+ # @return [Twitter::Tweet, Twitter::List, nil]
14
46
  attr_reader :name, :source, :target, :target_object
15
47
 
48
+ # Initializes a new Event object
49
+ #
50
+ # @api public
51
+ # @example
52
+ # Twitter::Streaming::Event.new(data)
16
53
  # @param data [Hash]
54
+ # @return [Twitter::Streaming::Event]
17
55
  def initialize(data)
18
56
  @name = data[:event].to_sym
19
57
  @source = Twitter::User.new(data[:source])
@@ -21,8 +59,12 @@ module Twitter
21
59
  @target_object = target_object_factory(@name, data[:target_object])
22
60
  end
23
61
 
24
- private
62
+ private
25
63
 
64
+ # Builds the target object based on event type
65
+ #
66
+ # @api private
67
+ # @return [Twitter::Tweet, Twitter::List, nil]
26
68
  def target_object_factory(event_name, data)
27
69
  if LIST_EVENTS.include?(event_name)
28
70
  Twitter::List.new(data)
@@ -1,5 +1,6 @@
1
1
  module Twitter
2
2
  module Streaming
3
+ # Represents a list of friend IDs from the streaming API
3
4
  class FriendList < Array
4
5
  end
5
6
  end
@@ -7,20 +7,30 @@ require "twitter/tweet"
7
7
 
8
8
  module Twitter
9
9
  module Streaming
10
+ # Parses streaming messages from the Twitter API
11
+ #
12
+ # @api public
10
13
  class MessageParser
14
+ # Parses streaming data into appropriate objects
15
+ #
16
+ # @api public
17
+ # @example
18
+ # MessageParser.parse(data)
19
+ # @param data [Hash] The streaming data to parse.
20
+ # @return [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning, nil]
11
21
  def self.parse(data) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
12
- if data[:id]
22
+ if data.key?(:id)
13
23
  Tweet.new(data)
14
- elsif data[:event]
24
+ elsif data.key?(:event)
15
25
  Event.new(data)
16
- elsif data[:direct_message]
17
- DirectMessage.new(data[:direct_message])
18
- elsif data[:friends]
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])
26
+ elsif data.key?(:direct_message)
27
+ DirectMessage.new(data.fetch(:direct_message))
28
+ elsif data.key?(:friends)
29
+ FriendList.new(data.fetch(:friends))
30
+ elsif data.key?(:delete) && data.fetch(:delete).key?(:status)
31
+ DeletedTweet.new(data.fetch(:delete).fetch(:status))
32
+ elsif data.key?(:warning)
33
+ StallWarning.new(data.fetch(:warning))
24
34
  end
25
35
  end
26
36
  end
@@ -2,32 +2,58 @@ require "buftok"
2
2
  require "http"
3
3
  require "json"
4
4
  require "twitter/error"
5
- require "llhttp"
6
5
 
7
6
  module Twitter
8
7
  module Streaming
8
+ # Handles streaming response parsing
9
+ #
10
+ # @api public
9
11
  class Response
10
12
  # Initializes a new Response object
11
13
  #
14
+ # @api public
15
+ # @example
16
+ # response = Twitter::Streaming::Response.new { |data| puts data }
12
17
  # @return [Twitter::Streaming::Response]
13
18
  def initialize(&block)
14
- @block = block
15
- @parser = LLHttp::Parser.new(self, type: :response)
16
- @tokenizer = BufferedTokenizer.new("\r\n")
19
+ @block = block
20
+ @parser = LLHttp::Parser.new(self, type: :response)
21
+ @tokenizer = BufferedTokenizer.new("\r\n") # steep:ignore UnknownConstant
17
22
  end
18
23
 
24
+ # Appends data to the parser
25
+ #
26
+ # @api public
27
+ # @example
28
+ # response << data
29
+ # @param data [String] The data to append.
30
+ # @return [void]
19
31
  def <<(data)
20
32
  @parser << data
21
33
  end
22
34
 
35
+ # Handles body data from the response
36
+ #
37
+ # @api public
38
+ # @example
39
+ # response.on_body(data)
40
+ # @param data [String] The body data.
41
+ # @return [void]
23
42
  def on_body(data)
24
43
  @tokenizer.extract(data).each do |line|
25
44
  next if line.empty?
26
45
 
27
- @block.call(JSON.parse(line, symbolize_names: true))
46
+ @block.call(JSON.parse(line, symbolize_names: true)) # steep:ignore UnknownConstant
28
47
  end
29
48
  end
30
49
 
50
+ # Handles status code from the response
51
+ #
52
+ # @api public
53
+ # @example
54
+ # response.on_status(200)
55
+ # @param _status [Integer] The status code.
56
+ # @return [void]
31
57
  def on_status(_status)
32
58
  error = Twitter::Error::ERRORS[@parser.status_code]
33
59
  raise error if error
@@ -1,6 +1,29 @@
1
1
  module Twitter
2
2
  module Streaming
3
+ # Represents a Twitter streaming stall warning
4
+ #
5
+ # @api public
3
6
  class StallWarning < Twitter::Base
7
+ # Returns the warning code
8
+ #
9
+ # @api public
10
+ # @example
11
+ # stall_warning.code
12
+ # @return [String]
13
+
14
+ # Returns the warning message
15
+ #
16
+ # @api public
17
+ # @example
18
+ # stall_warning.message
19
+ # @return [String]
20
+
21
+ # Returns the percent full value
22
+ #
23
+ # @api public
24
+ # @example
25
+ # stall_warning.percent_full
26
+ # @return [Integer]
4
27
  attr_reader :code, :message, :percent_full
5
28
  end
6
29
  end
@@ -3,15 +3,39 @@ require "memoizable"
3
3
  require "twitter/base"
4
4
 
5
5
  module Twitter
6
- class Suggestion < Twitter::Base
6
+ # Represents a Twitter user suggestion category
7
+ class Suggestion < Base
7
8
  include Equalizer.new(:slug)
8
9
  include Memoizable
9
10
 
11
+ # The number of users in this category
12
+ #
13
+ # @api public
14
+ # @example
15
+ # suggestion.size
10
16
  # @return [Integer]
11
17
  attr_reader :size
18
+
19
+ # The name of the suggestion category
20
+ #
21
+ # @api public
22
+ # @example
23
+ # suggestion.name
24
+ # @return [String]
25
+
26
+ # The slug of the suggestion category
27
+ #
28
+ # @api public
29
+ # @example
30
+ # suggestion.slug
12
31
  # @return [String]
13
32
  attr_reader :name, :slug
14
33
 
34
+ # Returns the users in this suggestion category
35
+ #
36
+ # @api public
37
+ # @example
38
+ # suggestion.users
15
39
  # @return [Array<Twitter::User>]
16
40
  def users
17
41
  @attrs.fetch(:users, []).collect do |user|
@@ -1,7 +1,8 @@
1
1
  require "twitter/basic_user"
2
2
 
3
3
  module Twitter
4
- class TargetUser < Twitter::BasicUser
4
+ # Represents the target user in a relationship
5
+ class TargetUser < BasicUser
5
6
  predicate_attr_reader :followed_by
6
7
  end
7
8
  end
data/lib/twitter/trend.rb CHANGED
@@ -2,9 +2,37 @@ require "equalizer"
2
2
  require "twitter/base"
3
3
 
4
4
  module Twitter
5
- class Trend < Twitter::Base
5
+ # Represents a Twitter trending topic
6
+ class Trend < Base
6
7
  include Equalizer.new(:name)
8
+
9
+ # Events associated with this trend
10
+ #
11
+ # @api public
12
+ # @example
13
+ # trend.events
14
+ # @return [String]
15
+
16
+ # The name of the trend
17
+ #
18
+ # @api public
19
+ # @example
20
+ # trend.name
7
21
  # @return [String]
22
+
23
+ # The search query for this trend
24
+ #
25
+ # @api public
26
+ # @example
27
+ # trend.query
28
+ # @return [String]
29
+
30
+ # The tweet volume for this trend
31
+ #
32
+ # @api public
33
+ # @example
34
+ # trend.tweet_volume
35
+ # @return [Integer]
8
36
  attr_reader :events, :name, :query, :tweet_volume
9
37
 
10
38
  predicate_attr_reader :promoted_content