twitter 6.2.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -7
  3. data/LICENSE.md +1 -1
  4. data/README.md +9 -12
  5. data/lib/twitter.rb +5 -0
  6. data/lib/twitter/client.rb +5 -5
  7. data/lib/twitter/creatable.rb +5 -1
  8. data/lib/twitter/cursor.rb +12 -2
  9. data/lib/twitter/direct_message.rb +2 -0
  10. data/lib/twitter/direct_message_event.rb +44 -0
  11. data/lib/twitter/direct_messages/welcome_message.rb +17 -0
  12. data/lib/twitter/direct_messages/welcome_message_rule.rb +12 -0
  13. data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +36 -0
  14. data/lib/twitter/direct_messages/welcome_message_wrapper.rb +42 -0
  15. data/lib/twitter/enumerable.rb +14 -3
  16. data/lib/twitter/error.rb +48 -6
  17. data/lib/twitter/null_object.rb +15 -1
  18. data/lib/twitter/premium_search_results.rb +67 -0
  19. data/lib/twitter/profile.rb +2 -2
  20. data/lib/twitter/rate_limit.rb +2 -2
  21. data/lib/twitter/rest/account_activity.rb +99 -0
  22. data/lib/twitter/rest/api.rb +6 -0
  23. data/lib/twitter/rest/direct_messages.rb +131 -42
  24. data/lib/twitter/rest/direct_messages/welcome_messages.rb +90 -0
  25. data/lib/twitter/rest/favorites.rb +2 -2
  26. data/lib/twitter/rest/lists.rb +1 -0
  27. data/lib/twitter/rest/premium_search.rb +34 -0
  28. data/lib/twitter/rest/request.rb +39 -13
  29. data/lib/twitter/rest/search.rb +4 -3
  30. data/lib/twitter/rest/timelines.rb +1 -0
  31. data/lib/twitter/rest/tweets.rb +2 -31
  32. data/lib/twitter/rest/upload_utils.rb +68 -0
  33. data/lib/twitter/rest/utils.rb +24 -7
  34. data/lib/twitter/search_results.rb +4 -3
  35. data/lib/twitter/streaming/client.rb +5 -1
  36. data/lib/twitter/streaming/connection.rb +16 -3
  37. data/lib/twitter/streaming/message_parser.rb +1 -1
  38. data/lib/twitter/streaming/response.rb +1 -0
  39. data/lib/twitter/tweet.rb +10 -1
  40. data/lib/twitter/utils.rb +4 -2
  41. data/lib/twitter/version.rb +2 -2
  42. data/twitter.gemspec +3 -4
  43. metadata +16 -21
@@ -9,7 +9,7 @@ module Twitter
9
9
  include Twitter::Enumerable
10
10
  include Twitter::Utils
11
11
  # @return [Hash]
12
- attr_reader :attrs
12
+ attr_reader :attrs, :rate_limit
13
13
  alias to_h attrs
14
14
  alias to_hash to_h
15
15
 
@@ -48,8 +48,9 @@ module Twitter
48
48
 
49
49
  # @return [Hash]
50
50
  def fetch_next_page
51
- response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(next_page)).perform
52
- self.attrs = response
51
+ response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(next_page))
52
+ self.attrs = response.perform
53
+ @rate_limit = response.rate_limit
53
54
  end
54
55
 
55
56
  # @param attrs [Hash]
@@ -105,6 +105,10 @@ module Twitter
105
105
  end
106
106
  end
107
107
 
108
+ def close
109
+ @connection.close
110
+ end
111
+
108
112
  private
109
113
 
110
114
  def request(method, uri, params)
@@ -112,7 +116,7 @@ module Twitter
112
116
  headers = Twitter::Headers.new(self, method, uri, params).request_headers
113
117
  request = HTTP::Request.new(verb: method, uri: uri + '?' + to_url_params(params), headers: headers, proxy: proxy)
114
118
  response = Streaming::Response.new do |data|
115
- if item = Streaming::MessageParser.parse(data) # rubocop:disable AssignmentInCondition
119
+ if item = Streaming::MessageParser.parse(data) # rubocop:disable Lint/AssignmentInCondition
116
120
  yield(item)
117
121
  end
118
122
  end
@@ -11,14 +11,23 @@ module Twitter
11
11
  @tcp_socket_class = options.fetch(:tcp_socket_class) { TCPSocket }
12
12
  @ssl_socket_class = options.fetch(:ssl_socket_class) { OpenSSL::SSL::SSLSocket }
13
13
  @using_ssl = options.fetch(:using_ssl) { false }
14
+ @write_pipe = nil
14
15
  end
15
16
 
16
- def stream(request, response)
17
+ def stream(request, response) # rubocop:disable Metrics/MethodLength
17
18
  client = connect(request)
18
19
  request.stream(client)
