Sha256: bd317eafa6853d3c4c81252cb2be72fad77cc4e6ccde3d125545def95978b041

Contents?: true

Size: 920 Bytes

Versions: 1

Compression:

Stored size: 920 Bytes

Contents

require "twitter"
require "fluent/plugin/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 :access_token, :string, secret: true
  config_param :access_token_secret, :string, secret: true

  def initialize
    super
  end

  def configure(conf)
    super

    @twitter = Twitter::REST::Client.new(
      consumer_key: @consumer_key,
      consumer_secret: @consumer_secret,
      access_token: @access_token,
      access_token_secret: @access_token_secret
    )
  end

  def process(tag, es)
    es.each do |_time, record|
      tweet(record['message'])
    end
  end

  def tweet(message)
    begin
      @twitter.update(message)
    rescue Twitter::Error => e
      log.error("Twitter Error: #{e.message}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-twitter-0.6.1 lib/fluent/plugin/out_twitter.rb