fluent-plugin-nicorepo 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a2dc10e30236f3ea0cea6b6742f035203c4230e
4
- data.tar.gz: ea3c862aadb8c497c17223add433c8e4db47fb89
3
+ metadata.gz: 5255e192a3d1b9c375676acb31c9e7e4e425a2da
4
+ data.tar.gz: '06812ecca4547ca68d428c53ada56bf21894eee3'
5
5
  SHA512:
6
- metadata.gz: 5d024c75ca6d5911636597d92e8633e6983d967b0a9590cdcf1a0d6ce50c225a479218262d58dfc8c85094e605ed1b890c4ab4d903d36cad83e75a6bc6682d89
7
- data.tar.gz: d1ab68a85d62481453d751b0acb4300a83e6f51e39f98fb9fc9281cd4bc18a5c1a56b19cf1a07e71fb8ac7872ad78aa88bee0b48f9526f4c90c65ee205f40873
6
+ metadata.gz: 1a5c876c6d8b64c8e6f478f8de37480a09009fb3b3e3ec7bb96e40ef712f5caaab3b7f2a346d4e6bccf9504df61745171c348733f0f02f8ea228acf358440977
7
+ data.tar.gz: '0691577feb9aa6386109551ab962f6ff1f12948b2d34ea11ffd1d378d007be9c16e5e97f40a11fa773e72a55b6ef6f1c83141ade98e4008b3bf60aac7fd1bcb9'
data/README.md CHANGED
@@ -24,14 +24,15 @@ You can also specify kind of reports by the optional attribute `kind`.
24
24
  ```
25
25
  <source>
26
26
  type nicorepo
27
- mail your@email.com # required: login mail address for nicovideo
28
- pass password # required: login password for nicovide
29
27
  interval 3h # optional: interval to fetch reports from nicovideo (defualt: 10 min)
30
28
  kind videos # optional: kind of reports to be filtered [all, videos, lives] (default: all)
31
29
  tag nicorepo.idobata
32
30
  </source>
33
31
  ```
34
32
 
