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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a623533c3b3481c071ddc840d3cc1de3a9394ecc
4
- data.tar.gz: c868ef117f2d8d2efa6de0246c0897a8d24fb973
3
+ metadata.gz: 87bb2ca448ee83469233e386786cd2eb0ca79769
4
+ data.tar.gz: 8cf645f6f608dae97d64d09d484316d831a2bbb7
5
5
  SHA512:
6
- metadata.gz: 750503cb57adcd45da96ae582026b649e3793b6cdf92801f2994ebb5863855a1d62d6153c53f337e3b65b62bf6cf586ca3775962d78ec0ffdf828d69774c6cf8
7
- data.tar.gz: ace8902a68177ce88e91c1a5eace6ba886d6a468d55edc6a16da8511f04ed739de017a87893398097614e0ff7b59d86e343685eb5a29fa7b84629acd4a667cc7
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.parse('https://mrmondialisation.org/feed/')
5
+ puts Feedium.find('http://www.gazzettadelsud.it/feed.jsp')
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Feedium
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
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?(base_uri ? URI.parse(base_uri).merge(l['href']).to_s : l['href'])
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
- url = %w(feed rss atom).detect {|k| a['href'].end_with?(k) }
41
- return @request.url if url && self.feed?(base_uri ? URI.parse(base_uri).merge(url).to_s : url)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feedium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex