feed_searcher 0.0.3 → 0.0.4

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.
@@ -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[@type='application/rss+xml' or @type='application/atom+xml']")
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
@@ -1,3 +1,3 @@
1
1
  class FeedSearcher
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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/rss.atom" rel="alternate" title="example" type="application/atom+xml" />
13
- <link href="http://rss.example.com/rss.atom" rel="alternate" title="example" type="application/atom+xml" />
14
- <link href="/rss.xml" rel="alternate" title="example" type="application/atom+xml" />
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
- example
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/rss.atom
27
- http://rss.example.com/rss.atom
28
- http://example.com/rss.xml
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feed_searcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: