rrimm 0.2.0 → 0.3.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.lock +1 -1
- data/lib/rrimm/config.rb +22 -1
- data/lib/rrimm/feed.rb +4 -0
- data/lib/rrimm/item_formatter/mail.rb +9 -5
- data/rrimm.gemspec +1 -1
- data/spec/xkcd.xml +2 -0
- data/spec/xkcd_spec.rb +34 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb036536a321e067fc90a265804b35c33fa73c7e
|
4
|
+
data.tar.gz: 795bf60b495b3dca4d30f66a742568b84cdb8a9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5111bb5488f6ae6804b8fb765384420e2eb512ec8c2b5d5a9ca2b0a726f3f3c9c7e1f1d3f93db79cebd6d7d77884f6f83720359e8c8bbd0f8db04682ec0191d8
|
7
|
+
data.tar.gz: debc92ba0768fd0f993a4d5033ee71881ef17d203d7ca4f9158fe4e6a427bf1fdbeb42efe08b3a2d9686e48462360d1d94b532ae82af595f141f197ffb91039f
|
data/Gemfile.lock
CHANGED
data/lib/rrimm/config.rb
CHANGED
@@ -27,7 +27,11 @@ module RRImm
|
|
27
27
|
|
28
28
|
puts "Feeds:"
|
29
29
|
@feeds.values.group_by { |f| f.category }.map do |cat, feeds|
|
30
|
-
|
30
|
+
if cat.nil? or cat.empty?
|
31
|
+
puts ""
|
32
|
+
else
|
33
|
+
puts "#{cat}:"
|
34
|
+
end
|
31
35
|
feeds.each do |feed|
|
32
36
|
fqdn = [feed.name]
|
33
37
|
fqdn << feed.uri unless feed.name.eql? feed.uri
|
@@ -65,6 +69,23 @@ module RRImm
|
|
65
69
|
@feeds[name] = feed_def
|
66
70
|
end
|
67
71
|
|
72
|
+
def category(cat_name, &block)
|
73
|
+
Feed.module_eval do
|
74
|
+
@@tmp_cat_name = cat_name
|
75
|
+
alias :old_initialize :initialize
|
76
|
+
def initialize(feed_name)
|
77
|
+
old_initialize(feed_name)
|
78
|
+
@category = @@tmp_cat_name
|
79
|
+
end
|
80
|
+
end
|
81
|
+
self.instance_eval(&block) if block
|
82
|
+
ensure
|
83
|
+
Feed.module_eval do
|
84
|
+
alias :initialize :old_initialize
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
68
89
|
def load(file)
|
69
90
|
instance_eval(File.read(file), file)
|
70
91
|
end
|
data/lib/rrimm/feed.rb
CHANGED
@@ -9,14 +9,18 @@ module RRImm
|
|
9
9
|
@sender = hash[:from]
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
if
|
14
|
-
|
12
|
+
def default_author(feed_config)
|
13
|
+
if feed_config.default_name?
|
14
|
+
"RRImm <#{@sender}>"
|
15
15
|
else
|
16
|
-
@sender
|
16
|
+
"#{feed_config.name} <#{@sender}>"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
def from(authors)
|
21
|
+
authors.compact.select { |a| a.include? '@' }.first
|
22
|
+
end
|
23
|
+
|
20
24
|
def subject(feed, item, feed_config)
|
21
25
|
subject = item.title
|
22
26
|
subject = "[#{feed_config.category}]#{item.title}" if feed_config.category
|
@@ -24,7 +28,7 @@ module RRImm
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def format(feed, item, feed_config, pipe)
|
27
|
-
pipe.write "From: #{from(
|
31
|
+
pipe.write "From: #{from [item.author, default_author(feed_config)]}\n"
|
28
32
|
pipe.write "To: #{dest}\n"
|
29
33
|
pipe.write "Subject: #{subject(feed, item, feed_config)}\n"
|
30
34
|
pipe.write "Content-Type: text/html;\n"
|
data/rrimm.gemspec
CHANGED
data/spec/xkcd.xml
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<rss version="2.0"><channel><title>xkcd.com</title><link>http://xkcd.com/</link><description>xkcd.com: A webcomic of romance and math humor.</description><language>en</language><item><title>When You Assume</title><link>http://xkcd.com/1339/</link><description><img src="http://imgs.xkcd.com/comics/when_you_assume.png" title="You know what happens when you assert--you make an ass out of the emergency response team." alt="You know what happens when you assert--you make an ass out of the emergency response team." /></description><pubDate>Fri, 07 Mar 2014 05:00:00 -0000</pubDate><guid>http://xkcd.com/1339/</guid></item><item><title>Land Mammals</title><link>http://xkcd.com/1338/</link><description><img src="http://imgs.xkcd.com/comics/land_mammals.png" title="Bacteria still outweigh us thousands to one--and that's not even counting the several pounds of them in your body." alt="Bacteria still outweigh us thousands to one--and that's not even counting the several pounds of them in your body." /></description><pubDate>Wed, 05 Mar 2014 05:00:00 -0000</pubDate><guid>http://xkcd.com/1338/</guid></item><item><title>Hack</title><link>http://xkcd.com/1337/</link><description><img src="http://imgs.xkcd.com/comics/hack.png" title="HACK THE STARS" alt="HACK THE STARS" /></description><pubDate>Mon, 03 Mar 2014 05:00:00 -0000</pubDate><guid>http://xkcd.com/1337/</guid></item><item><title>Transformers</title><link>http://xkcd.com/1336/</link><description><img src="http://imgs.xkcd.com/comics/transformers.png" title="A helicopter bursts from a chrysalis and alights on a rock, rotors still damp." alt="A helicopter bursts from a chrysalis and alights on a rock, rotors still damp." /></description><pubDate>Fri, 28 Feb 2014 05:00:00 -0000</pubDate><guid>http://xkcd.com/1336/</guid></item></channel></rss>
|
data/spec/xkcd_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe RRImm::ItemFormatter::Mail do
|
5
|
+
it 'formats correctly xkcd feed' do
|
6
|
+
mail_formatter = RRImm::ItemFormatter::Mail.new(
|
7
|
+
from: 'from@example.com',
|
8
|
+
to: 'to@example.com'
|
9
|
+
)
|
10
|
+
xkcd_file = File.join('file://', File.dirname(__FILE__), 'xkcd.xml')
|
11
|
+
feed = Feedzirra::Feed.fetch_and_parse(xkcd_file)
|
12
|
+
expect(feed.entries.size).to be > 0
|
13
|
+
s = StringIO.new
|
14
|
+
config = double('config')
|
15
|
+
config.should_receive(:category).and_return nil
|
16
|
+
config.should_receive(:default_name?).and_return(true)
|
17
|
+
mail_formatter.format(feed, feed.entries.first, config, s)
|
18
|
+
s.close
|
19
|
+
expect(s.string).to eq "From: RRImm <from@example.com>\nTo: to@example.com\nSubject: When You Assume\nContent-Type: text/html;\n\nhttp://xkcd.com/1339/\n\n<img src=\"http://imgs.xkcd.com/comics/when_you_assume.png\" title=\"You know what happens when you assert--you make an ass out of the emergency response team.\" alt=\"You know what happens when you assert--you make an ass out of the emergency response team.\" />\n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe RRImm::ItemFormatter::Default do
|
24
|
+
it 'formats correctly xkcd feed' do
|
25
|
+
default_formatter = RRImm::ItemFormatter::Default.new
|
26
|
+
xkcd_file = File.join('file://', File.dirname(__FILE__), 'xkcd.xml')
|
27
|
+
feed = Feedzirra::Feed.fetch_and_parse(xkcd_file)
|
28
|
+
expect(feed.entries.size).to be > 0
|
29
|
+
s = StringIO.new
|
30
|
+
default_formatter.format(feed, feed.entries.first, nil, s)
|
31
|
+
s.close
|
32
|
+
expect(s.string).to eq "xkcd.com: When You Assume (2014-03-07 05:00:00 UTC)\n"
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrimm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grégoire Seux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- spec/config_spec.rb
|
110
110
|
- spec/feed_spec.rb
|
111
111
|
- spec/spec_helper.rb
|
112
|
+
- spec/xkcd.xml
|
113
|
+
- spec/xkcd_spec.rb
|
112
114
|
homepage: http://github.com/kamaradclimber/rrimm
|
113
115
|
licenses:
|
114
116
|
- Apache Licence v2
|
@@ -138,3 +140,5 @@ test_files:
|
|
138
140
|
- spec/config_spec.rb
|
139
141
|
- spec/feed_spec.rb
|
140
142
|
- spec/spec_helper.rb
|
143
|
+
- spec/xkcd.xml
|
144
|
+
- spec/xkcd_spec.rb
|