class Fluent::TwittersearchInput
Attributes
twitter[R]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_twittersearch.rb, line 19 def initialize super require "twitter" end
Public Instance Methods
configure(config)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_twittersearch.rb, line 24 def configure(config) super Twitter.configure do |cnf| cnf.consumer_key = @consumer_key cnf.consumer_secret = @consumer_secret end @twitter = Twitter::Client.new( :oauth_token => @oauth_token, :oauth_token_secret => @oauth_token_secret ) raise Fluent::ConfigError.new if @keyword.nil? and @hashtag.nil? end
run()
click to toggle source
# File lib/fluent/plugin/in_twittersearch.rb, line 64 def run loop do search.each do |tweet| Engine.emit @tag,Engine.now,tweet end sleep @run_interval end end
search()
click to toggle source
# File lib/fluent/plugin/in_twittersearch.rb, line 42 def search tweets = [] @twitter.search(@keyword.nil? ? "##{@hashtag}" : @keyword, :count => @count, :result_type => @result_type).results.reverse.map do |result| tweet = Hash.new [:id,:retweet_count,:favorite_count].each do |key| tweet.store(key.to_s, result[key].to_s) end [:screen_name,:profile_image_url,:profile_image_url_https].each do |key| tweet.store(key.to_s, result.user[key].to_s) end tweet.store('created_at', result[:created_at].strftime("%Y-%m-%d %H:%M:%S")) tweet.store('user_id', result.user[:id]) tweet.store('text',result.text.force_encoding('utf-8')) tweet.store('name',result.user.name.force_encoding('utf-8')) tweets << tweet end tweets end
shutdown()
click to toggle source
# File lib/fluent/plugin/in_twittersearch.rb, line 73 def shutdown Thread.kill(@thread) end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_twittersearch.rb, line 37 def start super @thread = Thread.new(&method(:run)) end