feed_parser 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/feed_parser/feed.rb +8 -3
- data/lib/feed_parser.rb +3 -1
- data/spec/feed_parser_spec.rb +3 -3
- metadata +4 -4
data/lib/feed_parser/feed.rb
CHANGED
@@ -4,11 +4,16 @@ class FeedParser
|
|
4
4
|
|
5
5
|
def initialize(feed_url)
|
6
6
|
parsed_url = parse_url(feed_url)
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
connection_options = {"User-Agent" => FeedParser::USER_AGENT}
|
9
|
+
connection_options[:http_basic_authentication] = parsed_url[:basic_auth] if parsed_url[:basic_auth]
|
10
|
+
|
11
|
+
raw_feed = if parsed_url[:protocol]
|
12
|
+
open(parsed_url[:url], connection_options)
|
9
13
|
else
|
10
14
|
open(parsed_url[:url])
|
11
15
|
end
|
16
|
+
|
12
17
|
@feed = Nokogiri::XML(raw_feed)
|
13
18
|
@feed.remove_namespaces!
|
14
19
|
@type = (@feed.search('rss')[0] && :rss || :atom)
|
@@ -54,7 +59,7 @@ class FeedParser
|
|
54
59
|
the_rest[-2].insert(0, '?') if the_rest[-2].is_a?(String)
|
55
60
|
url = (protocol && [protocol, the_rest.join].join('://') || the_rest.join)
|
56
61
|
basic_auth = auth.split(':') if auth
|
57
|
-
{:url => url, :basic_auth => basic_auth}
|
62
|
+
{:protocol => protocol, :url => url, :basic_auth => basic_auth}
|
58
63
|
end
|
59
64
|
end
|
60
65
|
end
|
data/lib/feed_parser.rb
CHANGED
data/spec/feed_parser_spec.rb
CHANGED
@@ -13,17 +13,17 @@ describe FeedParser do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should fetch a feed by url" do
|
16
|
-
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/").and_return(feed_xml)
|
16
|
+
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", "User-Agent" => FeedParser::USER_AGENT).and_return(feed_xml)
|
17
17
|
FeedParser::Feed.new("http://blog.example.com/feed/")
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should fetch a feed using basic auth if auth embedded to the url" do
|
21
|
-
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", :http_basic_authentication => ["user", "pass"]).and_return(feed_xml)
|
21
|
+
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", "User-Agent" => FeedParser::USER_AGENT, :http_basic_authentication => ["user", "pass"]).and_return(feed_xml)
|
22
22
|
FeedParser::Feed.new("http://user:pass@blog.example.com/feed/")
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should fetch a feed with only a user name embedded to the url" do
|
26
|
-
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", :http_basic_authentication => ["user"]).and_return(feed_xml)
|
26
|
+
FeedParser::Feed.any_instance.should_receive(:open).with("http://blog.example.com/feed/", "User-Agent" => FeedParser::USER_AGENT, :http_basic_authentication => ["user"]).and_return(feed_xml)
|
27
27
|
FeedParser::Feed.new("http://user@blog.example.com/feed/")
|
28
28
|
end
|
29
29
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feed_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Arttu Tervo
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-08 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|