logstash-input-twitter 2.1.0 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2c82687f3ddd3386c346f11cead1cd3a6bbc485
4
- data.tar.gz: 8ba300f93af4f14852047a19f1187fc72f0cda80
3
+ metadata.gz: ded0fb06a53cdd6b628e29f8adcd942c7375da1e
4
+ data.tar.gz: bc9905695444a89e7d347250f6d91b84d860afec
5
5
  SHA512:
6
- metadata.gz: b5f37dde1ba6376d57f4d4064b7f9ddcadaa7ada41449f6abfd80dc9a51b852981bbee2fc9566d38ad3bdc0badba1689ec6520bc801d90353fc55e22a1569fe4
7
- data.tar.gz: f7bd667faadaa77c6e41f53785dc807e2764ae20c65276023ca7297d1108cf6479326501d248e778a463df89372db55a5d2dc648f3ab41795fe56c633e3f62cd
6
+ metadata.gz: 11ba55f9584d1bbd0d81b739b7c2a30b16f822204d72037c7b23fa8c90ad15853d9eb80dc65cf0c8d1637522b442827f7642ead1ca05d917ba30680be67301f9
7
+ data.tar.gz: dd86f9b3956e406e35fadd8dd7242550e0297d398ec576055547ef1171c334f2c778036b1397a5271770df0c0b739a08f87eea03ffbd228d1986d041b64aa4b4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.2.0
2
+ - Upgraded the twitter gem to the last version available, 5.15.0
3
+ - Add proxy support, Fixes #7.
4
+
1
5
  ## 2.1.0
2
6
  - Add an option to fetch data from the sample endpoint.
3
7
  - Add hashtags, symbols and user_mentions as data for the non extended tweet event.
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+ require 'twitter/streaming/connection'
3
+ require 'twitter/streaming/response'
4
+ require 'twitter/streaming/message_parser'
5
+
6
+ module LogStash
7
+ module Inputs
8
+ class TwitterPatches
9
+
10
+ def self.patch
11
+ verify_version
12
+ patch_json
13
+ patch_connection_stream
14
+ patch_request
15
+ end
16
+
17
+ private
18
+
19
+ def self.verify_version
20
+ raise("Incompatible Twitter gem version and the LogStash::Json.load") unless ::Twitter::Version.to_s == "5.15.0"
21
+ end
22
+
23
+ def self.patch_connection_stream
24
+ ::Twitter::Streaming::Connection.class_eval do
25
+ def stream(request, response)
26
+ socket = @tcp_socket_class.new(Resolv.getaddress(request.socket_host), request.socket_port)
27
+ socket = ssl_stream(socket) if !request.using_proxy?
28
+
29
+ request.stream(socket)
30
+ while body = socket.readpartial(1024) # rubocop:disable AssignmentInCondition
31
+ response << body
32
+ end
33
+ end
34
+
35
+ def ssl_stream(client)
36
+ client_context = OpenSSL::SSL::SSLContext.new
37
+ ssl_client = @ssl_socket_class.new(client, client_context)
38
+ ssl_client.connect
39
+ end
40
+
41
+ def normalized_port(scheme)
42
+ HTTP::URI.port_mapping[scheme]
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.patch_request
48
+ ::Twitter::Streaming::Client.class_eval do
49
+ def request(method, uri, params)
50
+ before_request.call
51
+ headers = ::Twitter::Headers.new(self, method, uri, params).request_headers
52
+ request = ::HTTP::Request.new(method, uri + '?' + to_url_params(params), headers, proxy)
53
+ response = ::Twitter::Streaming::Response.new do |data|
54
+ if item = ::Twitter::Streaming::MessageParser.parse(data) # rubocop:disable AssignmentInCondition
55
+ yield(item)
56
+ end
57
+ end
58
+ @connection.stream(request, response)
59
+ end
60
+ end
61
+ end
62
+
63
+ def self.patch_json
64
+ ::Twitter::Streaming::Response.module_eval do
65
+ def on_body(data)
66
+ @tokenizer.extract(data).each do |line|
67
+ next if line.empty?
68
+ begin
69
+ @block.call(LogStash::Json.load(line, :symbolize_keys => true))
70
+ rescue LogStash::Json::ParserError
71
+ # silently ignore json parsing errors
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -5,6 +5,7 @@ require "logstash/timestamp"
5
5
  require "logstash/util"
6
6
  require "logstash/json"
7
7
  require "stud/interval"
8
+ require "logstash/inputs/twitter/patches"
8
9
 
9
10
  # Ingest events from the Twitter Streaming API.
10
11
  class LogStash::Inputs::Twitter < LogStash::Inputs::Base
@@ -88,6 +89,15 @@ class LogStash::Inputs::Twitter < LogStash::Inputs::Base
88
89
  # Lets you ingore the retweets coming out of the Twitter API. Default => false
89
90
  config :ignore_retweets, :validate => :boolean, :default => false
90
91
 
92
+ # When to use a proxy to handle the connections
93
+ config :use_proxy, :validate => :boolean, :default => false
94
+
95
+ # Location of the proxy, by default the same machine as the one running this LS instance
96
+ config :proxy_address, :validate => :string, :default => "127.0.0.1"
97
+
98
+ # Port where the proxy is listening, by default 3128 (squid)
99
+ config :proxy_port, :validate => :number, :default => 3128
100
+
91
101
  def register
92
102
  require "twitter"
93
103
 
