feedisco 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/VERSION +1 -1
- data/feedisco.gemspec +1 -1
- data/lib/feedisco/discovery.rb +8 -6
- data/lib/feedisco/version.rb +1 -1
- data/spec/fixtures/several_links.html +1 -0
- data/spec/lib/discovery_spec.rb +19 -16
- metadata +2 -2
data/README.md
CHANGED
@@ -107,6 +107,10 @@ Contribute by forking, tweaking, and sending pull requests, but please add the a
|
|
107
107
|
|
108
108
|
### History
|
109
109
|
|
110
|
+
#### `0.1.3`
|
111
|
+
|
112
|
+
* Corrected bug causing some links to appear several times in the result.
|
113
|
+
|
110
114
|
#### `0.1.2`
|
111
115
|
|
112
116
|
* Supports `StringIO` as a return from the open-uri `open` method (which is returned instead of a `Tempfile` when the content is smaller than a given size - 10KB).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/feedisco.gemspec
CHANGED
data/lib/feedisco/discovery.rb
CHANGED
@@ -30,23 +30,25 @@ module Feedisco
|
|
30
30
|
|
31
31
|
# Check <link> elements
|
32
32
|
doc.css('link').each do |link|
|
33
|
-
|
33
|
+
discovery = complete_extracted_url(link[:href], harmonized_url) if link[:rel] =~ %r{(alternate|service.feed)}i && Feedisco.feed_content_types.include?(link[:type].downcase.strip)
|
34
|
+
feeds << discovery unless discovery.nil? or feeds.include? discovery
|
34
35
|
end
|
35
36
|
|
36
37
|
# Check <a> elements
|
37
38
|
doc.css('a').each do |a|
|
38
|
-
if
|
39
|
-
(a[:href] =~ %r{\A/}
|
40
|
-
!feeds.include?(a[:href]))
|
39
|
+
if looks_like_feed? a[:href] and
|
40
|
+
(a[:href] =~ %r{\A/} or a[:href] =~ %r{#{URI.parse(harmonized_url).host}/})
|
41
41
|
|
42
|
-
|
42
|
+
discovery = complete_extracted_url(a[:href], harmonized_url)
|
43
|
+
feeds << discovery unless discovery.nil? or feeds.include?(discovery)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
47
|
# Check <a> elements again, less restrictively, so we add all discovered feeds even the ones
|
47
48
|
# on external domains, but the will come after in the feeds array.
|
48
49
|
doc.css('a').each do |a|
|
49
|
-
|
50
|
+
discovery = complete_extracted_url(a[:href], harmonized_url) if looks_like_feed? a[:href]
|
51
|
+
feeds << discovery unless discovery.nil? or feeds.include?(discovery)
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
data/lib/feedisco/version.rb
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
<a href="http://example.com/feed.rss">feed.rss</a>
|
11
11
|
<a href="http://another.domain.com/feed.rss">another domain's feed.rss</a>
|
12
12
|
<a href="http://example.com/feed.rss">feed.rss</a>
|
13
|
+
<a href="feed.rss">feed.rss, without the prefix part</a>
|
13
14
|
</body>
|
14
15
|
|
15
16
|
</html>
|
data/spec/lib/discovery_spec.rb
CHANGED
@@ -19,16 +19,19 @@ describe "Feedisco::Discovery" do
|
|
19
19
|
|
20
20
|
context 'from fixtures' do
|
21
21
|
|
22
|
-
|
23
|
-
file = File.open(File.join(File.dirname(__FILE__), '..', 'fixtures',
|
22
|
+
def file_for_fixture(fixture_file_name)
|
23
|
+
file = File.open(File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_file_name))
|
24
24
|
file.stub!(:class => stub(:to_s => 'Tempfile'), :content_type => 'text/html')
|
25
|
+
file
|
26
|
+
end
|
25
27
|
|
26
|
-
|
28
|
+
it 'should return an empty array' do
|
29
|
+
Feedisco.should_receive(:open).and_yield(file_for_fixture 'no_link.html')
|
27
30
|
Feedisco.find('example.com').should == []
|
28
31
|
end
|
29
32
|
|
30
33
|
it 'should include the alternate link' do
|
31
|
-
file =
|
34
|
+
file = file_for_fixture 'alternate.html'
|
32
35
|
file.stub!(:class => stub(:to_s => 'Tempfile'), :content_type => 'text/html')
|
33
36
|
|
34
37
|
Feedisco.should_receive(:open).and_yield(file)
|
@@ -36,40 +39,35 @@ describe "Feedisco::Discovery" do
|
|
36
39
|
end
|
37
40
|
|
38
41
|
it 'should include a <a> link in the body' do
|
39
|
-
file =
|
40
|
-
file.stub!(:class => stub(:to_s => 'Tempfile'), :content_type => 'text/html')
|
42
|
+
file = file_for_fixture 'one_link_in_body.html'
|
41
43
|
|
42
44
|
Feedisco.should_receive(:open).and_yield(file)
|
43
45
|
Feedisco.find('example.com').should include("http://example.com/feed.rss")
|
44
46
|
end
|
45
47
|
|
46
48
|
it 'should include link to feeds on the URL\'s domain' do
|
47
|
-
file =
|
48
|
-
file.stub!(:class => stub(:to_s => 'Tempfile'), :content_type => 'text/html')
|
49
|
+
file = file_for_fixture 'several_links.html'
|
49
50
|
|
50
51
|
Feedisco.should_receive(:open).and_yield(file)
|
51
52
|
Feedisco.find('example.com').should include("http://example.com/feed.rss")
|
52
53
|
end
|
53
54
|
|
54
55
|
it 'should have the alternate link as the first of the returned feed' do
|
55
|
-
file =
|
56
|
-
file.stub!(:class => stub(:to_s => 'Tempfile'), :content_type => 'text/html')
|
56
|
+
file = file_for_fixture 'several_links.html'
|
57
57
|
|
58
58
|
Feedisco.should_receive(:open).and_yield(file)
|
59
59
|
Feedisco.find('example.com').first.should == "http://example.com/feed.xml"
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should include link to feeds on other domains' do
|
63
|
-
file =
|
64
|
-
file.stub!(:class => stub(:to_s => 'Tempfile'), :content_type => 'text/html')
|
63
|
+
file = file_for_fixture 'several_links.html'
|
65
64
|
|
66
65
|
Feedisco.should_receive(:open).and_yield(file)
|
67
66
|
Feedisco.find('example.com').should include "http://another.domain.com/feed.rss"
|
68
67
|
end
|
69
68
|
|
70
69
|
it 'should have links to feeds on other domains after links to feeds on the same domain' do
|
71
|
-
file =
|
72
|
-
file.stub!(:class => stub(:to_s => 'Tempfile'), :content_type => 'text/html')
|
70
|
+
file = file_for_fixture 'several_links.html'
|
73
71
|
|
74
72
|
Feedisco.should_receive(:open).and_yield(file)
|
75
73
|
feeds = Feedisco.find('example.com')
|
@@ -77,13 +75,18 @@ describe "Feedisco::Discovery" do
|
|
77
75
|
end
|
78
76
|
|
79
77
|
it 'should include each link only once' do
|
80
|
-
file =
|
81
|
-
file.stub!(:class => stub(:to_s => 'Tempfile'), :content_type => 'text/html')
|
78
|
+
file = file_for_fixture 'several_links.html'
|
82
79
|
|
83
80
|
Feedisco.should_receive(:open).and_yield(file)
|
84
81
|
feeds = Feedisco.find('example.com')
|
85
82
|
feeds.select { |f| f == 'http://example.com/feed.rss' }.count.should == 1
|
86
83
|
end
|
84
|
+
|
85
|
+
it "should complete a relative link" do
|
86
|
+
Feedisco.should_receive(:open).and_yield(file_for_fixture 'several_links.html')
|
87
|
+
feeds = Feedisco.find('example.com')
|
88
|
+
feeds.should include 'http://example.com/feed.rss'
|
89
|
+
end
|
87
90
|
end
|
88
91
|
|
89
92
|
context 'from real websites (this may change so some examples may break)' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feedisco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -104,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
segments:
|
106
106
|
- 0
|
107
|
-
hash:
|
107
|
+
hash: 2342868453426803014
|
108
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
109
|
none: false
|
110
110
|
requirements:
|