feed_parser 0.2.6 → 0.2.7
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.md +2 -0
- data/lib/feed_parser/feed.rb +2 -1
- data/lib/feed_parser.rb +3 -1
- data/spec/feed_parser_spec.rb +12 -5
- metadata +6 -6
data/README.md
CHANGED
@@ -32,6 +32,8 @@ Add to Gemfile
|
|
32
32
|
# for available options, check out the OpenURI documentation: http://apidock.com/ruby/OpenURI
|
33
33
|
fp = FeedParser.new(:url => "http://example.com/feed/", :http => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})
|
34
34
|
|
35
|
+
If the fetched XML is not a valid RSS or an ATOM feed, a FeedParser::UnknownFeedType is raised in FeedParser#parse.
|
36
|
+
|
35
37
|
## Running tests
|
36
38
|
|
37
39
|
Install dependencies by running `bundle install`.
|
data/lib/feed_parser/feed.rb
CHANGED
@@ -7,7 +7,8 @@ class FeedParser
|
|
7
7
|
raw_feed = open_or_follow_redirect(feed_url)
|
8
8
|
@feed = Nokogiri::XML(raw_feed)
|
9
9
|
@feed.remove_namespaces!
|
10
|
-
@type = (@feed.search('rss')[0] && :rss || :atom)
|
10
|
+
@type = ((@feed.search('rss')[0] && :rss) || (@feed.search('/feed/title')[0] && :atom))
|
11
|
+
raise FeedParser::UnknownFeedType.new("Feed is not an RSS feed or an ATOM feed") unless @type
|
11
12
|
self
|
12
13
|
end
|
13
14
|
|
data/lib/feed_parser.rb
CHANGED
@@ -3,10 +3,12 @@ require 'nokogiri'
|
|
3
3
|
|
4
4
|
class FeedParser
|
5
5
|
|
6
|
-
VERSION = "0.2.
|
6
|
+
VERSION = "0.2.7"
|
7
7
|
|
8
8
|
USER_AGENT = "Ruby / FeedParser gem"
|
9
9
|
|
10
|
+
class FeedParser::UnknownFeedType < Exception ; end
|
11
|
+
|
10
12
|
def initialize(opts)
|
11
13
|
@url = opts[:url]
|
12
14
|
@http_options = opts[:http] || {}
|
data/spec/feed_parser_spec.rb
CHANGED
@@ -8,6 +8,10 @@ class NotSaneSanitizer
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe FeedParser do
|
11
|
+
def feed_xml(filename = 'nodeta.rss.xml')
|
12
|
+
File.read(File.join(File.dirname(__FILE__), 'fixtures', filename))
|
13
|
+
end
|
14
|
+
|
11
15
|
def http_connection_options
|
12
16
|
opts = {"User-Agent" => FeedParser::USER_AGENT}
|
13
17
|
opts[:redirect] = true if RUBY_VERSION >= '1.9'
|
@@ -16,17 +20,13 @@ describe FeedParser do
|
|
16
20
|
|
17
21
|
describe "#new" do
|
18
22
|
it "should forward given http options to the OpenURI" do
|
19
|
-
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options.merge(:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE))
|
23
|
+
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options.merge(:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)).and_return(feed_xml)
|
20
24
|
fp = FeedParser.new(:url => "http://blog.example.com/feed/", :http => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})
|
21
25
|
fp.parse
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
describe FeedParser::Feed, "#new" do
|
26
|
-
def feed_xml(filename = 'nodeta.rss.xml')
|
27
|
-
File.read(File.join(File.dirname(__FILE__), 'fixtures', filename))
|
28
|
-
end
|
29
|
-
|
30
30
|
it "should fetch a feed by url" do
|
31
31
|
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options).and_return(feed_xml)
|
32
32
|
FeedParser::Feed.new("http://blog.example.com/feed/")
|
@@ -63,6 +63,13 @@ describe FeedParser do
|
|
63
63
|
feed.url.should == "https://developers.facebook.com/blog/feed"
|
64
64
|
}.should_not raise_error
|
65
65
|
end
|
66
|
+
|
67
|
+
it "should raise an error unless retrieved XML is not an RSS or an ATOM feed" do
|
68
|
+
FeedParser::Feed.any_instance.should_receive(:open).with("http://example.com/blog/feed/invalid.xml", http_connection_options).and_return("foo bar")
|
69
|
+
lambda {
|
70
|
+
FeedParser::Feed.new("http://example.com/blog/feed/invalid.xml")
|
71
|
+
}.should raise_error(FeedParser::UnknownFeedType, "Feed is not an RSS feed or an ATOM feed")
|
72
|
+
end
|
66
73
|
end
|
67
74
|
|
68
75
|
describe "#parse" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feed_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152406380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152406380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152404940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '2.6'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152404940
|
36
36
|
description: Rss and Atom feed parser with sanitizer support built on top of Nokogiri.
|
37
37
|
email:
|
38
38
|
- arttu.tervo@gmail.com
|