feed_parser 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/lib/feed_parser/feed.rb +3 -1
- data/lib/feed_parser.rb +3 -2
- data/spec/feed_parser_spec.rb +15 -6
- metadata +6 -9
data/README.md
CHANGED
@@ -28,6 +28,10 @@ Add to Gemfile
|
|
28
28
|
pp feed_item
|
29
29
|
end
|
30
30
|
|
31
|
+
# you can also pass http options to be used for the connection
|
32
|
+
# for available options, check out the OpenURI documentation: http://apidock.com/ruby/OpenURI
|
33
|
+
fp = FeedParser.new(:url => "http://example.com/feed/", :http => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})
|
34
|
+
|
31
35
|
## Running tests
|
32
36
|
|
33
37
|
Install dependencies by running `bundle install`.
|
data/lib/feed_parser/feed.rb
CHANGED
@@ -2,7 +2,8 @@ class FeedParser
|
|
2
2
|
class Feed
|
3
3
|
attr_reader :type
|
4
4
|
|
5
|
-
def initialize(feed_url)
|
5
|
+
def initialize(feed_url, http_options = {})
|
6
|
+
@http_options = http_options
|
6
7
|
raw_feed = open_or_follow_redirect(feed_url)
|
7
8
|
@feed = Nokogiri::XML(raw_feed)
|
8
9
|
@feed.remove_namespaces!
|
@@ -50,6 +51,7 @@ class FeedParser
|
|
50
51
|
parsed_url = parse_url(feed_url)
|
51
52
|
|
52
53
|
connection_options = {"User-Agent" => FeedParser::USER_AGENT}
|
54
|
+
connection_options.merge!(@http_options)
|
53
55
|
connection_options[:http_basic_authentication] = parsed_url[:basic_auth] if parsed_url[:basic_auth]
|
54
56
|
|
55
57
|
connection_options[:redirect] = true if RUBY_VERSION >= '1.9'
|
data/lib/feed_parser.rb
CHANGED
@@ -3,12 +3,13 @@ require 'nokogiri'
|
|
3
3
|
|
4
4
|
class FeedParser
|
5
5
|
|
6
|
-
VERSION = "0.2.
|
6
|
+
VERSION = "0.2.6"
|
7
7
|
|
8
8
|
USER_AGENT = "Ruby / FeedParser gem"
|
9
9
|
|
10
10
|
def initialize(opts)
|
11
11
|
@url = opts[:url]
|
12
|
+
@http_options = opts[:http] || {}
|
12
13
|
@@sanitizer = (opts[:sanitizer] || SelfSanitizer.new)
|
13
14
|
@@fields_to_sanitize = (opts[:fields_to_sanitize] || [:content])
|
14
15
|
self
|
@@ -23,7 +24,7 @@ class FeedParser
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def parse
|
26
|
-
@feed ||= Feed.new(@url)
|
27
|
+
@feed ||= Feed.new(@url, @http_options)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
data/spec/feed_parser_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'openssl'
|
1
2
|
require 'feed_parser'
|
2
3
|
|
3
4
|
class NotSaneSanitizer
|
@@ -7,17 +8,25 @@ class NotSaneSanitizer
|
|
7
8
|
end
|
8
9
|
|
9
10
|
describe FeedParser do
|
11
|
+
def http_connection_options
|
12
|
+
opts = {"User-Agent" => FeedParser::USER_AGENT}
|
13
|
+
opts[:redirect] = true if RUBY_VERSION >= '1.9'
|
14
|
+
opts
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#new" do
|
18
|
+
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))
|
20
|
+
fp = FeedParser.new(:url => "http://blog.example.com/feed/", :http => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})
|
21
|
+
fp.parse
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
10
25
|
describe FeedParser::Feed, "#new" do
|
11
26
|
def feed_xml(filename = 'nodeta.rss.xml')
|
12
27
|
File.read(File.join(File.dirname(__FILE__), 'fixtures', filename))
|
13
28
|
end
|
14
29
|
|
15
|
-
def http_connection_options
|
16
|
-
opts = {"User-Agent" => FeedParser::USER_AGENT}
|
17
|
-
opts[:redirect] = true if RUBY_VERSION >= '1.9'
|
18
|
-
opts
|
19
|
-
end
|
20
|
-
|
21
30
|
it "should fetch a feed by url" do
|
22
31
|
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options).and_return(feed_xml)
|
23
32
|
FeedParser::Feed.new("http://blog.example.com/feed/")
|
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.6
|
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-01-
|
12
|
+
date: 2012-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160499900 !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: *2160499900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &2160496620 !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: *2160496620
|
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
|
@@ -71,9 +71,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
71
|
- - ! '>='
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
hash: -3280497308779213588
|
77
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
75
|
none: false
|
79
76
|
requirements:
|