lib/fluent/plugin/out_twitter.rb in fluent-plugin-twitter-0.6.0 vs lib/fluent/plugin/out_twitter.rb in fluent-plugin-twitter-0.6.1
- old
+ new
@@ -1,51 +1,40 @@
-require "fluent/output"
+require "twitter"
+require "fluent/plugin/output"
-class Fluent::TwitterOutput < Fluent::Output
+class Fluent::Plugin::TwitterOutput < Fluent::Plugin::Output
Fluent::Plugin.register_output('twitter', self)
- config_param :consumer_key, :string, :secret => true
- config_param :consumer_secret, :string, :secret => true
- config_param :oauth_token, :string, :default => nil, :secret => true
- config_param :oauth_token_secret, :string, :default => nil, :secret => true
- config_param :access_token, :string, :default => nil, :secret => true
- config_param :access_token_secret, :string, :default => nil, :secret => true
+ config_param :consumer_key, :string, secret: true
+ config_param :consumer_secret, :string, secret: true
+ config_param :access_token, :string, secret: true
+ config_param :access_token_secret, :string, secret: true
def initialize
super
- require 'twitter'
end
def configure(conf)
super
- @access_token = @access_token || @oauth_token
- @access_token_secret = @access_token_secret || @oauth_token_secret
- if !@consumer_key or !@consumer_secret or !@access_token or !@access_token_secret
- raise Fluent::ConfigError, "missing values in consumer_key or consumer_secret or oauth_token or oauth_token_secret"
- end
-
@twitter = Twitter::REST::Client.new(
- :consumer_key => @consumer_key,
- :consumer_secret => @consumer_secret,
- :access_token => @access_token,
- :access_token_secret => @access_token_secret
+ consumer_key: @consumer_key,
+ consumer_secret: @consumer_secret,
+ access_token: @access_token,
+ access_token_secret: @access_token_secret
)
end
- def emit(tag, es, chain)
- es.each do |time,record|
+ def process(tag, es)
+ es.each do |_time, record|
tweet(record['message'])
end
-
- chain.next
end
def tweet(message)
begin
@twitter.update(message)
rescue Twitter::Error => e
- $log.error("Twitter Error: #{e.message}")
+ log.error("Twitter Error: #{e.message}")
end
end
end
-