fluent-plugin-rss 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/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/Rakefile +9 -0
- data/fluent-plugin-rss.gemspec +23 -0
- data/lib/fluent/plugin/in_rss.rb +55 -0
- data/test/helper.rb +18 -0
- data/test/plugin/test_in_rss.rb +32 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 453767bbb3e9f90ec40e64e97a9b1b3f725a60b1
|
4
|
+
data.tar.gz: 508affd5097e64099f17e6cc64afce53947648a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0d42924eb14029622f283948a096b31feed29e20a4b6ea98997b9eb8352a9abf95c0f4f927ab5791d5967f6b26d67078f14fe31d33ad950473f1bec23d96dcb
|
7
|
+
data.tar.gz: 2927c5eecefaee685e84a392fea38cacd6814b879e9c6363ce243d4b56239a9ff136d0a29f5ad294b4cd982282c6f621c9e85b5cca7d37cbfea8163fc3373f26
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-plugin-rss (0.0.1)
|
5
|
+
fluentd
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
cool.io (1.2.1)
|
11
|
+
fluentd (0.10.44)
|
12
|
+
cool.io (>= 1.1.1, < 2.0.0, != 1.2.0)
|
13
|
+
http_parser.rb (~> 0.5.1)
|
14
|
+
json (>= 1.4.3)
|
15
|
+
msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
|
16
|
+
sigdump (~> 0.2.2)
|
17
|
+
yajl-ruby (~> 1.0)
|
18
|
+
http_parser.rb (0.5.3)
|
19
|
+
json (1.8.1)
|
20
|
+
msgpack (0.5.8)
|
21
|
+
rake (10.2.0)
|
22
|
+
sigdump (0.2.2)
|
23
|
+
yajl-ruby (1.1.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.5)
|
30
|
+
fluent-plugin-rss!
|
31
|
+
rake
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Shunsuke Michii
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# fluent-plugin-rss
|
2
|
+
|
3
|
+
fetch RSS feed items and emit to fluentd stream.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```
|
8
|
+
<source>
|
9
|
+
tag rss.nytimes # Required: tag to emit
|
10
|
+
url http://example.com/input-your-rss-feed-here.rdf # Required: feed url
|
11
|
+
interval 10m # Optional: fetch interval (default: 5 min.)
|
12
|
+
attrs date, title # Optional: attributes to emit stream
|
13
|
+
</source>
|
14
|
+
```
|
15
|
+
|
16
|
+
## Todo
|
17
|
+
|
18
|
+
- more tests
|
19
|
+
- more documentation (if you needed)
|
20
|
+
|
21
|
+
* * *
|
22
|
+
|
23
|
+
## Copyright
|
24
|
+
|
25
|
+
Copyright © 2014 Shunsuke Michii.
|
26
|
+
All rights reserved.
|
27
|
+
|
28
|
+
This software is released under MIT License (see LICENCE file).
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Patches Welcome!
|
33
|
+
|
34
|
+
1. Fork it ( http://github.com/<my-github-username>/fluent-plugin-rss/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
39
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
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-rss"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["harukasan"]
|
9
|
+
spec.email = ["harukasan@pixiv.com"]
|
10
|
+
spec.summary = %q{Fluent input plugin to fetch RSS feed items}
|
11
|
+
spec.description = %q{Fluent input plugin to fetch RSS feed items.}
|
12
|
+
spec.homepage = "https://github.com/harukasan/fluent-plugin-rss"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^test/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_runtime_dependency "fluentd"
|
23
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rss'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class RSSInput < Fluent::Input
|
5
|
+
Plugin.register_input 'rss', self
|
6
|
+
|
7
|
+
config_param :tag, :string
|
8
|
+
config_param :url, :string
|
9
|
+
config_param :interval, :time, default: '5m'
|
10
|
+
config_param :attrs, :string, default: 'date, title, description'
|
11
|
+
|
12
|
+
def configure(conf)
|
13
|
+
super
|
14
|
+
|
15
|
+
@attrs = @attrs.split(',').map {|attr| attr.strip }
|
16
|
+
@current_time = Time.now
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
@thread = Thread.new(&method(:run))
|
21
|
+
end
|
22
|
+
|
23
|
+
def shutdown
|
24
|
+
Thread.kill(@thread)
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
loop do
|
29
|
+
Thread.new(&method(:emit_rss))
|
30
|
+
sleep @interval
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def emit_rss
|
35
|
+
begin
|
36
|
+
next_current_time = @current_time
|
37
|
+
rss = RSS::Parser.parse(@url)
|
38
|
+
rss.items.each do |item|
|
39
|
+
record = {}
|
40
|
+
@attrs.each do |attr|
|
41
|
+
record[attr] = item.send(attr) if item.send(attr)
|
42
|
+
end
|
43
|
+
time = Time.parse item.date.to_s
|
44
|
+
if time > @current_time
|
45
|
+
Fluent::Engine.emit @tag, Time.parse(item.date.to_s), record
|
46
|
+
next_current_time = time if time > next_current_time
|
47
|
+
end
|
48
|
+
end
|
49
|
+
@current_time = next_current_time
|
50
|
+
rescue => e
|
51
|
+
log.error e
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
+
require 'fluent/plugin/in_rss'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class RSSInputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_driver(conf)
|
9
|
+
Fluent::Test::InputTestDriver.new(Fluent::RSSInput).configure(conf)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_configure_full
|
13
|
+
d = create_driver %q{
|
14
|
+
tag test
|
15
|
+
url http://example.com/example.rss
|
16
|
+
interval 10m
|
17
|
+
attrs date, title
|
18
|
+
}
|
19
|
+
|
20
|
+
assert_equal 'test', d.instance.tag
|
21
|
+
assert_equal 'http://example.com/example.rss', d.instance.url
|
22
|
+
assert_equal 10 * 60, d.instance.interval
|
23
|
+
assert_equal ['date', 'title'], d.instance.attrs
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_configure_error_when_config_is_empty
|
27
|
+
assert_raise(Fluent::ConfigError) do
|
28
|
+
create_driver ''
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-rss
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- harukasan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: fluentd
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Fluent input plugin to fetch RSS feed items.
|
56
|
+
email:
|
57
|
+
- harukasan@pixiv.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- fluent-plugin-rss.gemspec
|
68
|
+
- lib/fluent/plugin/in_rss.rb
|
69
|
+
- test/helper.rb
|
70
|
+
- test/plugin/test_in_rss.rb
|
71
|
+
homepage: https://github.com/harukasan/fluent-plugin-rss
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.0
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Fluent input plugin to fetch RSS feed items
|
95
|
+
test_files:
|
96
|
+
- test/helper.rb
|
97
|
+
- test/plugin/test_in_rss.rb
|