rss2mail 0.1.0 → 0.1.1

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.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to rss2mail version 0.1.0
5
+ This documentation refers to rss2mail version 0.1.1
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/lib/rss2mail/feed.rb CHANGED
@@ -28,12 +28,12 @@ require 'erb'
28
28
  require 'nuggets/file/which'
29
29
  require 'nuggets/string/evaluate'
30
30
 
31
- require 'rss2mail/rss'
32
-
33
31
  module RSS2Mail
34
32
 
35
33
  class Feed
36
34
 
35
+ include Util
36
+
37
37
  HOST = ENV['HOSTNAME'] || ENV['HOST'] || %x{hostname}.chomp
38
38
 
39
39
  attr_reader :feed, :reload, :verbose, :debug, :simple, :updated, :content, :rss
@@ -146,7 +146,7 @@ module RSS2Mail
146
146
  log conditions.inspect, debug
147
147
 
148
148
  begin
149
- open(feed[:url], conditions) { |uri|
149
+ open_feed(feed[:url], conditions) { |uri|
150
150
  if etag = uri.meta['etag']
151
151
  feed[:etag] = etag
152
152
  end
data/lib/rss2mail/rss.rb CHANGED
@@ -27,7 +27,6 @@
27
27
  #++
28
28
 
29
29
  require 'rss'
30
- require 'open-uri'
31
30
  require 'simple-rss'
32
31
  require 'unidecode'
33
32
  require 'nuggets/util/i18n'
@@ -42,7 +41,7 @@ module RSS2Mail
42
41
 
43
42
  class RSS
44
43
 
45
- USER_AGENT = "RSS2Mail/#{VERSION}".freeze
44
+ include Util
46
45
 
47
46
  SUBSTITUTIONS = {
48
47
  '–' => '--',
@@ -57,7 +56,7 @@ module RSS2Mail
57
56
  attr_reader :content, :rss
58
57
 
59
58
  def self.parse(url, *args)
60
- new(open(url, 'User-Agent' => USER_AGENT), *args)
59
+ new(open_feed(url), *args)
61
60
  end
62
61
 
63
62
  def initialize(content, simple = false)
@@ -118,7 +117,7 @@ module RSS2Mail
118
117
  end
119
118
 
120
119
  def subject
121
- @subject ||= title ? clean_subject(title) : 'NO TITLE'
120
+ @subject ||= title ? clean_subject(title.dup) : 'NO TITLE'
122
121
  end
123
122
 
124
123
  private
@@ -165,7 +164,7 @@ module RSS2Mail
165
164
  def get_body(tag, encoding)
166
165
  body = case tag
167
166
  when nil then return
168
- when true then open(link).read
167
+ when true then open_feed(link).read
169
168
  when String then extract_body(tag)
170
169
  when Array then extract_body(*tag)
171
170
  else raise ArgumentError, "don't know how to handle tag of type #{tag.class}"
@@ -179,19 +178,18 @@ module RSS2Mail
179
178
 
180
179
  def extract_body(expr, attribute = nil)
181
180
  if defined?(Hpricot)
182
- elem = Hpricot(open(link)).at(expr)
181
+ elem = Hpricot(open_feed(link)).at(expr)
183
182
  attribute ? elem[attribute] : elem.to_s
184
183
  else
185
- open(link).read
184
+ open_feed(link).read
186
185
  end
187
186
  end
188
187
 
189
- def clean_subject(string)
190
- string.
191
- replace_diacritics.
192
- gsub(SUBSTITUTIONS_RE) { |m| SUBSTITUTIONS[m] }.
193
- to_ascii.
194
- gsub(/'/, "'\\\\''")
188
+ def clean_subject(str)
189
+ str.replace_diacritics!
190
+ str.gsub!(SUBSTITUTIONS_RE) { |m| SUBSTITUTIONS[m] }
191
+ str.gsub!(/'/, "'\\\\''")
192
+ str.to_ascii
195
193
  end
196
194
 
197
195
  end
data/lib/rss2mail/util.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # A component of rss2mail, the RSS to e-mail forwarder. #
5
5
  # #
6
- # Copyright (C) 2007-2011 Jens Wille #
6
+ # Copyright (C) 2007-2012 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <ww@blackwinter.de> #
@@ -28,23 +28,27 @@ require 'uri'
28
28
  require 'open-uri'
29
29
  require 'hpricot'
30
30
 
31
+ require 'rss2mail/version'
32
+
31
33
  module RSS2Mail
32
34
 
33
35
  module Util
34
36
 
35
37
  extend self
36
38
 
37
- FEED_REGEXP = %r{\Aapplication/(?:atom|rss)\+xml\z}io
39
+ USER_AGENT = "RSS2Mail/#{VERSION}".freeze
40
+
41
+ FEED_RE = %r{\Aapplication/(?:atom|rss)\+xml\z}i
38
42
 
39
43
  # cf. <http://www.rssboard.org/rss-autodiscovery>
40
44
  def discover_feed(url, or_self = false)
41
45
  default = or_self ? url : nil
42
46
 
43
47
  unless url.nil? || url.empty? || url == 'about:blank'
44
- doc = Hpricot(open(url))
48
+ doc = Hpricot(open_feed(url))
45
49
 
46
50
  if feed_element = doc.search('//link[@rel="alternate"').find { |link|
47
- link[:type] =~ FEED_REGEXP
51
+ link[:type] =~ FEED_RE
48
52
  }
49
53
  if feed_href = feed_element[:href]
50
54
  return feed_href if feed_href =~ URI.regexp(%w[http https])
@@ -58,6 +62,10 @@ module RSS2Mail
58
62
  default
59
63
  end
60
64
 
65
+ def open_feed(url, options = {}, &block)
66
+ open(url, options.merge('User-Agent' => USER_AGENT), &block)
67
+ end
68
+
61
69
  end
62
70
 
63
71
  end
@@ -4,7 +4,7 @@ module RSS2Mail
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 0
7
+ TINY = 1
8
8
 
9
9
  class << self
10
10
 
data/lib/rss2mail.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # rss2mail -- Send RSS feeds as e-mail #
5
5
  # #
6
- # Copyright (C) 2007-2011 Jens Wille #
6
+ # Copyright (C) 2007-2012 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <ww@blackwinter.de> #
@@ -24,8 +24,9 @@
24
24
  ###############################################################################
25
25
  #++
26
26
 
27
+ require 'rss2mail/util'
27
28
  require 'rss2mail/feed'
28
- require 'rss2mail/version'
29
+ require 'rss2mail/rss'
29
30
 
30
31
  module RSS2Mail
31
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rss2mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-17 00:00:00.000000000 Z
12
+ date: 2012-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simple-rss
@@ -107,7 +107,7 @@ rdoc_options:
107
107
  - --line-numbers
108
108
  - --all
109
109
  - --title
110
- - rss2mail Application documentation (v0.1.0)
110
+ - rss2mail Application documentation (v0.1.1)
111
111
  - --main
112
112
  - README
113
113
  require_paths: