fluent-plugin-tumblr 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c70293cd4e3fcbe0975bda19f434d5eb41d5bf66
4
+ data.tar.gz: 57c751daba6397962f6ce61bee405833163fb176
5
+ SHA512:
6
+ metadata.gz: 9828085d3020e503c2cfe4c4a11ef1552a83f101d16bc106060d4c6f339b0a0036c6c490bbcd496eade7eb66e5b5abfe48396b8bee0ff2b6d7ba0714e6d7d625
7
+ data.tar.gz: 1665b9cd3e6bc162c31e0f3a09cd0c516249a8085b57addac4eaabedb8a94f6820c01fe20177d9982a7af518e4aa2b134bbf7ccc812b894a64f123324d38231f
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
19
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent_parser_s.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ # fluent-plugin-tumblr
2
+
3
+ ## Output
4
+
5
+ Plugin to post entry to your tumblr
6
+
7
+ ### What's 'tumblr'
8
+
9
+ see: https://www.tumblr.com/
10
+
11
+ ### Configure Example
12
+
13
+ ````
14
+ type tumblr
15
+ consumer_key YOUR_TUMBLR_CONSUMER_KEY
16
+ consumer_secret YOUR_TUMBLR_CONSUMER_SECRET_KEY
17
+ oauth_token YOUR_TUMBLR_OATH_TOKEN_KEY
18
+ oauth_token_secret YOUR_TUMBLR_OATH_TOKEN_SECRET_KEY
19
+ tumblr_url YOUR_TUMBLR_URL
20
+ tags_template TAG_<%= record['tag'] %>
21
+ caption_template <%= record['message'] %>
22
+ link_key url
23
+ image_key raw_image
24
+ post_type picture
25
+ ````
26
+
27
+ - **Support post_type picture only**
28
+ - You can use ERB in tags_template, caption_template
29
+ - http://rubydoc.info/gems/tumblr_client/0.8.2/Tumblr/Post#photo-instance_method
30
+ - if base64 encored image in `image_key`, set `base64encoded true`
31
+ - if raw image in `image_key`, set `base64encoded false`
32
+
33
+ #### Optional
34
+ - post_interval
35
+ - Internal of post to tumblr
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
44
+
45
+ ## releases
46
+
47
+ - 2014/01/25 0.0.2 Release gem
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-tumblr"
7
+ spec.version = '0.0.2'
8
+ spec.authors = ["bash0C7"]
9
+ spec.email = ["koshiba+github@4038nullpointer.com"]
10
+ spec.description = "Fluentd output plugin to post entry to your tumblr"
11
+ spec.summary = "Fluentd output plugin to post entry to your tumblr"
12
+ spec.homepage = "https://github.com/bash0C7/fluent-plugin-tumblr"
13
+ spec.license = "Ruby's"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "fluentd"
21
+ spec.add_dependency "tumblr_client", ">= 0.8.2"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rr"
26
+ spec.add_development_dependency "pry"
27
+ end
@@ -0,0 +1,113 @@
1
+ require 'tumblr_client'
2
+ require 'erb'
3
+ require 'tempfile'
4
+ require 'base64'
5
+ require 'ostruct'
6
+
7
+ module Fluent
8
+ class Fluent::TumblrOutput < Fluent::Output
9
+ Fluent::Plugin.register_output('tumblr', self)
10
+
11
+ def initialize
12
+ super
13
+ end
14
+
15
+ config_param :consumer_key, :string
16
+ config_param :consumer_secret, :string
17
+ config_param :oauth_token, :string
18
+ config_param :oauth_token_secret, :string
19
+
20
+ config_param :tumblr_url, :string
21
+ config_param :tags_template, :string
22
+ config_param :caption_template, :string
23
+
24
+ config_param :link_key, :string
25
+ config_param :image_key, :string
26
+ config_param :post_type, :string
27
+ config_param :base64encoded, :bool
28
+
29
+ config_param :post_interval, :integer, :default => 10
30
+
31
+ attr_accessor :tumblr_client
32
+
33
+ def configure(conf)
34
+ super
35
+
36
+ @tags = ERB.new(@tags_template)
37
+ @caption = ERB.new(@caption_template)
38
+ raise "Unsupport post_type: #{@post_type}" unless @post_type == 'picture'
39
+
40
+ Tumblr.configure do |config|
41
+ config.consumer_key = @consumer_key
42
+ config.consumer_secret = @consumer_secret
43
+ config.oauth_token = @oauth_token
44
+ config.oauth_token_secret = @oauth_token_secret
45
+ end
46
+ @tumblr_client = Tumblr::Client.new
47
+
48
+ @q = Queue.new
49
+ end
50
+
51
+ def start
52
+ super
53
+
54
+ @thread = Thread.new(&method(:post))
55
+ rescue
56
+ $log.warn "raises exception: #{$!.class}, '#{$!.message}"
57
+ end
58
+
59
+ def shutdown
60
+ super
61
+
62
+ Thread.kill(@thread)
63
+ end
64
+
65
+ def emit(tag, es, chain)
66
+ es.each {|time, record|
67
+ param = OpenStruct.new
68
+ param.tag = tag
69
+ param.time = time
70
+ param.record = record
71
+
72
+ @q.push param
73
+ }
74
+
75
+ chain.next
76
+ end
77
+
78
+ private
79
+ def post()
80
+ loop do
81
+ param = @q.pop
82
+ tag = param.tag
83
+ time = param.time
84
+ record = param.record
85
+
86
+ post_to_tumblr tag, time, record
87
+
88
+ sleep(@post_interval)
89
+ end
90
+ end
91
+
92
+ def post_to_tumblr(tag, time, record)
93
+ tempfile = Tempfile.new(File.basename(__FILE__), Dir.tmpdir)
94
+ begin
95
+ tempfile.binmode
96
+
97
+ tempfile.write(@base64encoded ? Base64.decode64(record[@image_key]) : record[@image_key])
98
+ tempfile.close
99
+
100
+ @tumblr_client.photo(@tumblr_url,
101
+ tags: @tags.result(binding),
102
+ caption: @caption.result(binding),
103
+ link: record[@link_key],
104
+ data: tempfile.path
105
+ )
106
+ rescue
107
+ $log.warn "raises exception: #{$!.class}, '#{$!.message}'"
108
+ ensure
109
+ tempfile.unlink
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe do
4
+ let(:driver) {Fluent::Test::OutputTestDriver.new(Fluent::TumblrOutput, 'test.metrics').configure(config)}
5
+ let(:instance) {driver.instance}
6
+
7
+ describe 'emit' do
8
+ let(:record1) {{ 'tweet_url' => 'some_url1', 'raw_media' => 'picture1'}}
9
+ let(:record2) {{ 'tweet_url' => 'some_url2', 'raw_media' => 'picture2'}}
10
+ let(:time) {0}
11
+ let(:posted) {
12
+ d = driver
13
+
14
+ tumblr_client = Tumblr::Client.new
15
+
16
+ mock(tumblr_client).photo("tumblr_url", {:tags=>"TAG", :caption=>"CAPTION", :link=>"some_url1", :data=>"filepath"})
17
+ mock(tumblr_client).photo("tumblr_url", {:tags=>"TAG", :caption=>"CAPTION", :link=>"some_url2", :data=>"filepath"})
18
+
19
+ any_instance_of(Tempfile) do |klass|
20
+ stub(klass).path { 'filepath' }
21
+ end
22
+
23
+ d.instance.tumblr_client = tumblr_client
24
+
25
+ d.emit(record1, Time.at(time))
26
+ d.emit(record2, Time.at(time))
27
+ d.run
28
+ }
29
+
30
+ context do
31
+ let(:config) {
32
+ %[
33
+ consumer_key consumer_key
34
+ consumer_secret consumer_secret
35
+ oauth_token oauth_token
36
+ oauth_token_secret oauth_token_secret
37
+ tumblr_url tumblr_url
38
+ tags_template TAG
39
+ caption_template CAPTION
40
+ link_key tweet_url
41
+ image_key raw_media
42
+ base64encoded false
43
+ post_type picture
44
+ post_interval 0
45
+ ]
46
+ }
47
+
48
+ subject {posted}
49
+ it{should_not be_nil}
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,25 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+
18
+ require 'fluent/load'
19
+ require 'fluent/test'
20
+
21
+ require 'fluent/plugin/out_tumblr'
22
+
23
+ require 'pry'
24
+ require 'rr'
25
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-tumblr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - bash0C7
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tumblr_client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Fluentd output plugin to post entry to your tumblr
112
+ email:
113
+ - koshiba+github@4038nullpointer.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - fluent-plugin-tumblr.gemspec
124
+ - lib/fluent/plugin/out_tumblr.rb
125
+ - spec/lib/fluent/plugin/out_tumblr_spec.rb
126
+ - spec/spec_helper.rb
127
+ homepage: https://github.com/bash0C7/fluent-plugin-tumblr
128
+ licenses:
129
+ - Ruby's
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.0.5
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Fluentd output plugin to post entry to your tumblr
151
+ test_files:
152
+ - spec/lib/fluent/plugin/out_tumblr_spec.rb
153
+ - spec/spec_helper.rb