fluent-plugin-twittersearch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +11 -0
- data/fluent-plugin-twittersearch.gemspec +21 -0
- data/lib/fluent/plugin/in_twittersearch.rb +75 -0
- data/test/plugin/in_twittersearch.rb +114 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aab5386d955e9c8169ae355bd13cd3057ea097cd
|
4
|
+
data.tar.gz: 43138cf5af4906c1c00a724d355b82a8603e125d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2de9e1082c081387f6b47108db7ae25f9f8f697ecd825b970b25f846d7f5c099b8bb30bde846ecd1fc38b45d927e056cd6a8707124907132832fdfdea40de655
|
7
|
+
data.tar.gz: be1ce01e9d723491221917e9462c551b49df3a8c1321445e7196d1c8ca6a72775b1f1f94ae167b7c2aea3c2e9c3e291a9468ec04a5337940e385ad493cf0565c
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# For TextMate, emacs, vim
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.swp
|
5
|
+
*.tmproj
|
6
|
+
*~
|
7
|
+
.\#*
|
8
|
+
.bundle
|
9
|
+
.config
|
10
|
+
.yardoc
|
11
|
+
Gemfile.lock
|
12
|
+
InstalledFiles
|
13
|
+
\#*
|
14
|
+
_yardoc
|
15
|
+
coverage
|
16
|
+
doc/
|
17
|
+
lib/bundler/man
|
18
|
+
pkg
|
19
|
+
pkg/*
|
20
|
+
rdoc
|
21
|
+
spec/reports
|
22
|
+
test/tmp
|
23
|
+
test/version_tmp
|
24
|
+
tmp
|
25
|
+
tmtags
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Freddie FUJIWARA
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Fluent::Plugin::Twittersearch
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fluent-plugin-twittersearch'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fluent-plugin-twittersearch
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-twittersearch"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Freddie Fujiwara"]
|
9
|
+
s.date = %q{2013-09-29}
|
10
|
+
s.email = "github@ze.gs"
|
11
|
+
s.homepage = "http://github.com/freddiefujiwara/fluent-plugin-twittersearch"
|
12
|
+
s.summary = "twittersearch plugin for Fluentd"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_dependency %q<fluentd>, ["~> 0.10.0"]
|
20
|
+
s.add_dependency %q<twitter>, ["~> 4.8.1"]
|
21
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Fluent
|
2
|
+
class TwittersearchError < StandardError
|
3
|
+
end
|
4
|
+
class TwittersearchInput < Input
|
5
|
+
Plugin.register_input('twittersearch', self)
|
6
|
+
config_param :consumer_key, :string
|
7
|
+
config_param :consumer_secret, :string
|
8
|
+
config_param :oauth_token, :string
|
9
|
+
config_param :oauth_token_secret, :string
|
10
|
+
config_param :tag, :string
|
11
|
+
config_param :keyword, :string,:default => nil
|
12
|
+
config_param :hashtag, :string,:default => nil
|
13
|
+
config_param :count, :integer
|
14
|
+
config_param :run_interval, :integer
|
15
|
+
config_param :result_type, :string
|
16
|
+
|
17
|
+
attr_reader :twitter
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
super
|
21
|
+
require "twitter"
|
22
|
+
end
|
23
|
+
|
24
|
+
def configure(config)
|
25
|
+
super
|
26
|
+
Twitter.configure do |cnf|
|
27
|
+
cnf.consumer_key = @consumer_key
|
28
|
+
cnf.consumer_secret = @consumer_secret
|
29
|
+
end
|
30
|
+
@twitter = Twitter::Client.new(
|
31
|
+
:oauth_token => @oauth_token,
|
32
|
+
:oauth_token_secret => @oauth_token_secret
|
33
|
+
)
|
34
|
+
raise Fluent::ConfigError.new if @keyword.nil? and @hashtag.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def start
|
38
|
+
super
|
39
|
+
@thread = Thread.new(&method(:run))
|
40
|
+
end
|
41
|
+
|
42
|
+
def search
|
43
|
+
tweets = []
|
44
|
+
@twitter.search(@keyword.nil? ? "##{@hashtag}" : @keyword,
|
45
|
+
:count => @count,
|
46
|
+
:result_type => @result_type).results.reverse.map do |result|
|
47
|
+
|
48
|
+
tweet = Hash.new
|
49
|
+
[:created_at,:id,:retweet_count,:favorite_count].each do |key|
|
50
|
+
tweet.store(key.to_s, result[key])
|
51
|
+
end
|
52
|
+
[:id,:screen_name,:profile_image_url,:profile_image_url_https].each do |key|
|
53
|
+
tweet.store(key.to_s, result.user[key])
|
54
|
+
end
|
55
|
+
tweet.store('text',result.text.force_encoding('utf-8'))
|
56
|
+
tweet.store('name',result.user.name.force_encoding('utf-8'))
|
57
|
+
tweets << tweet
|
58
|
+
end
|
59
|
+
tweets
|
60
|
+
end
|
61
|
+
|
62
|
+
def run
|
63
|
+
loop do
|
64
|
+
search.each do |tweet|
|
65
|
+
Engine.emit @tag,Engine.now,tweet
|
66
|
+
end
|
67
|
+
sleep @run_interval
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def shutdown
|
72
|
+
Thread.kill(@thread)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
require 'json'
|
3
|
+
require 'fluent/plugin/in_twittersearch'
|
4
|
+
|
5
|
+
class FileInputTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Fluent::Test.setup
|
8
|
+
|
9
|
+
@d = create_driver %[
|
10
|
+
consumer_key T5dTrSxS3oXqBbaoYZERw
|
11
|
+
consumer_secret Trg3qrO7dUSkKZeGxgjmi3B11JuFhjwhiWIkwWKDe0
|
12
|
+
oauth_token 1960044126-heQQwLkiqoTj7uEJAVy0WDUZEEZDJfQqk7C4JIz
|
13
|
+
oauth_token_secret r0JZ258nTeYzfJ6PZcpD8Pd1ulgawXFt2fP5J5lzZ8
|
14
|
+
tag input.twitter
|
15
|
+
keyword rakuten
|
16
|
+
count 1
|
17
|
+
run_interval 60
|
18
|
+
result_type recent
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_driver(config = CONFIG)
|
23
|
+
Fluent::Test::OutputTestDriver.new(Fluent::TwittersearchInput).configure(config)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_configure
|
27
|
+
assert_raise Fluent::ConfigError do
|
28
|
+
d = create_driver %[
|
29
|
+
consumer_key T5dTrSxS3oXqBbaoYZERw
|
30
|
+
consumer_secret Trg3qrO7dUSkKZeGxgjmi3B11JuFhjwhiWIkwWKDe0
|
31
|
+
oauth_token 1960044126-heQQwLkiqoTj7uEJAVy0WDUZEEZDJfQqk7C4JIz
|
32
|
+
oauth_token_secret r0JZ258nTeYzfJ6PZcpD8Pd1ulgawXFt2fP5J5lzZ
|
33
|
+
tag input.twitter
|
34
|
+
count 1
|
35
|
+
run_interval 60
|
36
|
+
result_type recent
|
37
|
+
]
|
38
|
+
end
|
39
|
+
d = create_driver %[
|
40
|
+
consumer_key T5dTrSxS3oXqBbaoYZERw
|
41
|
+
consumer_secret Trg3qrO7dUSkKZeGxgjmi3B11JuFhjwhiWIkwWKDe0
|
42
|
+
oauth_token 1960044126-heQQwLkiqoTj7uEJAVy0WDUZEEZDJfQqk7C4JIz
|
43
|
+
oauth_token_secret r0JZ258nTeYzfJ6PZcpD8Pd1ulgawXFt2fP5J5lzZ
|
44
|
+
tag input.twitter
|
45
|
+
keyword rakuten
|
46
|
+
hashtag rakuten
|
47
|
+
count 1
|
48
|
+
run_interval 60
|
49
|
+
result_type recent
|
50
|
+
]
|
51
|
+
d.instance.inspect
|
52
|
+
assert_equal 'T5dTrSxS3oXqBbaoYZERw', d.instance.consumer_key
|
53
|
+
assert_equal 'Trg3qrO7dUSkKZeGxgjmi3B11JuFhjwhiWIkwWKDe0', d.instance.consumer_secret
|
54
|
+
assert_equal '1960044126-heQQwLkiqoTj7uEJAVy0WDUZEEZDJfQqk7C4JIz', d.instance.oauth_token
|
55
|
+
assert_equal 'r0JZ258nTeYzfJ6PZcpD8Pd1ulgawXFt2fP5J5lzZ', d.instance.oauth_token_secret
|
56
|
+
assert_equal 'input.twitter', d.instance.tag
|
57
|
+
assert_equal 'rakuten', d.instance.keyword
|
58
|
+
assert_equal 'rakuten', d.instance.hashtag
|
59
|
+
assert_equal 1, d.instance.count
|
60
|
+
assert_equal 60, d.instance.run_interval
|
61
|
+
assert_equal 'recent', d.instance.result_type
|
62
|
+
assert_not_nil d.instance.twitter
|
63
|
+
assert_equal Twitter::Client , d.instance.twitter.class
|
64
|
+
assert_raise Twitter::Error::Unauthorized do
|
65
|
+
d.instance.twitter.search(d.instance.keyword,
|
66
|
+
:count => d.instance.count,
|
67
|
+
:result_type => d.instance.result_type)
|
68
|
+
end
|
69
|
+
d = create_driver %[
|
70
|
+
consumer_key T5dTrSxS3oXqBbaoYZERw
|
71
|
+
consumer_secret Trg3qrO7dUSkKZeGxgjmi3B11JuFhjwhiWIkwWKDe0
|
72
|
+
oauth_token 1960044126-heQQwLkiqoTj7uEJAVy0WDUZEEZDJfQqk7C4JIz
|
73
|
+
oauth_token_secret r0JZ258nTeYzfJ6PZcpD8Pd1ulgawXFt2fP5J5lzZ8
|
74
|
+
tag input.twitter
|
75
|
+
keyword rakuten
|
76
|
+
hashtag rakuten
|
77
|
+
count 1
|
78
|
+
run_interval 60
|
79
|
+
result_type recent
|
80
|
+
]
|
81
|
+
assert_equal 1, d.instance.twitter.search(d.instance.keyword,
|
82
|
+
:count => d.instance.count,
|
83
|
+
:result_type => d.instance.result_type).results.count
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_search
|
87
|
+
d = create_driver %[
|
88
|
+
consumer_key T5dTrSxS3oXqBbaoYZERw
|
89
|
+
consumer_secret Trg3qrO7dUSkKZeGxgjmi3B11JuFhjwhiWIkwWKDe0
|
90
|
+
oauth_token 1960044126-heQQwLkiqoTj7uEJAVy0WDUZEEZDJfQqk7C4JIz
|
91
|
+
oauth_token_secret r0JZ258nTeYzfJ6PZcpD8Pd1ulgawXFt2fP5J5lzZ8
|
92
|
+
tag input.twitter
|
93
|
+
keyword rakuten
|
94
|
+
hashtag rakuten
|
95
|
+
count 1
|
96
|
+
run_interval 60
|
97
|
+
result_type recent
|
98
|
+
]
|
99
|
+
tweets = d.instance.search
|
100
|
+
tweets.each do |tweet|
|
101
|
+
[:created_at,
|
102
|
+
:id,
|
103
|
+
:text,
|
104
|
+
:retweet_count,
|
105
|
+
:favorite_count,
|
106
|
+
:screen_name,
|
107
|
+
:name,
|
108
|
+
:profile_image_url,
|
109
|
+
:profile_image_url_https].each do |key|
|
110
|
+
assert_not_nil tweet[key.to_s]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-twittersearch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Freddie Fujiwara
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-29 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.10.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.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: twitter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.8.1
|
41
|
+
description:
|
42
|
+
email: github@ze.gs
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- fluent-plugin-twittersearch.gemspec
|
53
|
+
- lib/fluent/plugin/in_twittersearch.rb
|
54
|
+
- test/plugin/in_twittersearch.rb
|
55
|
+
homepage: http://github.com/freddiefujiwara/fluent-plugin-twittersearch
|
56
|
+
licenses: []
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.0.3
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: twittersearch plugin for Fluentd
|
78
|
+
test_files: []
|