rrimm 0.2.0 → 0.3.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: fe165abd85bdd5c571e37e41e89763e500c94a8e
4
- data.tar.gz: 4d1f772e68e92b5a7a6a078aaa5f486919f37522
3
+ metadata.gz: cb036536a321e067fc90a265804b35c33fa73c7e
4
+ data.tar.gz: 795bf60b495b3dca4d30f66a742568b84cdb8a9a
5
5
  SHA512:
6
- metadata.gz: 8a8a4626df8cedb7ffd9677fbfb1c97426755c718cdea89f8fa63c7d5821e322a4ca81925949a912a418779017b5cb318ab05880d21b20f6f2f4ff1a41af44d5
7
- data.tar.gz: 610e769fcf85197cae7429e42f57e80e809617b90934dba572bebbf8b92f2aa7f0534765a11d7f919e157635aeaf5f03d59933d7bbaaaaeacecb74a50574f3e4
6
+ metadata.gz: 5111bb5488f6ae6804b8fb765384420e2eb512ec8c2b5d5a9ca2b0a726f3f3c9c7e1f1d3f93db79cebd6d7d77884f6f83720359e8c8bbd0f8db04682ec0191d8
7
+ data.tar.gz: debc92ba0768fd0f993a4d5033ee71881ef17d203d7ca4f9158fe4e6a427bf1fdbeb42efe08b3a2d9686e48462360d1d94b532ae82af595f141f197ffb91039f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rrimm (0.2.0)
4
+ rrimm (0.3.0)
5
5
  feedzirra
6
6
  open_uri_redirections
7
7
  parallel
@@ -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
- puts "#{cat}:" unless cat.nil? or cat.empty?
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
@@ -37,6 +37,10 @@ module RRImm
37
37
  @uri
38
38
  end
39
39
 
40
+ def default_name?
41
+ @name.eql? @uri
42
+ end
43
+
40
44
  def formatter_class(arg=nil)
41
45
  if arg
42
46
  @formatter_class = arg
@@ -9,14 +9,18 @@ module RRImm
9
9
  @sender = hash[:from]
10
10
  end
11
11
 
12
- def from(item)
13
- if item.author and item.author.include? '@'
14
- item.author
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(item)}\n"
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"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rrimm'
3
- s.version = '0.2.0'
3
+ s.version = '0.3.0'
4
4
  s.licenses = ['Apache Licence v2']
5
5
  s.summary = "RSS to email tool"
6
6
  s.description = "imm reboot in ruby. Retrieve rss feeds and send them by email"
@@ -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>&lt;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." /&gt;</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>&lt;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." /&gt;</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>&lt;img src="http://imgs.xkcd.com/comics/hack.png" title="HACK THE STARS" alt="HACK THE STARS" /&gt;</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>&lt;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." /&gt;</description><pubDate>Fri, 28 Feb 2014 05:00:00 -0000</pubDate><guid>http://xkcd.com/1336/</guid></item></channel></rss>
@@ -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.2.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-09 00:00:00.000000000 Z
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