class Fluent::TumblrOutput
Attributes
tumblr_client[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_tumblr.rb, line 11 def initialize super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_tumblr.rb, line 33 def configure(conf) super @tags = ERB.new(@tags_template) @caption = ERB.new(@caption_template) raise "Unsupport post_type: #{@post_type}" unless @post_type == 'picture' Tumblr.configure do |config| config.consumer_key = @consumer_key config.consumer_secret = @consumer_secret config.oauth_token = @oauth_token config.oauth_token_secret = @oauth_token_secret end @tumblr_client = Tumblr::Client.new @q = Queue.new end
emit(tag, es, chain)
click to toggle source
# File lib/fluent/plugin/out_tumblr.rb, line 65 def emit(tag, es, chain) es.each {|time, record| param = OpenStruct.new param.tag = tag param.time = time param.record = record @q.push param } chain.next end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_tumblr.rb, line 59 def shutdown super Thread.kill(@thread) end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_tumblr.rb, line 51 def start super @thread = Thread.new(&method(:post)) rescue $log.warn "raises exception: #{$!.class}, '#{$!.message}" end
Private Instance Methods
post()
click to toggle source
# File lib/fluent/plugin/out_tumblr.rb, line 79 def post() loop do param = @q.pop tag = param.tag time = param.time record = param.record post_to_tumblr tag, time, record sleep(@post_interval) end end
post_to_tumblr(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_tumblr.rb, line 92 def post_to_tumblr(tag, time, record) tempfile = Tempfile.new(File.basename(__FILE__), Dir.tmpdir) begin tempfile.binmode tempfile.write(@base64encoded ? Base64.decode64(record[@image_key]) : record[@image_key]) tempfile.close @tumblr_client.photo(@tumblr_url, tags: @tags.result(binding), caption: @caption.result(binding), link: record[@link_key], data: tempfile.path ) rescue $log.warn "raises exception: #{$!.class}, '#{$!.message}'" ensure tempfile.unlink end end