19
- while body = client.readpartial(1024) # rubocop:disable AssignmentInCondition
20
- response << body
20
+ read_pipe, @write_pipe = IO.pipe
21
+ loop do
22
+ read_ios, _write_ios, _exception_ios = IO.select([read_pipe, client])
23
+ case read_ios.first
24
+ when client
25
+ response << client.readpartial(1024)
26
+ when read_pipe
27
+ break
28
+ end
21
29
  end
30
+ client.close
22
31
  end
23
32
 
24
33
  def connect(request)
@@ -30,6 +39,10 @@ module Twitter
30
39
  ssl_client.connect
31
40
  end
32
41
 
42
+ def close
43
+ @write_pipe&.write('q')
44
+ end
45
+
33
46
  private
34
47
 
35
48
  def new_tcp_socket(host, port)
@@ -8,7 +8,7 @@ require 'twitter/tweet'
8
8
  module Twitter
9
9
  module Streaming
10
10
  class MessageParser
11
- def self.parse(data) # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
11
+ def self.parse(data) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
12
12
  if data[:id]
13
13
  Tweet.new(data)
14
14
  elsif data[:event]
@@ -27,6 +27,7 @@ module Twitter
27
27
  def on_body(data)
28
28
  @tokenizer.extract(data).each do |line|
29
29
  next if line.empty?
30
+
30
31
  @block.call(JSON.parse(line, symbolize_names: true))
31
32
  end
32
33
  end
@@ -10,7 +10,7 @@ module Twitter
10
10
  attr_reader :filter_level, :in_reply_to_screen_name, :lang, :source, :text
11
11
  # @return [Integer]
12
12
  attr_reader :favorite_count, :in_reply_to_status_id, :in_reply_to_user_id,
13
- :retweet_count
13
+ :quote_count, :reply_count, :retweet_count
14
14
  alias in_reply_to_tweet_id in_reply_to_status_id
15
15
  alias reply? in_reply_to_user_id?
16
16
  object_attr_reader :GeoFactory, :geo
@@ -29,6 +29,15 @@ module Twitter
29
29
  predicate_attr_reader :favorited, :possibly_sensitive, :retweeted,
30
30
  :truncated
31
31
 
32
+ # Initializes a new object
33
+ #
34
+ # @param attrs [Hash]
35
+ # @return [Twitter::Tweet]
36
+ def initialize(attrs = {})
37
+ attrs[:text] = attrs[:full_text] if attrs[:text].nil? && !attrs[:full_text].nil?
38
+ super
39
+ end
40
+
32
41
  # @note May be > 280 characters.
33
42
  # @return [String]
34
43
  def full_text
@@ -7,9 +7,10 @@ module Twitter
7
7
  #
8
8
  # @param enumerable [Enumerable]
9
9
  # @return [Array, Enumerator]
10
- def flat_pmap(enumerable)
10
+ def flat_pmap(enumerable, &block)
11
11
  return to_enum(:flat_pmap, enumerable) unless block_given?
12
- pmap(enumerable, &Proc.new).flatten(1)
12
+
13
+ pmap(enumerable, &block).flatten(1)
13
14
  end
14
15
 
15
16
  # Returns a new array with the results of running block once for every element in enumerable.
@@ -19,6 +20,7 @@ module Twitter
19
20
  # @return [Array, Enumerator]
20
21
  def pmap(enumerable)
21
22
  return to_enum(:pmap, enumerable) unless block_given?
23
+
22
24
  if enumerable.count == 1
23
25
  enumerable.collect { |object| yield(object) }
24
26
  else
@@ -4,12 +4,12 @@ module Twitter
4
4
 
5
5
  # @return [Integer]
6
6
  def major
7
- 6
7
+ 7
8
8
  end
9
9
 
10
10
  # @return [Integer]
11
11
  def minor
12
- 2
12
+ 0
13
13
  end
14
14
 
15
15
  # @return [Integer]
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'twitter/version'
4
4
 
@@ -6,14 +6,13 @@ Gem::Specification.new do |spec|
6
6
  spec.add_dependency 'addressable', '~> 2.3'
7
7
  spec.add_dependency 'buftok', '~> 0.2.0'
8
8
  spec.add_dependency 'equalizer', '~> 0.0.11'
9
- spec.add_dependency 'http', '~> 3.0'
9
+ spec.add_dependency 'http', '~> 4.0'
10
10
  spec.add_dependency 'http-form_data', '~> 2.0'
11
11
  spec.add_dependency 'http_parser.rb', '~> 0.6.0'
12
12
  spec.add_dependency 'memoizable', '~> 0.4.0'
13
13
  spec.add_dependency 'multipart-post', '~> 2.0'
14
14
  spec.add_dependency 'naught', '~> 1.0'
15
15
  spec.add_dependency 'simple_oauth', '~> 0.3.0'
16
- spec.add_development_dependency 'bundler', '~> 1.0'
17
16
  spec.authors = ['Erik Michaels-Ober', 'John Nunemaker', 'Wynn Netherland', 'Steve Richert', 'Steve Agalloco']