@@ -98,20 +108,8 @@ class LogStash::Inputs::Twitter < LogStash::Inputs::Base
98
108
  # monkey patch twitter gem to ignore json parsing error.
99
109
  # at the same time, use our own json parser
100
110
  # this has been tested with a specific gem version, raise if not the same
101
- raise("Incompatible Twitter gem version and the LogStash::Json.load") unless Twitter::Version.to_s == "5.14.0"
102
-
103
- Twitter::Streaming::Response.module_eval do
104
- def on_body(data)
105
- @tokenizer.extract(data).each do |line|
106
- next if line.empty?
107
- begin
108
- @block.call(LogStash::Json.load(line, :symbolize_keys => true))
109
- rescue LogStash::Json::ParserError
110
- # silently ignore json parsing errors
111
- end
112
- end
113
- end
114
- end
111
+
112
+ LogStash::Inputs::TwitterPatches.patch
115
113
 
116
114
  @rest_client = Twitter::REST::Client.new { |c| configure(c) }
117
115
  @stream_client = Twitter::Streaming::Client.new { |c| configure(c) }
@@ -207,6 +205,12 @@ class LogStash::Inputs::Twitter < LogStash::Inputs::Base
207
205
  c.consumer_secret = @consumer_secret.value
208
206
  c.access_token = @oauth_token
209
207
  c.access_token_secret = @oauth_token_secret.value
208
+ if @use_proxy
209
+ c.proxy = {
210
+ proxy_address: @proxy_address,
211
+ proxy_port: @proxy_port,
212
+ }
213
+ end
210
214
  end
211
215
 
212
216
  def build_options
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-twitter'
4
- s.version = '2.1.0'
4
+ s.version = '2.2.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Read events from the twitter streaming api."
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
24
- s.add_runtime_dependency 'twitter', '5.14.0'
24
+ s.add_runtime_dependency 'twitter', '5.15.0'
25
25
  s.add_runtime_dependency 'stud', '>= 0.0.22', '< 0.1'
26
26
 
27
27
  s.add_development_dependency 'logstash-devutils'
@@ -188,6 +188,5 @@ describe LogStash::Inputs::Twitter do
188
188
  end
189
189
 
190
190
  end
191
-
192
191
  end
193
192
  end
@@ -71,5 +71,36 @@ describe LogStash::Inputs::Twitter do
71
71
  end
72
72
 
73
73
  end
74
+
75
+ context "when using a proxy" do
76
+ let(:config) do
77
+ <<-CONFIG
78
+ input {
79
+ twitter {
80
+ consumer_key => '#{ENV['TWITTER_CONSUMER_KEY']}'
81
+ consumer_secret => '#{ENV['TWITTER_CONSUMER_SECRET']}'
82
+ keywords => [ "London", "Barcelona" ]
83
+ oauth_token => '#{ENV['TWITTER_OAUTH_TOKEN']}'
84
+ oauth_token_secret => '#{ENV['TWITTER_OAUTH_TOKEN_SECRET']}'
85
+ full_tweet => true
86
+ use_proxy => true
87
+ proxy_address => '127.0.0.1'
88
+ proxy_port => 8123
89
+ }
90
+ }
91
+ CONFIG
92
+ end
93
+
94
+ let(:events) do
95
+ input(config) do |pipeline, queue|
96
+ 3.times.collect { queue.pop }
97
+ end
98
+ end
99
+
100
+ it "receive a list of events from the twitter stream" do
101
+ expect(events.count).to eq(3)
102
+ end
103
+ end
74
104
  end
105
+
75
106
  end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,6 @@ class MockClient
6
6
  def filter(options)
7
7
  loop { yield }
8
8
  end
9
-
10
9
  alias_method :sample, :filter
11
10
  end
12
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -36,12 +36,12 @@ dependencies:
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 5.14.0
39
+ version: 5.15.0
40
40
  requirement: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - '='
43
43
  - !ruby/object:Gem::Version
44
- version: 5.14.0
44
+ version: 5.15.0
45
45
  prerelease: false
46
46
  type: :runtime
47
47
  - !ruby/object:Gem::Dependency
@@ -98,17 +98,18 @@ executables: []
98
98
  extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
- - lib/logstash/inputs/twitter.rb
102
- - spec/spec_helper.rb
103
- - spec/inputs/twitter_spec.rb
104
- - spec/integration/twitter_spec.rb
105
- - logstash-input-twitter.gemspec
106
101
  - CHANGELOG.md
107
- - README.md
108
102
  - CONTRIBUTORS
109
103
  - Gemfile
110
104
  - LICENSE
111
105
  - NOTICE.TXT
106
+ - README.md
107
+ - lib/logstash/inputs/twitter.rb
108
+ - lib/logstash/inputs/twitter/patches.rb
109
+ - logstash-input-twitter.gemspec
110
+ - spec/inputs/twitter_spec.rb
111
+ - spec/integration/twitter_spec.rb
112
+ - spec/spec_helper.rb
112
113
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
113
114
  licenses:
114
115
  - Apache License (2.0)
@@ -131,11 +132,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  version: '0'
132
133
  requirements: []
133
134
  rubyforge_project:
134
- rubygems_version: 2.1.9
135
+ rubygems_version: 2.4.8
135
136
  signing_key:
136
137
  specification_version: 4
137
138
  summary: Read events from the twitter streaming api.
138
139
  test_files:
139
- - spec/spec_helper.rb
140
140
  - spec/inputs/twitter_spec.rb
141
141
  - spec/integration/twitter_spec.rb
142
+ - spec/spec_helper.rb