fluent-plugin-twitter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +14 -0
- data/README.md +42 -0
- data/Rakefile +10 -0
- data/fluent-plugin-twitter.gemspec +20 -0
- data/lib/fluent/plugin/out_twitter.rb +41 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_out_twitter.rb +46 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (c) 2012- Kentaro Yoshida
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
fluent-plugin-twitter
|
2
|
+
=====================
|
3
|
+
|
4
|
+
## Overview
|
5
|
+
create your own twitter bot with fluentd
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
### native gem
|
10
|
+
|
11
|
+
`````
|
12
|
+
gem install fluent-plugin-twitter
|
13
|
+
`````
|
14
|
+
|
15
|
+
### td-agent gem
|
16
|
+
`````
|
17
|
+
/usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-twitter
|
18
|
+
`````
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
|
22
|
+
### Sample
|
23
|
+
`````
|
24
|
+
<match notify.twitter>
|
25
|
+
type twitter
|
26
|
+
consumer_key YOUR_CONSUMER_KEY
|
27
|
+
consumer_secret YOUR_CONSUMER_SECRET
|
28
|
+
oauth_token YOUR_OAUTH_TOEKN
|
29
|
+
oauth_token_secret YOUR_OAUTH_TOEKN_SECRET
|
30
|
+
</match>
|
31
|
+
`````
|
32
|
+
|
33
|
+
## TODO
|
34
|
+
patches welcome!
|
35
|
+
|
36
|
+
## Copyright
|
37
|
+
|
38
|
+
Copyright © 2012- Kentaro Yoshida (@yoshi_ken)
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-twitter"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Kentaro Yoshida"]
|
8
|
+
s.email = ["y.ken.studio@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/y-ken/fluent-plugin-twitter"
|
10
|
+
s.summary = %q{Fluentd Output filter plugin. You can create your own "Twitter Bot" with fluentd messaging system.}
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
# specify any dependencies here; for example:
|
18
|
+
s.add_development_dependency "fluentd"
|
19
|
+
s.add_runtime_dependency "fluentd"
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Fluent::TwitterOutput < Fluent::Output
|
2
|
+
Fluent::Plugin.register_output('twitter', self)
|
3
|
+
|
4
|
+
config_param :consumer_key, :string
|
5
|
+
config_param :consumer_secret, :string
|
6
|
+
config_param :oauth_token, :string
|
7
|
+
config_param :oauth_token_secret, :string
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
require 'twitter'
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure(conf)
|
15
|
+
super
|
16
|
+
|
17
|
+
@twitter = Twitter::Client.new(
|
18
|
+
:consumer_key => conf['consumer_key'],
|
19
|
+
:consumer_secret => conf['consumer_secret'],
|
20
|
+
:oauth_token => conf['oauth_token'],
|
21
|
+
:oauth_token_secret => conf['oauth_token_secret']
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def emit(tag, es, chain)
|
26
|
+
es.each do |time,record|
|
27
|
+
tweet(record['message'])
|
28
|
+
end
|
29
|
+
|
30
|
+
chain.next
|
31
|
+
end
|
32
|
+
|
33
|
+
def tweet(message)
|
34
|
+
begin
|
35
|
+
@twitter.update(message)
|
36
|
+
rescue Twitter::Error => e
|
37
|
+
$log.error("Twitter Error: #{e.message}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/out_twitter'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TwitterOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
consumer_key CONSUMER_KEY
|
10
|
+
consumer_secret CONSUMER_SECRET
|
11
|
+
oauth_token OAUTH_TOEKN
|
12
|
+
oauth_token_secret OAUTH_TOEKN_SECRET
|
13
|
+
]
|
14
|
+
|
15
|
+
def create_driver(conf=CONFIG,tag='test')
|
16
|
+
Fluent::Test::OutputTestDriver.new(Fluent::TwitterOutput, tag).configure(conf)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_configure
|
20
|
+
assert_raise(Fluent::ConfigError) {
|
21
|
+
d = create_driver('')
|
22
|
+
}
|
23
|
+
d = create_driver %[
|
24
|
+
consumer_key CONSUMER_KEY
|
25
|
+
consumer_secret CONSUMER_SECRET
|
26
|
+
oauth_token OAUTH_TOEKN
|
27
|
+
oauth_token_secret OAUTH_TOEKN_SECRET
|
28
|
+
]
|
29
|
+
d.instance.inspect
|
30
|
+
assert_equal 'CONSUMER_KEY', d.instance.consumer_key
|
31
|
+
assert_equal 'CONSUMER_SECRET', d.instance.consumer_secret
|
32
|
+
assert_equal 'OAUTH_TOEKN', d.instance.oauth_token
|
33
|
+
assert_equal 'OAUTH_TOEKN_SECRET', d.instance.oauth_token_secret
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_emit
|
37
|
+
d1 = create_driver(CONFIG, 'input.access')
|
38
|
+
time = Time.parse("2012-01-02 13:14:15").to_i
|
39
|
+
d1.run do
|
40
|
+
d1.emit({'message' => 'sample message'})
|
41
|
+
end
|
42
|
+
emits = d1.emits
|
43
|
+
assert_equal 0, emits.length
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-twitter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kentaro Yoshida
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fluentd
|
16
|
+
requirement: &16126320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *16126320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fluentd
|
27
|
+
requirement: &16125060 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *16125060
|
36
|
+
description:
|
37
|
+
email:
|
38
|
+
- y.ken.studio@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE.txt
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- fluent-plugin-twitter.gemspec
|
49
|
+
- lib/fluent/plugin/out_twitter.rb
|
50
|
+
- test/helper.rb
|
51
|
+
- test/plugin/test_out_twitter.rb
|
52
|
+
homepage: https://github.com/y-ken/fluent-plugin-twitter
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.11
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Fluentd Output filter plugin. You can create your own "Twitter Bot" with
|
76
|
+
fluentd messaging system.
|
77
|
+
test_files:
|
78
|
+
- test/helper.rb
|
79
|
+
- test/plugin/test_out_twitter.rb
|