simple-rss 2.0.0 → 2.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/README.md +321 -0
- data/lib/simple-rss.rb +490 -4
- data/simple-rss.gemspec +4 -4
- data/test/base/enumerable_test.rb +101 -0
- data/test/base/feed_merging_and_diffing_test.rb +140 -0
- data/test/base/fetch_integration_test.rb +25 -0
- data/test/base/fetch_test.rb +90 -0
- data/test/base/filtering_and_validation_test.rb +187 -0
- data/test/base/hash_xml_serialization_test.rb +142 -0
- data/test/base/json_serialization_test.rb +81 -0
- data/test/base/media_and_enclosure_helpers_test.rb +84 -0
- metadata +13 -5
- data/README.markdown +0 -47
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class MediaAndEnclosureHelpersTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@feed = SimpleRSS.parse <<~XML
|
|
6
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
7
|
+
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
|
|
8
|
+
<channel>
|
|
9
|
+
<title>Podcast Feed</title>
|
|
10
|
+
<item>
|
|
11
|
+
<title>Episode 1</title>
|
|
12
|
+
<enclosure url="https://example.com/audio-1.mp3" type="audio/mpeg" length="12345" />
|
|
13
|
+
<media:content url="https://example.com/image-1.jpg" type="image/jpeg" />
|
|
14
|
+
<media:description>Episode image</media:description>
|
|
15
|
+
<media:thumbnail url="https://example.com/thumb-1.jpg" />
|
|
16
|
+
<itunes:duration>00:42:00</itunes:duration>
|
|
17
|
+
<itunes:image href="https://example.com/itunes-1.jpg" />
|
|
18
|
+
</item>
|
|
19
|
+
<item>
|
|
20
|
+
<title>Episode 2</title>
|
|
21
|
+
<media:thumbnail url="https://example.com/thumb-2.jpg" />
|
|
22
|
+
</item>
|
|
23
|
+
<item>
|
|
24
|
+
<title>Episode 3</title>
|
|
25
|
+
<enclosure url="https://example.com/audio-3.mp3" type="audio/mpeg" length="999" />
|
|
26
|
+
</item>
|
|
27
|
+
<item>
|
|
28
|
+
<title>Episode 4</title>
|
|
29
|
+
<enclosure url="" type="audio/mpeg" length="111" />
|
|
30
|
+
<media:thumbnail url="" />
|
|
31
|
+
<itunes:image href="" />
|
|
32
|
+
</item>
|
|
33
|
+
</channel>
|
|
34
|
+
</rss>
|
|
35
|
+
XML
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_enclosures_extracts_podcast_enclosures
|
|
39
|
+
enclosures = @feed.enclosures
|
|
40
|
+
|
|
41
|
+
assert_equal 2, enclosures.size
|
|
42
|
+
assert_equal "https://example.com/audio-1.mp3", enclosures.first[:url]
|
|
43
|
+
assert_equal "audio/mpeg", enclosures.first[:type]
|
|
44
|
+
assert_equal "12345", enclosures.first[:length]
|
|
45
|
+
assert_equal "Episode 1", enclosures.first[:item][:title]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_images_collects_unique_media_urls
|
|
49
|
+
images = @feed.images
|
|
50
|
+
|
|
51
|
+
assert_equal [
|
|
52
|
+
"https://example.com/thumb-1.jpg",
|
|
53
|
+
"https://example.com/image-1.jpg",
|
|
54
|
+
"https://example.com/itunes-1.jpg",
|
|
55
|
+
"https://example.com/thumb-2.jpg"
|
|
56
|
+
], images
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_item_media_helpers
|
|
60
|
+
first_item = @feed.items.first
|
|
61
|
+
second_item = @feed.items[1]
|
|
62
|
+
third_item = @feed.items[2]
|
|
63
|
+
fourth_item = @feed.items.last
|
|
64
|
+
|
|
65
|
+
assert_equal true, first_item.has_media?
|
|
66
|
+
assert_equal "https://example.com/image-1.jpg", first_item.media_url
|
|
67
|
+
|
|
68
|
+
assert_equal true, second_item.has_media?
|
|
69
|
+
assert_equal "https://example.com/thumb-2.jpg", second_item.media_url
|
|
70
|
+
|
|
71
|
+
assert_equal true, third_item.has_media?
|
|
72
|
+
assert_equal "https://example.com/audio-3.mp3", third_item.media_url
|
|
73
|
+
|
|
74
|
+
assert_equal false, fourth_item.has_media?
|
|
75
|
+
assert_nil fourth_item.media_url
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_media_description_and_itunes_duration_are_parsed
|
|
79
|
+
first_item = @feed.items.first
|
|
80
|
+
|
|
81
|
+
assert_equal "Episode image", first_item[:media_description]
|
|
82
|
+
assert_equal "00:42:00", first_item[:itunes_duration]
|
|
83
|
+
end
|
|
84
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple-rss
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lucas Carlson
|
|
@@ -60,7 +60,7 @@ extensions: []
|
|
|
60
60
|
extra_rdoc_files: []
|
|
61
61
|
files:
|
|
62
62
|
- LICENSE
|
|
63
|
-
- README.
|
|
63
|
+
- README.md
|
|
64
64
|
- Rakefile
|
|
65
65
|
- lib/simple-rss.rb
|
|
66
66
|
- simple-rss.gemspec
|
|
@@ -68,8 +68,16 @@ files:
|
|
|
68
68
|
- test/base/base_test.rb
|
|
69
69
|
- test/base/empty_tag_test.rb
|
|
70
70
|
- test/base/encoding_test.rb
|
|
71
|
+
- test/base/enumerable_test.rb
|
|
71
72
|
- test/base/feed_attributes_test.rb
|
|
73
|
+
- test/base/feed_merging_and_diffing_test.rb
|
|
74
|
+
- test/base/fetch_integration_test.rb
|
|
75
|
+
- test/base/fetch_test.rb
|
|
76
|
+
- test/base/filtering_and_validation_test.rb
|
|
77
|
+
- test/base/hash_xml_serialization_test.rb
|
|
72
78
|
- test/base/item_attributes_test.rb
|
|
79
|
+
- test/base/json_serialization_test.rb
|
|
80
|
+
- test/base/media_and_enclosure_helpers_test.rb
|
|
73
81
|
- test/data/atom.xml
|
|
74
82
|
- test/data/atom_with_entry_attrs.xml
|
|
75
83
|
- test/data/atom_with_feed_attrs.xml
|
|
@@ -81,7 +89,7 @@ files:
|
|
|
81
89
|
- test/data/rss20_with_channel_attrs.xml
|
|
82
90
|
- test/data/rss20_with_item_attrs.xml
|
|
83
91
|
- test/test_helper.rb
|
|
84
|
-
homepage:
|
|
92
|
+
homepage: https://github.com/cardmagic/simple-rss
|
|
85
93
|
licenses: []
|
|
86
94
|
metadata: {}
|
|
87
95
|
rdoc_options: []
|
|
@@ -91,14 +99,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
91
99
|
requirements:
|
|
92
100
|
- - ">="
|
|
93
101
|
- !ruby/object:Gem::Version
|
|
94
|
-
version: '
|
|
102
|
+
version: '3.1'
|
|
95
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
104
|
requirements:
|
|
97
105
|
- - ">="
|
|
98
106
|
- !ruby/object:Gem::Version
|
|
99
107
|
version: '0'
|
|
100
108
|
requirements: []
|
|
101
|
-
rubygems_version: 4.0.
|
|
109
|
+
rubygems_version: 4.0.6
|
|
102
110
|
specification_version: 4
|
|
103
111
|
summary: A simple, flexible, extensible, and liberal RSS and Atom reader for Ruby.
|
|
104
112
|
It is designed to be backwards compatible with the standard RSS parser, but will
|
data/README.markdown
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
## Welcome to Simple RSS
|
|
2
|
-
|
|
3
|
-
Simple RSS is a simple, flexible, extensible, and liberal RSS and Atom reader
|
|
4
|
-
for Ruby. It is designed to be backwards compatible with the standard RSS
|
|
5
|
-
parser, but will never do RSS generation.
|
|
6
|
-
|
|
7
|
-
## Download
|
|
8
|
-
|
|
9
|
-
* gem install simple-rss
|
|
10
|
-
* https://github.com/cardmagic/simple-rss
|
|
11
|
-
* git clone git@github.com:cardmagic/simple-rss.git
|
|
12
|
-
|
|
13
|
-
### Usage
|
|
14
|
-
The API is similar to Ruby's standard RSS parser:
|
|
15
|
-
|
|
16
|
-
require 'rubygems'
|
|
17
|
-
require 'simple-rss'
|
|
18
|
-
require 'open-uri'
|
|
19
|
-
|
|
20
|
-
rss = SimpleRSS.parse open('http://rss.slashdot.org/Slashdot/slashdot/to')
|
|
21
|
-
|
|
22
|
-
rss.channel.title # => "Slashdot"
|
|
23
|
-
rss.channel.link # => "http://slashdot.org/"
|
|
24
|
-
rss.items.first.link # => "http://books.slashdot.org/article.pl?sid=05/08/29/1319236&from=rss"
|
|
25
|
-
|
|
26
|
-
But since the parser can read Atom feeds as easily as RSS feeds, there are optional aliases that allow more atom like reading:
|
|
27
|
-
|
|
28
|
-
rss.feed.title # => "Slashdot"
|
|
29
|
-
rss.feed.link # => "http://slashdot.org/"
|
|
30
|
-
rss.entries.first.link # => "http://books.slashdot.org/article.pl?sid=05/08/29/1319236&from=rss"
|
|
31
|
-
|
|
32
|
-
The parser does not care about the correctness of the XML as it does not use an XML library to read the information. Thus it is flexible and allows for easy extending via:
|
|
33
|
-
|
|
34
|
-
SimpleRSS.feed_tags << :some_new_tag
|
|
35
|
-
SimpleRSS.item_tags << :"item+myrel" # this will extend SimpleRSS to be able to parse RSS items or ATOM entries that have a rel specified, common in many blogger feeds
|
|
36
|
-
SimpleRSS.item_tags << :"feedburner:origLink" # this will extend SimpleRSS to be able to parse RSS items or ATOM entries that have a specific pre-tag specified, common in many feedburner feeds
|
|
37
|
-
SimpleRSS.item_tags << :"media:content#url" # this will grab the url attribute of the media:content tag
|
|
38
|
-
|
|
39
|
-
## Authors
|
|
40
|
-
|
|
41
|
-
* Lucas Carlson (mailto:lucas@rufy.com)
|
|
42
|
-
* Herval Freire (mailto:hervalfreire@gmail.com)
|
|
43
|
-
|
|
44
|
-
Inspired by [Blagg](http://www.raelity.org/lang/perl/blagg) from Rael Dornfest.
|
|
45
|
-
|
|
46
|
-
This library is released under the terms of the GNU LGPL.
|
|
47
|
-
|