feed_searcher 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/feed_searcher/page.rb +11 -1
- data/lib/feed_searcher/version.rb +1 -1
- data/spec/feed_searcher_spec.rb +25 -7
- metadata +1 -1
data/lib/feed_searcher/page.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
class FeedSearcher
|
2
2
|
class Page
|
3
|
+
MIME_TYPES = %w[
|
4
|
+
application/atom+xml
|
5
|
+
application/rdf+xml
|
6
|
+
application/rss+xml
|
7
|
+
]
|
8
|
+
|
3
9
|
attr_reader :page
|
4
10
|
|
5
11
|
def initialize(page)
|
@@ -13,7 +19,11 @@ class FeedSearcher
|
|
13
19
|
private
|
14
20
|
|
15
21
|
def feed_attributes
|
16
|
-
root.xpath("//link[@
|
22
|
+
root.xpath("//link[@rel='alternate' and (#{types_query})]")
|
23
|
+
end
|
24
|
+
|
25
|
+
def types_query
|
26
|
+
MIME_TYPES.map {|type| "@type='#{type}'" }.join(" or ")
|
17
27
|
end
|
18
28
|
|
19
29
|
def root
|
data/spec/feed_searcher_spec.rb
CHANGED
@@ -9,23 +9,41 @@ describe FeedSearcher do
|
|
9
9
|
<html>
|
10
10
|
<head>
|
11
11
|
<meta charset="UTF-8">
|
12
|
-
<link href="http://example.com/
|
13
|
-
<link href="http://
|
14
|
-
<link href="/
|
12
|
+
<link href="http://example.com/1" rel="alternate" type="application/atom+xml" />
|
13
|
+
<link href="http://example.com/2" rel="alternate" type="application/rdf+xml" />
|
14
|
+
<link href="http://example.com/3" rel="alternate" type="application/rss+xml" />
|
15
|
+
<link href="http://example.com/4" rel="alternate" type="application/xml" />
|
16
|
+
<link href="http://example.com/5" rel="resource" type="application/rss+xml" />
|
17
|
+
<link href="http://www.example.com/6" rel="alternate" type="application/rss+xml" />
|
18
|
+
<link href="http://other-example.com/7" rel="alternate" type="application/rss+xml" />
|
19
|
+
<link href="/8" rel="alternate" type="application/rss+xml" />
|
15
20
|
</head>
|
16
21
|
<body>
|
17
|
-
|
22
|
+
body
|
18
23
|
</body>
|
19
24
|
</html>
|
20
25
|
EOF
|
21
26
|
)
|
22
27
|
end
|
23
28
|
|
29
|
+
# This example makes sure the following specifications.
|
30
|
+
#
|
31
|
+
# * it recognizes application/atom+xml
|
32
|
+
# * it recognizes application/rdf+xml
|
33
|
+
# * it recognizes application/rss+xml
|
34
|
+
# * it does not recognizes application/xml
|
35
|
+
# * it keeps subdomain
|
36
|
+
# * it keeps other domain
|
37
|
+
# * it converts absolute url
|
38
|
+
#
|
24
39
|
it "returns feed URLs from given URL" do
|
25
40
|
FeedSearcher.search("http://example.com/").should == %w[
|
26
|
-
http://example.com/
|
27
|
-
http://
|
28
|
-
http://example.com/
|
41
|
+
http://example.com/1
|
42
|
+
http://example.com/2
|
43
|
+
http://example.com/3
|
44
|
+
http://www.example.com/6
|
45
|
+
http://other-example.com/7
|
46
|
+
http://example.com/8
|
29
47
|
]
|
30
48
|
end
|
31
49
|
end
|