feedium 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/parse.rb +1 -1
- data/lib/feedium/request.rb +3 -1
- data/lib/feedium/version.rb +1 -1
- data/lib/feedium.rb +11 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87bb2ca448ee83469233e386786cd2eb0ca79769
|
4
|
+
data.tar.gz: 8cf645f6f608dae97d64d09d484316d831a2bbb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a3db6240adb8c5dfc7e0df4bebc0f6a3c1845b6981aee11be381ad7471bdd2a943f5dec61e7eea00cf5ff1e8ef1422edb5bfbbf7e2ae2c173c4afeb3f55f5e7
|
7
|
+
data.tar.gz: b5a2b8fefe268e6be2d6104c6abdf0e654125879ec27d15210a839fccb0b628f10e704b204f46b345e7a46a3bec620bdbc903daf494cdc3c12da370becb93cbd
|
data/examples/parse.rb
CHANGED
@@ -2,4 +2,4 @@ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
require File.join(dir, 'feedium')
|
3
3
|
|
4
4
|
# puts Feedium.parse('http://mangastream.com/rss')
|
5
|
-
puts Feedium.
|
5
|
+
puts Feedium.find('http://www.gazzettadelsud.it/feed.jsp')
|
data/lib/feedium/request.rb
CHANGED
@@ -4,7 +4,9 @@ class Feedium::Request
|
|
4
4
|
URI_REQEX = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
|
5
5
|
MAX_CONTENT_SIZE = 5 * 1048576 # bytes in 1MB
|
6
6
|
|
7
|
-
def initialize(url)
|
7
|
+
def initialize(url, base_uri = nil)
|
8
|
+
url = URI.parse(base_uri).merge(url).to_s if base_uri
|
9
|
+
|
8
10
|
begin
|
9
11
|
@uri = URI.parse(url)
|
10
12
|
rescue URI::InvalidURIError => e
|
data/lib/feedium/version.rb
CHANGED
data/lib/feedium.rb
CHANGED
@@ -25,20 +25,25 @@ module Feedium
|
|
25
25
|
doc = Nokogiri::HTML(@request.io.read)
|
26
26
|
|
27
27
|
if doc.at('base') && doc.at('base')['href']
|
28
|
-
base_uri = doc.at('base')['href']
|
28
|
+
@base_uri = doc.at('base')['href']
|
29
29
|
else
|
30
|
-
base_uri = "#{@request.uri.scheme}://#{@request.uri.host}"
|
30
|
+
@base_uri = "#{@request.uri.scheme}://#{@request.uri.host}"
|
31
31
|
end
|
32
32
|
|
33
33
|
doc.xpath("//link[@rel='alternate'][@href][@type]").each do |l|
|
34
34
|
if CONTENT_TYPES.include?(l['type'].downcase.strip)
|
35
|
-
return @request.url if self.feed?(
|
35
|
+
return @request.url if self.feed?(l['href'])
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
doc.xpath("//a[@href]").each do |a|
|
40
|
-
|
41
|
-
|
40
|
+
found = %w(feed rss atom).detect {|k| !a['href'].index(k).nil? }
|
41
|
+
|
42
|
+
begin
|
43
|
+
return @request.url if found && self.feed?(a['href'])
|
44
|
+
rescue Feedium::RequestError
|
45
|
+
next
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
44
49
|
nil
|
@@ -53,7 +58,7 @@ module Feedium
|
|
53
58
|
end
|
54
59
|
|
55
60
|
def self.feed?(url)
|
56
|
-
@request = Request.new(url)
|
61
|
+
@request = Request.new(url, @base_uri)
|
57
62
|
@request.send
|
58
63
|
|
59
64
|
content_type = @request.io.content_type.downcase
|