33
+ The login email and password for nicovideo are required to be specified in `~/.netrc`.
34
+ See [nicorepo](https://github.com/upinetree/nicorepo) for the details.
35
+
35
36
  ## Contributing
36
37
 
37
38
  1. Fork it ( https://github.com/upinetree/fluent-plugin-nicorepo/fork )
@@ -19,9 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "fluentd", "~> 0.12.37"
22
- spec.add_runtime_dependency "nicorepo", "~> 0.0.8"
22
+ spec.add_runtime_dependency "nicorepo", "~> 1.0.0"
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "pry"
26
26
  spec.add_development_dependency "test-unit", "~> 3.0"
27
+ spec.add_development_dependency "mocha", "~> 1.2"
27
28
  end
@@ -7,10 +7,6 @@ module Fluent
7
7
 
8
8
  desc 'The tag of the event'
9
9
  config_param :tag, :string
10
- desc 'The login main address for nicovideo'
11
- config_param :mail, :string
12
- desc 'The login password for nicovideo'
13
- config_param :pass, :string
14
10
  desc 'The interval of each fetching'
15
11
  config_param :interval, :time, default: 600
16
12
  desc 'Max logs number at once fetch'
@@ -21,7 +17,7 @@ module Fluent
21
17
  config_param :kind, :string, default: 'all'
22
18
 
23
19
  def configure(conf)
24
- @nicorepo = Nicorepo.new
20
+ @client = Nicorepo::Client.new
25
21
  super
26
22
  end
27
23
 
@@ -43,11 +39,10 @@ module Fluent
43
39
  end
44
40
 
45
41
  def on_timer
46
- reports = fetch_reports
47
- reports.each do |report|
48
- time = Time.now
49
- record = report_to_hash(report)
50
- router.emit(@tag, time, record)
42
+ time = Time.now
43
+
44
+ fetch_report.format.each do |log|
45
+ router.emit(@tag, time, log)
51
46
  end
52
47
  rescue => e
53
48
  log.error "unexpected error", error: e
@@ -55,30 +50,20 @@ module Fluent
55
50
 
56
51
  private
57
52
 
58
- def fetch_reports
59
- since = Time.now - @interval
60
- @nicorepo.login(@mail, @pass)
53
+ def fetch_report
54
+ last_fetched_at = Time.now - @interval
61
55
 
62
56
  case @kind
63
57
  when 'all'
64
- @nicorepo.all(@limit_num, since: since)
58
+ @client.all(@limit_num, to: last_fetched_at)
65
59
  when 'videos'
66
- @nicorepo.videos(@limit_num, @limit_page, since: since)
60
+ @client.videos(@limit_num, limit_page: @limit_page, to: last_fetched_at)
67
61
  when 'lives'
68
- @nicorepo.lives(@limit_num, @limit_page, since: since)
62
+ @client.lives(@limit_num, limit_page: @limit_page, to: last_fetched_at)
69
63
  else
70
64
  log.error "unsupported report kind: #{@kind}"
71
65
  []
72
66
  end
73
67
  end
74
-
75
- def report_to_hash(report)
76
- {
77
- 'body' => report.body,
78
- 'title' => report.title,
79
- 'url' => report.url,
80
- 'date' => report.date
81
- }
82
- end
83
68
  end
84
69
  end
@@ -1,7 +1,7 @@
1
1
  module Fluent
2
2
  module Plugin
3
3
  module Nicorepo
4
- VERSION = "0.0.2"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
7
7
  end
data/test/helper.rb CHANGED
@@ -4,6 +4,6 @@ Bundler.setup
4
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
 
7
- require 'pry'
8
-
9
7
  require "fluent/test"
8
+ require 'mocha/test_unit'
9
+ require 'pry'
@@ -1,30 +1,18 @@
1
1
  require 'helper'
2
2
  require 'fluent/plugin/in_nicorepo'
3
3
 
4
- class NicorepoDouble
5
- def login(*)
6
- puts 'logined'
7
- end
8
-
9
- def all(*)
10
- [OpenStruct.new({
11
- body: "report body",
12
- title: "report title",
13
- url: "report url",
14
- date: "report date"
15
- })]
16
- end
17
- end
18
-
19
4
  class NicorepoInputTest < Test::Unit::TestCase
20
- def setup
21
- Fluent::Test.setup
22
- Fluent::NicorepoInput.send(:const_set, :Nicorepo, NicorepoDouble)
23
- end
5
+ DUMMY_REPORT = OpenStruct.new(
6
+ format: [{
7
+ sender: "dummy_user",
8
+ topic: "動画投稿",
9
+ title: "dummy_title",
10
+ url: "http://example.com",
11
+ created_at: Time.now
12
+ }]
13
+ )
24
14
 
25
15
  CONFIG = %[
26
- mail dummy@mail.com
27
- pass dummy_pass
28
16
  tag nicorepo.test
29
17
  ]
30
18
 
@@ -35,14 +23,17 @@ class NicorepoInputTest < Test::Unit::TestCase
35
23
  kind: 'all'
36
24
  }
37
25
 
26
+ def setup
27
+ Fluent::Test.setup
28
+ Nicorepo::Client.any_instance.stubs(:all).returns(DUMMY_REPORT)
29
+ end
30
+
38
31
  def create_driver(conf = CONFIG)
39
32
  Fluent::Test::InputTestDriver.new(Fluent::NicorepoInput).configure(conf, true)
40
33
  end
41
34
 
42
35
  def test_configure
43
36
  d = create_driver
44
- assert_equal('dummy@mail.com', d.instance.mail)
45
- assert_equal('dummy_pass', d.instance.pass)
46
37
  assert_equal('nicorepo.test', d.instance.tag)
47
38
  assert_equal(CONFIG_DEFAULTS[:interval], d.instance.interval)
48
39
  assert_equal(CONFIG_DEFAULTS[:limit_num], d.instance.limit_num)
@@ -51,12 +42,7 @@ class NicorepoInputTest < Test::Unit::TestCase
51
42
  end
52
43
 
53
44
  def test_emit
54
- expected_record = {
55
- 'body' => "report body",
56
- 'title' => "report title",
57
- 'url' => "report url",
58
- 'date' => "report date"
59
- }
45
+ expected_record = DUMMY_REPORT.format.first
60
46
 
61
47
  d = create_driver
62
48
  d.run
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-nicorepo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - upinetree
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.8
33
+ version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.8
40
+ version: 1.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.2'
97
111
  description: Fluent input plugin for Nicorepo.
98
112
  email:
99
113
  - upinetree@gmail.com