18
17
  spec.description = 'A Ruby interface to the Twitter API.'
19
18
  spec.email = %w[sferik@gmail.com]
@@ -22,7 +21,7 @@ Gem::Specification.new do |spec|
22
21
  spec.licenses = %w[MIT]
23
22
  spec.name = 'twitter'
24
23
  spec.require_paths = %w[lib]
25
- spec.required_ruby_version = '>= 1.9.3'
24
+ spec.required_ruby_version = '>= 2.3'
26
25
  spec.summary = spec.description
27
26
  spec.version = Twitter::Version
28
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.0
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-11-08 00:00:00.000000000 Z
15
+ date: 2020-02-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: addressable
@@ -62,14 +62,14 @@ dependencies:
62
62
  requirements:
63
63
  - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: '3.0'
65
+ version: '4.0'
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '3.0'
72
+ version: '4.0'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: http-form_data
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -154,20 +154,6 @@ dependencies:
154
154
  - - "~>"
155
155
  - !ruby/object:Gem::Version
156
156
  version: 0.3.0
157
- - !ruby/object:Gem::Dependency
158
- name: bundler
159
- requirement: !ruby/object:Gem::Requirement
160
- requirements:
161
- - - "~>"
162
- - !ruby/object:Gem::Version
163
- version: '1.0'
164
- type: :development
165
- prerelease: false
166
- version_requirements: !ruby/object:Gem::Requirement
167
- requirements:
168
- - - "~>"
169
- - !ruby/object:Gem::Version
170
- version: '1.0'
171
157
  description: A Ruby interface to the Twitter API.
172
158
  email:
173
159
  - sferik@gmail.com
@@ -189,6 +175,11 @@ files:
189
175
  - lib/twitter/creatable.rb
190
176
  - lib/twitter/cursor.rb
191
177
  - lib/twitter/direct_message.rb
178
+ - lib/twitter/direct_message_event.rb
179
+ - lib/twitter/direct_messages/welcome_message.rb
180
+ - lib/twitter/direct_messages/welcome_message_rule.rb
181
+ - lib/twitter/direct_messages/welcome_message_rule_wrapper.rb
182
+ - lib/twitter/direct_messages/welcome_message_wrapper.rb
192
183
  - lib/twitter/entities.rb
193
184
  - lib/twitter/entity.rb
194
185
  - lib/twitter/entity/hashtag.rb
@@ -216,19 +207,23 @@ files:
216
207
  - lib/twitter/null_object.rb
217
208
  - lib/twitter/oembed.rb
218
209
  - lib/twitter/place.rb
210
+ - lib/twitter/premium_search_results.rb
219
211
  - lib/twitter/profile.rb
220
212
  - lib/twitter/profile_banner.rb
221
213
  - lib/twitter/rate_limit.rb
222
214
  - lib/twitter/relationship.rb
215
+ - lib/twitter/rest/account_activity.rb
223
216
  - lib/twitter/rest/api.rb
224
217
  - lib/twitter/rest/client.rb
225
218
  - lib/twitter/rest/direct_messages.rb
219
+ - lib/twitter/rest/direct_messages/welcome_messages.rb
226
220
  - lib/twitter/rest/favorites.rb
227
221
  - lib/twitter/rest/friends_and_followers.rb
228
222
  - lib/twitter/rest/help.rb
229
223
  - lib/twitter/rest/lists.rb
230
224
  - lib/twitter/rest/oauth.rb
231
225
  - lib/twitter/rest/places_and_geo.rb
226
+ - lib/twitter/rest/premium_search.rb
232
227
  - lib/twitter/rest/request.rb
233
228
  - lib/twitter/rest/saved_searches.rb
234
229
  - lib/twitter/rest/search.rb
@@ -238,6 +233,7 @@ files:
238
233
  - lib/twitter/rest/trends.rb
239
234
  - lib/twitter/rest/tweets.rb
240
235
  - lib/twitter/rest/undocumented.rb
236
+ - lib/twitter/rest/upload_utils.rb
241
237
  - lib/twitter/rest/users.rb
242
238
  - lib/twitter/rest/utils.rb
243
239
  - lib/twitter/saved_search.rb
@@ -275,15 +271,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
275
271
  requirements:
276
272
  - - ">="
277
273
  - !ruby/object:Gem::Version
278
- version: 1.9.3
274
+ version: '2.3'
279
275
  required_rubygems_version: !ruby/object:Gem::Requirement
280
276
  requirements:
281
277
  - - ">="
282
278
  - !ruby/object:Gem::Version
283
279
  version: '0'
284
280
  requirements: []
285
- rubyforge_project:
286
- rubygems_version: 2.7.2
281
+ rubygems_version: 3.1.2
287
282
  signing_key:
288
283
  specification_version: 4
289
284
  summary: A Ruby interface to the Twitter API.