blackwinter-rss2mail 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of rss2mail, the RSS to e-mail forwarder. #
5
+ # #
6
+ # Copyright (C) 2007-2008 Jens Wille #
7
+ # #
8
+ # Authors: #
9
+ # Jens Wille <ww@blackwinter.de> #
10
+ # #
11
+ # rss2mail is free software; you can redistribute it and/or modify it under #
12
+ # the terms of the GNU General Public License as published by the Free #
13
+ # Software Foundation; either version 3 of the License, or (at your option) #
14
+ # any later version. #
15
+ # #
16
+ # rss2mail is distributed in the hope that it will be useful, but WITHOUT ANY #
17
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
18
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
19
+ # details. #
20
+ # #
21
+ # You should have received a copy of the GNU General Public License along #
22
+ # with rss2mail. If not, see <http://www.gnu.org/licenses/>. #
23
+ # #
24
+ ###############################################################################
25
+ #++
26
+
27
+ require 'rss'
28
+
29
+ require 'rubygems'
30
+ require 'simple-rss'
31
+
32
+ module RSS2Mail
33
+
34
+ class RSS
35
+
36
+ attr_reader :content, :rss
37
+
38
+ def initialize(content, simple = false)
39
+ @content = content
40
+ @simple = simple
41
+
42
+ @rss = simple ? simple_parse : parse
43
+ end
44
+
45
+ def simple?
46
+ @simple
47
+ end
48
+
49
+ def items
50
+ @items ||= rss.items.map { |item| Item.new(item) }
51
+ end
52
+
53
+ def parse
54
+ ::RSS::Parser.parse(content, false) || simple_parse
55
+ end
56
+
57
+ def simple_parse
58
+ SimpleRSS.parse(content)
59
+ end
60
+
61
+ class Item
62
+
63
+ ALIASES = {
64
+ :title => %w[],
65
+ :link => %w[],
66
+ :description => %w[summary content],
67
+ :date => %w[pubDate updated],
68
+ :author => %w[dc_creator]
69
+ }
70
+
71
+ def initialize(item)
72
+ @item = item
73
+ end
74
+
75
+ def method_missing(method, *args, &block)
76
+ if aliases = ALIASES[method]
77
+ [method, *aliases].each { |name|
78
+ begin
79
+ res = @item.send(name)
80
+ return res if res
81
+ rescue NoMethodError
82
+ end
83
+ }
84
+
85
+ nil
86
+ else
87
+ super
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,65 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of rss2mail, the RSS to e-mail forwarder. #
5
+ # #
6
+ # Copyright (C) 2007-2008 Jens Wille #
7
+ # #
8
+ # Authors: #
9
+ # Jens Wille <ww@blackwinter.de> #
10
+ # #
11
+ # rss2mail is free software; you can redistribute it and/or modify it under #
12
+ # the terms of the GNU General Public License as published by the Free #
13
+ # Software Foundation; either version 3 of the License, or (at your option) #
14
+ # any later version. #
15
+ # #
16
+ # rss2mail is distributed in the hope that it will be useful, but WITHOUT ANY #
17
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
18
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
19
+ # details. #
20
+ # #
21
+ # You should have received a copy of the GNU General Public License along #
22
+ # with rss2mail. If not, see <http://www.gnu.org/licenses/>. #
23
+ # #
24
+ ###############################################################################
25
+ #++
26
+
27
+ require 'open-uri'
28
+ require 'uri'
29
+
30
+ require 'rubygems'
31
+ require 'hpricot'
32
+
33
+ module RSS2Mail
34
+
35
+ module Util
36
+
37
+ extend self
38
+
39
+ FEED_REGEXP = %r{\Aapplication/(?:atom|rss)\+xml\z}io
40
+
41
+ # cf. <http://www.rssboard.org/rss-autodiscovery>
42
+ def discover_feed(url, or_self = false)
43
+ default = or_self ? url : nil
44
+
45
+ unless url.nil? || url.empty? || url == 'about:blank'
46
+ doc = Hpricot(open(url))
47
+
48
+ if feed_element = doc.search('//link[@rel="alternate"').find { |link|
49
+ link[:type] =~ FEED_REGEXP
50
+ }
51
+ if feed_href = feed_element[:href]
52
+ return feed_href if feed_href =~ URI.regexp(%w[http https])
53
+
54
+ base_href = doc.at('base')[:href] rescue url
55
+ return URI.join(base_href, feed_href).to_s
56
+ end
57
+ end
58
+ end
59
+
60
+ default
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,27 @@
1
+ module RSS2Mail
2
+
3
+ module Version
4
+
5
+ MAJOR = 0
6
+ MINOR = 0
7
+ TINY = 1
8
+
9
+ class << self
10
+
11
+ # Returns array representation.
12
+ def to_a
13
+ [MAJOR, MINOR, TINY]
14
+ end
15
+
16
+ # Short-cut for version string.
17
+ def to_s
18
+ to_a.join('.')
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+ VERSION = Version.to_s
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blackwinter-rss2mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jens Wille
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-19 00:00:00 -08:00
13
+ default_executable: rss2mail
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: simple-rss
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: hpricot
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: unidecode
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: ruby-nuggets
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ description: Send RSS feeds as e-mail
52
+ email: jens.wille@uni-koeln.de
53
+ executables:
54
+ - rss2mail
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - COPYING
59
+ - ChangeLog
60
+ - README
61
+ files:
62
+ - lib/rss2mail/rss.rb
63
+ - lib/rss2mail/version.rb
64
+ - lib/rss2mail/util.rb
65
+ - lib/rss2mail/feed.rb
66
+ - lib/rss2mail.rb
67
+ - bin/rss2mail
68
+ - Rakefile
69
+ - COPYING
70
+ - ChangeLog
71
+ - README
72
+ - example/feeds.yaml
73
+ has_rdoc: true
74
+ homepage: http://rss2mail.rubyforge.org/
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --line-numbers
78
+ - --inline-source
79
+ - --title
80
+ - rss2mail Application documentation
81
+ - --main
82
+ - README
83
+ - --charset
84
+ - UTF-8
85
+ - --all
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project: rss2mail
103
+ rubygems_version: 1.2.0
104
+ signing_key:
105
+ specification_version: 2
106
+ summary: Send RSS feeds as e-mail
107
+ test_files: []
108
+