fluent-plugin-nicorepo 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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/fluent-plugin-nicorepo.gemspec +26 -0
- data/lib/fluent/plugin/in_nicorepo.rb +77 -0
- data/lib/fluent/plugin/nicorepo/version.rb +7 -0
- data/test/helper.rb +11 -0
- data/test/plugin/test_in_nicorepo.rb +72 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c6ca92549a94b550f0d65129bba174327f43dfc
|
4
|
+
data.tar.gz: 8c3b31a53a4c87e6be506eea425b6f5351bbe552
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ac7f885deaec8c8d28569ce9051f891183c4b4d3d611c409edd3d6e08212b855dc17690245d35107065706a2d532109eddcbc2370627cb33b5220be69b6a526
|
7
|
+
data.tar.gz: 3035143e15b74ed99e7481ab14c0ae3f6c02db9729345af867c4b4fd2b977a8b459a533a5680a08ae257743596f4c022fd07d191e7e3b9057adf747f8f0f2565
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 upinetree
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Fluentd::Plugin::Nicorepo
|
2
|
+
|
3
|
+
Input plugin to fetch Nicorepo on Nicovideo.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fluent-plugin-nicorepo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fluent-plugin-nicorepo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
This plugin fetches reports of Nicorepo in every `interval` that specified by configuration file as shown below.
|
22
|
+
You can also specify kind of reports by the optional attribute `kind`.
|
23
|
+
|
24
|
+
```
|
25
|
+
<source>
|
26
|
+
type nicorepo
|
27
|
+
mail your@email.com # required: login mail address for nicovideo
|
28
|
+
pass password # required: login password for nicovide
|
29
|
+
interval 3h # optional: interval to fetch reports from nicovideo (defualt: 10 min)
|
30
|
+
kind videos # optional: kind of reports to be filtered [all, videos, lives] (default: all)
|
31
|
+
tag nicorepo.idobata
|
32
|
+
</source>
|
33
|
+
```
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/upinetree/fluent-plugin-nicorepo/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fluent/plugin/nicorepo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fluent-plugin-nicorepo"
|
8
|
+
spec.version = Fluent::Plugin::Nicorepo::VERSION
|
9
|
+
spec.authors = ["upinetree"]
|
10
|
+
spec.email = ["essequake@gmail.com"]
|
11
|
+
spec.summary = %q{Fluent input plugin for Nicorepo}
|
12
|
+
spec.description = %q{Fluent input plugin for Nicorepo.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "fluentd"
|
22
|
+
spec.add_runtime_dependency "nicorepo"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'nicorepo'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class NicorepoInput < Fluent::Input
|
5
|
+
Plugin.register_input 'nicorepo', self
|
6
|
+
|
7
|
+
config_param :tag, :string
|
8
|
+
config_param :mail, :string
|
9
|
+
config_param :pass, :string
|
10
|
+
config_param :interval, :time, default: 600
|
11
|
+
config_param :limit_num, :integer, default: 50
|
12
|
+
config_param :limit_page, :integer, default: 30
|
13
|
+
config_param :kind, :string, default: 'all'
|
14
|
+
|
15
|
+
def configure(conf)
|
16
|
+
@nicorepo = Nicorepo.new
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def start
|
21
|
+
@thread = Thread.new(&method(:run))
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def shutdown
|
26
|
+
Thread.kill(@thread)
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
loop do
|
32
|
+
Thread.new(&method(:on_timer))
|
33
|
+
sleep @interval
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_timer
|
38
|
+
reports = fetch_reports
|
39
|
+
reports.each do |report|
|
40
|
+
time = Time.now
|
41
|
+
record = report_to_hash(report)
|
42
|
+
Engine.emit(@tag, time, record)
|
43
|
+
end
|
44
|
+
rescue => e
|
45
|
+
log.error "unexpected error", error: e
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def fetch_reports
|
51
|
+
since = Time.now - @interval
|
52
|
+
@nicorepo.login(@mail, @pass)
|
53
|
+
|
54
|
+
case @kind
|
55
|
+
when 'all'
|
56
|
+
@nicorepo.all(@limit_num, since: since)
|
57
|
+
when 'videos'
|
58
|
+
@nicorepo.videos(@limit_num, @limit_page, since: since)
|
59
|
+
when 'lives'
|
60
|
+
@nicorepo.lives(@limit_num, @limit_page, since: since)
|
61
|
+
else
|
62
|
+
log.error "unsupported report kind: #{@kind}"
|
63
|
+
[]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def report_to_hash(report)
|
68
|
+
{
|
69
|
+
body: report.body,
|
70
|
+
title: report.title,
|
71
|
+
url: report.url,
|
72
|
+
date: report.date
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'minitest/unit'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'fluent/test'
|
10
|
+
require 'fluent/plugin/in_nicorepo'
|
11
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class NicorepoDouble
|
4
|
+
def initialize
|
5
|
+
end
|
6
|
+
|
7
|
+
def login(*)
|
8
|
+
puts 'logined'
|
9
|
+
end
|
10
|
+
|
11
|
+
def all(*)
|
12
|
+
[OpenStruct.new({
|
13
|
+
body: "report body",
|
14
|
+
title: "report title",
|
15
|
+
url: "report url",
|
16
|
+
date: "report date"
|
17
|
+
})]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class NicorepoInputTest < MiniTest::Unit::TestCase
|
22
|
+
def setup
|
23
|
+
Fluent::Test.setup
|
24
|
+
Fluent::NicorepoInput.send(:const_set, :Nicorepo, NicorepoDouble)
|
25
|
+
end
|
26
|
+
|
27
|
+
CONFIG = %[
|
28
|
+
mail dummy@mail.com
|
29
|
+
pass dummy_pass
|
30
|
+
tag nicorepo.test
|
31
|
+
]
|
32
|
+
|
33
|
+
CONFIG_DEFAULTS = {
|
34
|
+
interval: 600,
|
35
|
+
limit_num: 50,
|
36
|
+
limit_page: 30,
|
37
|
+
kind: 'all'
|
38
|
+
}
|
39
|
+
|
40
|
+
def create_driver(conf = CONFIG)
|
41
|
+
Fluent::Test::InputTestDriver.new(Fluent::NicorepoInput).configure(conf)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_configure
|
45
|
+
d = create_driver
|
46
|
+
assert_equal('dummy@mail.com', d.instance.mail)
|
47
|
+
assert_equal('dummy_pass', d.instance.pass)
|
48
|
+
assert_equal('nicorepo.test', d.instance.tag)
|
49
|
+
assert_equal(CONFIG_DEFAULTS[:interval], d.instance.interval)
|
50
|
+
assert_equal(CONFIG_DEFAULTS[:limit_num], d.instance.limit_num)
|
51
|
+
assert_equal(CONFIG_DEFAULTS[:limit_page], d.instance.limit_page)
|
52
|
+
assert_equal(CONFIG_DEFAULTS[:kind], d.instance.kind)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_emit
|
56
|
+
expected_record = {
|
57
|
+
body: "report body",
|
58
|
+
title: "report title",
|
59
|
+
url: "report url",
|
60
|
+
date: "report date"
|
61
|
+
}
|
62
|
+
|
63
|
+
d = create_driver
|
64
|
+
d.run
|
65
|
+
d.run
|
66
|
+
# TODO: 2回runしないとemitsに反映されない原因を調べる
|
67
|
+
# Fluent::Engine.emitは正しく実行されていることを確認
|
68
|
+
|
69
|
+
assert_equal(expected_record, d.emits.first[2])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-nicorepo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- upinetree
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-09 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: nicorepo
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
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.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
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: pry
|
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
|
+
description: Fluent input plugin for Nicorepo.
|
84
|
+
email:
|
85
|
+
- essequake@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- fluent-plugin-nicorepo.gemspec
|
96
|
+
- lib/fluent/plugin/in_nicorepo.rb
|
97
|
+
- lib/fluent/plugin/nicorepo/version.rb
|
98
|
+
- test/helper.rb
|
99
|
+
- test/plugin/test_in_nicorepo.rb
|
100
|
+
homepage: ''
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.2.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Fluent input plugin for Nicorepo
|
124
|
+
test_files:
|
125
|
+
- test/helper.rb
|
126
|
+
- test/plugin/test_in_nicorepo.rb
|