automatic 14.1.0 → 14.2.0
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 +4 -4
- data/Gemfile +3 -2
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/automatic.gemspec +17 -9
- data/bin/automatic +4 -4
- data/doc/ChangeLog +27 -0
- data/doc/PLUGINS +36 -6
- data/doc/PLUGINS.ja +35 -7
- data/doc/README +4 -4
- data/doc/README.ja +3 -3
- data/lib/automatic.rb +2 -1
- data/lib/automatic/feed_maker.rb +80 -0
- data/lib/automatic/feed_parser.rb +6 -50
- data/lib/automatic/recipe.rb +1 -1
- data/lib/automatic/version.rb +1 -1
- data/plugins/filter/accept.rb +4 -3
- data/plugins/filter/github_feed.rb +12 -11
- data/plugins/filter/ignore.rb +3 -3
- data/plugins/filter/image_source.rb +10 -10
- data/plugins/filter/one.rb +4 -3
- data/plugins/filter/rand.rb +3 -3
- data/plugins/filter/sanitize.rb +2 -3
- data/plugins/provide/fluentd.rb +5 -4
- data/plugins/publish/amazon_s3.rb +58 -0
- data/plugins/publish/fluentd.rb +5 -4
- data/plugins/publish/google_calendar.rb +2 -2
- data/plugins/publish/hipchat.rb +1 -1
- data/plugins/publish/twitter.rb +1 -1
- data/plugins/store/database.rb +4 -4
- data/plugins/store/file.rb +95 -0
- data/plugins/store/full_text.rb +1 -1
- data/plugins/store/permalink.rb +1 -1
- data/plugins/subscription/feed.rb +2 -2
- data/plugins/subscription/g_guide.rb +3 -2
- data/plugins/subscription/link.rb +4 -3
- data/plugins/subscription/pocket.rb +12 -11
- data/plugins/subscription/text.rb +35 -44
- data/plugins/subscription/tumblr.rb +3 -3
- data/plugins/subscription/twitter.rb +1 -1
- data/plugins/subscription/twitter_search.rb +11 -12
- data/plugins/subscription/weather.rb +7 -6
- data/plugins/subscription/xml.rb +4 -3
- data/spec/fixtures/sampleFeeds.tsv +1 -0
- data/spec/fixtures/sampleFeeds2.tsv +2 -0
- data/spec/lib/automatic/pipeline_spec.rb +4 -4
- data/spec/lib/automatic_spec.rb +3 -3
- data/spec/plugins/filter/github_feed_spec.rb +9 -8
- data/spec/plugins/filter/image_source_spec.rb +7 -7
- data/spec/plugins/notify/ikachan_spec.rb +3 -3
- data/spec/plugins/provide/fluentd_spec.rb +6 -5
- data/spec/plugins/publish/amazon_s3_spec.rb +40 -0
- data/spec/plugins/publish/console_spec.rb +3 -3
- data/spec/plugins/publish/fluentd_spec.rb +5 -4
- data/spec/plugins/publish/google_calendar_spec.rb +5 -5
- data/spec/plugins/publish/hatena_bookmark_spec.rb +10 -10
- data/spec/plugins/publish/hipchat_spec.rb +6 -6
- data/spec/plugins/publish/instapaper_spec.rb +6 -6
- data/spec/plugins/publish/memcached_spec.rb +3 -3
- data/spec/plugins/publish/pocket_spec.rb +3 -3
- data/spec/plugins/publish/twitter_spec.rb +4 -4
- data/spec/plugins/store/{target_link_spec.rb → file_spec.rb} +10 -10
- data/spec/plugins/subscription/pocket_spec.rb +3 -3
- data/spec/plugins/subscription/text_spec.rb +32 -2
- data/spec/plugins/subscription/twitter_search_spec.rb +3 -3
- data/test/integration/test_fluentd.yml +1 -0
- data/test/integration/test_image2local.yml +6 -2
- data/test/integration/test_text2feed.yml +8 -0
- data/test/integration/test_tumblr2local.yml +6 -0
- metadata +26 -7
- data/plugins/store/target_link.rb +0 -55
data/lib/automatic.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# Name:: Automatic::Ruby
|
3
3
|
# Author:: 774 <http://id774.net>
|
4
4
|
# Created:: Feb 18, 2012
|
5
|
-
# Updated::
|
5
|
+
# Updated:: Feb 21, 2014
|
6
6
|
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
7
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
8
|
|
@@ -12,6 +12,7 @@ module Automatic
|
|
12
12
|
require 'automatic/pipeline'
|
13
13
|
require 'automatic/log'
|
14
14
|
require 'automatic/feed_parser'
|
15
|
+
require 'automatic/feed_maker'
|
15
16
|
require 'automatic/version'
|
16
17
|
|
17
18
|
USER_DIR = "/.automatic"
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Name:: Automatic::FeedMaker
|
3
|
+
# Author:: 774 <http://id774.net>
|
4
|
+
# Created:: Feb 21, 2014
|
5
|
+
# Updated:: Feb 26, 2014
|
6
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
|
+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
|
+
|
9
|
+
module Automatic
|
10
|
+
module FeedMaker
|
11
|
+
require 'rss'
|
12
|
+
require 'uri'
|
13
|
+
require 'nokogiri'
|
14
|
+
|
15
|
+
class FeedObject
|
16
|
+
attr_accessor :title, :link, :description, :author, :comments
|
17
|
+
def initialize
|
18
|
+
@link = 'http://dummy'
|
19
|
+
@title = 'dummy'
|
20
|
+
@description = ''
|
21
|
+
@author = ''
|
22
|
+
@comments = ''
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.generate_feed(feed)
|
27
|
+
feed_object = FeedObject.new
|
28
|
+
feed_object.title = feed['title'] unless feed['title'].nil?
|
29
|
+
feed_object.link = feed['url'] unless feed['url'].nil?
|
30
|
+
feed_object.description = feed['description'] unless feed['description'].nil?
|
31
|
+
feed_object.author = feed['author'] unless feed['author'].nil?
|
32
|
+
feed_object.comments = feed['comments'] unless feed['comments'].nil?
|
33
|
+
feed_object
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.create_pipeline(feeds = [])
|
37
|
+
RSS::Maker.make("2.0") {|maker|
|
38
|
+
xss = maker.xml_stylesheets.new_xml_stylesheet
|
39
|
+
maker.channel.title = "Automatic Ruby"
|
40
|
+
maker.channel.description = "Automatic::FeedMaker"
|
41
|
+
maker.channel.link = "https://github.com/automaticruby/automaticruby"
|
42
|
+
maker.items.do_sort = true
|
43
|
+
|
44
|
+
unless feeds.nil?
|
45
|
+
feeds.each {|feed|
|
46
|
+
unless feed.link.nil?
|
47
|
+
Automatic::Log.puts("info", "Create Pipeline: #{feed.link}")
|
48
|
+
item = maker.items.new_item
|
49
|
+
item.title = feed.title
|
50
|
+
item.link = feed.link
|
51
|
+
begin
|
52
|
+
item.description = feed.description
|
53
|
+
item.author = feed.author
|
54
|
+
item.comments = feed.comments
|
55
|
+
item.date = feed.pubDate || Time.now
|
56
|
+
rescue NoMethodError
|
57
|
+
Automatic::Log.puts("warn", "Undefined field detected in feed.")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.content_provide(url, data)
|
66
|
+
RSS::Maker.make("2.0") {|maker|
|
67
|
+
xss = maker.xml_stylesheets.new_xml_stylesheet
|
68
|
+
maker.channel.title = "Automatic Ruby"
|
69
|
+
maker.channel.description = "Automatic::FeedMaker"
|
70
|
+
maker.channel.link = "https://github.com/automaticruby/automaticruby"
|
71
|
+
maker.items.do_sort = true
|
72
|
+
item = maker.items.new_item
|
73
|
+
item.title = "Automatic Ruby"
|
74
|
+
item.link = url
|
75
|
+
item.content_encoded = data
|
76
|
+
item.date = Time.now
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
# Name:: Automatic::FeedParser
|
3
3
|
# Author:: 774 <http://id774.net>
|
4
4
|
# Created:: Feb 19, 2012
|
5
|
-
# Updated::
|
6
|
-
# Copyright:: Copyright (c) 2012-
|
5
|
+
# Updated:: Feb 26, 2014
|
6
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
7
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
8
|
|
9
9
|
module Automatic
|
@@ -12,10 +12,10 @@ module Automatic
|
|
12
12
|
require 'uri'
|
13
13
|
require 'nokogiri'
|
14
14
|
|
15
|
-
def self.
|
15
|
+
def self.get_url(url)
|
16
16
|
begin
|
17
17
|
unless url.nil?
|
18
|
-
Automatic::Log.puts("info", "Parsing: #{url}")
|
18
|
+
Automatic::Log.puts("info", "Parsing Feed: #{url}")
|
19
19
|
feed = URI.parse(url).normalize
|
20
20
|
open(feed) {|http|
|
21
21
|
response = http.read
|
@@ -27,40 +27,11 @@ module Automatic
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.
|
30
|
+
def self.parse_html(html)
|
31
31
|
RSS::Maker.make("2.0") {|maker|
|
32
32
|
xss = maker.xml_stylesheets.new_xml_stylesheet
|
33
33
|
maker.channel.title = "Automatic Ruby"
|
34
|
-
maker.channel.description = "Automatic
|
35
|
-
maker.channel.link = "https://github.com/automaticruby/automaticruby"
|
36
|
-
maker.items.do_sort = true
|
37
|
-
|
38
|
-
unless feeds.nil?
|
39
|
-
feeds.each {|feed|
|
40
|
-
unless feed.link.nil?
|
41
|
-
Automatic::Log.puts("info", "Feed: #{feed.link}")
|
42
|
-
item = maker.items.new_item
|
43
|
-
item.title = feed.title
|
44
|
-
item.link = feed.link
|
45
|
-
begin
|
46
|
-
item.description = feed.description
|
47
|
-
item.author = feed.author
|
48
|
-
item.comments = feed.comments
|
49
|
-
item.date = feed.pubDate || Time.now
|
50
|
-
rescue NoMethodError
|
51
|
-
Automatic::Log.puts("warn", "Undefined field detected in feed.")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
}
|
55
|
-
end
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.parse(html)
|
60
|
-
RSS::Maker.make("2.0") {|maker|
|
61
|
-
xss = maker.xml_stylesheets.new_xml_stylesheet
|
62
|
-
maker.channel.title = "Automatic Ruby"
|
63
|
-
maker.channel.description = "Automatic Ruby"
|
34
|
+
maker.channel.description = "Automatic::FeedParser"
|
64
35
|
maker.channel.link = "https://github.com/automaticruby/automaticruby"
|
65
36
|
maker.items.do_sort = true
|
66
37
|
|
@@ -76,20 +47,5 @@ module Automatic
|
|
76
47
|
}
|
77
48
|
}
|
78
49
|
end
|
79
|
-
|
80
|
-
def self.content_provide(url, data)
|
81
|
-
RSS::Maker.make("2.0") {|maker|
|
82
|
-
xss = maker.xml_stylesheets.new_xml_stylesheet
|
83
|
-
maker.channel.title = "Automatic Ruby"
|
84
|
-
maker.channel.description = "Automatic Ruby"
|
85
|
-
maker.channel.link = "https://github.com/automaticruby/automaticruby"
|
86
|
-
maker.items.do_sort = true
|
87
|
-
item = maker.items.new_item
|
88
|
-
item.title = "Automatic Ruby"
|
89
|
-
item.link = url
|
90
|
-
item.content_encoded = data
|
91
|
-
item.date = Time.now
|
92
|
-
}
|
93
|
-
end
|
94
50
|
end
|
95
51
|
end
|
data/lib/automatic/recipe.rb
CHANGED
@@ -24,7 +24,7 @@ module Automatic
|
|
24
24
|
@procedure = Hashie::Mash.new(YAML.load(File.read(path)))
|
25
25
|
log_level = @procedure.global && @procedure.global.log && @procedure.global.log.level
|
26
26
|
Automatic::Log.level(log_level)
|
27
|
-
Automatic::Log.puts("info", "Loading: #{path}")
|
27
|
+
Automatic::Log.puts("info", "Loading Recipe: #{path}")
|
28
28
|
@procedure
|
29
29
|
end
|
30
30
|
|
data/lib/automatic/version.rb
CHANGED
data/plugins/filter/accept.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
# Name:: Automatic::Plugin::Filter::Accept
|
3
3
|
# Author:: soramugi <http://soramugi.net>
|
4
|
+
# 774 <http://id774.net>
|
4
5
|
# Created:: Jun 4, 2013
|
5
|
-
# Updated::
|
6
|
-
# Copyright:: Copyright (c) 2012-
|
6
|
+
# Updated:: Feb 21, 2014
|
7
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
8
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
9
|
|
9
10
|
module Automatic::Plugin
|
@@ -22,7 +23,7 @@ module Automatic::Plugin
|
|
22
23
|
new_feeds << items if contain(items) == true
|
23
24
|
}
|
24
25
|
end
|
25
|
-
@return_feeds << Automatic::
|
26
|
+
@return_feeds << Automatic::FeedMaker.create_pipeline(new_feeds) if new_feeds.length > 0
|
26
27
|
}
|
27
28
|
@return_feeds
|
28
29
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
# Name:: Automatic::Plugin::Filter::GithubFeed
|
3
3
|
# Author:: Kohei Hasegawa <http://github.com/banyan>
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
4
|
+
# 774 <http://id774.net>
|
5
|
+
# Created:: Jun 6, 2013
|
6
|
+
# Updated:: Feb 21, 2014
|
7
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
8
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
9
|
|
9
10
|
module Automatic::Plugin
|
@@ -17,20 +18,20 @@ module Automatic::Plugin
|
|
17
18
|
def run
|
18
19
|
@return_feeds = []
|
19
20
|
@pipeline.each {|feeds|
|
20
|
-
|
21
|
+
new_feeds = []
|
21
22
|
unless feeds.nil?
|
22
23
|
feeds.items.each {|feed|
|
23
24
|
Automatic::Log.puts("info", "Invoked: FilterGithubFeed")
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
hashie = Hashie::Mash.new
|
26
|
+
hashie.title = feed.title.content
|
27
|
+
hashie.link = feed.id.content
|
28
|
+
hashie.description = feed.content.content
|
29
|
+
new_feeds << hashie
|
29
30
|
}
|
30
31
|
end
|
31
|
-
@return_feeds << Automatic::
|
32
|
+
@return_feeds << Automatic::FeedMaker.create_pipeline(new_feeds)
|
32
33
|
}
|
33
|
-
@
|
34
|
+
@return_feeds
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
data/plugins/filter/ignore.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
# Name:: Automatic::Plugin::Filter::Ignore
|
3
3
|
# Author:: 774 <http://id774.net>
|
4
4
|
# Created:: Feb 22, 2012
|
5
|
-
# Updated::
|
6
|
-
# Copyright:: Copyright (c) 2012-
|
5
|
+
# Updated:: Feb 21, 2014
|
6
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
7
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
8
|
|
9
9
|
module Automatic::Plugin
|
@@ -22,7 +22,7 @@ module Automatic::Plugin
|
|
22
22
|
new_feeds << items if exclude(items) == false
|
23
23
|
}
|
24
24
|
end
|
25
|
-
@return_feeds << Automatic::
|
25
|
+
@return_feeds << Automatic::FeedMaker.create_pipeline(new_feeds) if new_feeds.length > 0
|
26
26
|
}
|
27
27
|
@return_feeds
|
28
28
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
# Name:: Automatic::Plugin::Filter::ImageSource
|
3
3
|
# Author:: 774 <http://id774.net>
|
4
4
|
# Created:: Feb 28, 2012
|
5
|
-
# Updated::
|
6
|
-
# Copyright:: Copyright (c) 2012-
|
5
|
+
# Updated:: Feb 26, 2014
|
6
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
7
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
8
|
|
9
9
|
module Automatic::Plugin
|
@@ -19,24 +19,24 @@ module Automatic::Plugin
|
|
19
19
|
def run
|
20
20
|
@return_feeds = []
|
21
21
|
@pipeline.each {|feeds|
|
22
|
-
|
22
|
+
new_feeds = Array.new
|
23
23
|
unless feeds.nil?
|
24
24
|
feeds.items.each {|feed|
|
25
25
|
arr = rewrite_link(feed)
|
26
26
|
if arr.length > 0
|
27
27
|
arr.each {|link|
|
28
|
-
Automatic::Log.puts("info", "
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
Automatic::Log.puts("info", "Extract Image: #{link}")
|
29
|
+
hashie = Hashie::Mash.new
|
30
|
+
hashie.title = 'FilterImageSource'
|
31
|
+
hashie.link = link
|
32
|
+
new_feeds << hashie
|
33
33
|
}
|
34
34
|
end
|
35
35
|
}
|
36
36
|
end
|
37
|
-
@return_feeds << Automatic::
|
37
|
+
@return_feeds << Automatic::FeedMaker.create_pipeline(new_feeds)
|
38
38
|
}
|
39
|
-
@
|
39
|
+
@return_feeds
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
data/plugins/filter/one.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
# Name:: Automatic::Plugin::Filter::One
|
3
3
|
# Author:: soramugi <http://soramugi.net>
|
4
|
+
# 774 <http://id774.net>
|
4
5
|
# Created:: May 8, 2013
|
5
|
-
# Updated::
|
6
|
-
# Copyright:: Copyright (c) 2012-
|
6
|
+
# Updated:: Feb 21, 2014
|
7
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
8
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
9
|
|
9
10
|
module Automatic::Plugin
|
@@ -27,7 +28,7 @@ module Automatic::Plugin
|
|
27
28
|
if item.count == 0
|
28
29
|
item << feed.items.shift
|
29
30
|
end
|
30
|
-
@return_feeds << Automatic::
|
31
|
+
@return_feeds << Automatic::FeedMaker.create_pipeline(item)
|
31
32
|
end
|
32
33
|
}
|
33
34
|
@return_feeds
|
data/plugins/filter/rand.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# Author:: soramugi <http://soramugi.net>
|
4
4
|
# 774 <http://id774.net>
|
5
5
|
# Created:: Mar 6, 2013
|
6
|
-
# Updated::
|
7
|
-
# Copyright:: Copyright (c) 2012-
|
6
|
+
# Updated:: Feb 21, 2014
|
7
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
8
8
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
9
9
|
|
10
10
|
module Automatic::Plugin
|
@@ -19,7 +19,7 @@ module Automatic::Plugin
|
|
19
19
|
@return_feeds = []
|
20
20
|
@pipeline.each {|feed|
|
21
21
|
unless feed.nil?
|
22
|
-
@return_feeds << Automatic::
|
22
|
+
@return_feeds << Automatic::FeedMaker.create_pipeline(feed.items.shuffle)
|
23
23
|
end
|
24
24
|
}
|
25
25
|
@return_feeds
|
data/plugins/filter/sanitize.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
# Name:: Automatic::Plugin::Filter::Sanitize
|
3
3
|
# Author:: 774 <http://id774.net>
|
4
4
|
# Created:: Jun 20, 2013
|
5
|
-
# Updated::
|
6
|
-
# Copyright:: Copyright (c) 2012-
|
5
|
+
# Updated:: Feb 21, 2014
|
6
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
7
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
8
|
|
9
9
|
module Automatic::Plugin
|
@@ -26,7 +26,6 @@ module Automatic::Plugin
|
|
26
26
|
def run
|
27
27
|
@return_feeds = []
|
28
28
|
@pipeline.each {|feeds|
|
29
|
-
return_feed_items = []
|
30
29
|
unless feeds.nil?
|
31
30
|
feeds.items.each {|feed|
|
32
31
|
feed = sanitize(feed)
|
data/plugins/provide/fluentd.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
# Name:: Automatic::Plugin::Provide::Fluentd
|
3
3
|
# Author:: 774 <http://id774.net>
|
4
4
|
# Created:: Jul 12, 2013
|
5
|
-
# Updated::
|
6
|
-
# Copyright:: Copyright (c) 2012-
|
5
|
+
# Updated:: Feb 25, 2014
|
6
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
7
|
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
8
|
|
9
9
|
module Automatic::Plugin
|
@@ -14,9 +14,10 @@ module Automatic::Plugin
|
|
14
14
|
def initialize(config, pipeline=[])
|
15
15
|
@config = config
|
16
16
|
@pipeline = pipeline
|
17
|
+
@mode = @config['mode']
|
17
18
|
@fluentd = Fluent::Logger::FluentLogger.open(nil,
|
18
19
|
host = @config['host'],
|
19
|
-
port = @config['port'])
|
20
|
+
port = @config['port']) unless @mode == 'test'
|
20
21
|
end
|
21
22
|
|
22
23
|
def run
|
@@ -24,7 +25,7 @@ module Automatic::Plugin
|
|
24
25
|
unless feeds.nil?
|
25
26
|
feeds.items.each {|feed|
|
26
27
|
begin
|
27
|
-
@fluentd.post(@config['tag'], feed.content_encoded)
|
28
|
+
@fluentd.post(@config['tag'], feed.content_encoded) unless @mode == 'test'
|
28
29
|
rescue
|
29
30
|
Automatic::Log.puts("error", "Fluent::Logger.post failed, the content_encoded of item may be not kind of Hash.")
|
30
31
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Name:: Automatic::Plugin::Publish::AmazonS3
|
3
|
+
# Author:: 774 <http://id774.net>
|
4
|
+
# Created:: Feb 24, 2014
|
5
|
+
# Updated:: Feb 24, 2014
|
6
|
+
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
|
7
|
+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
8
|
+
|
9
|
+
module Automatic::Plugin
|
10
|
+
class PublishAmazonS3
|
11
|
+
require 'uri'
|
12
|
+
require 'aws-sdk'
|
13
|
+
|
14
|
+
def initialize(config, pipeline=[])
|
15
|
+
@config = config
|
16
|
+
@pipeline = pipeline
|
17
|
+
s3 = AWS::S3.new(
|
18
|
+
:access_key_id => @config['access_key'],
|
19
|
+
:secret_access_key => @config['secret_key']
|
20
|
+
)
|
21
|
+
@bucket = s3.buckets[@config['bucket_name']]
|
22
|
+
@mode = @config['mode']
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
@pipeline.each {|feeds|
|
27
|
+
unless feeds.nil?
|
28
|
+
feeds.items.each {|feed|
|
29
|
+
unless feed.link.nil?
|
30
|
+
begin
|
31
|
+
uri = URI.parse(feed.link)
|
32
|
+
if uri.scheme == 'file'
|
33
|
+
upload_amazons3(uri.path, @config['target_path'])
|
34
|
+
else
|
35
|
+
Automatic::Log.puts("warn", "Skip feed due to uri scheme is not file.")
|
36
|
+
end
|
37
|
+
rescue
|
38
|
+
Automatic::Log.puts("error", "Error detected with #{feed.link} in uploading AmazonS3.")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
}
|
42
|
+
end
|
43
|
+
}
|
44
|
+
@pipeline
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def upload_amazons3(filename, target_path)
|
50
|
+
target = File.join(target_path, File.basename(filename))
|
51
|
+
object = @bucket.objects[target]
|
52
|
+
source = Pathname.new(filename)
|
53
|
+
object.write(source) unless @mode == "test"
|
54
|
+
Automatic::Log.puts("info", "Uploaded: file #{source} to the bucket #{target} on #{@bucket.name}.")
|
55
|
+
return source, target
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|