fed 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/fed.gemspec +2 -1
- data/lib/fed.rb +12 -6
- data/lib/fed/http/curb.rb +4 -2
- data/lib/fed/http/errors.rb +11 -0
- metadata +2 -1
data/fed.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'fed'
|
16
|
-
s.version = '0.0.
|
16
|
+
s.version = '0.0.4'
|
17
17
|
s.date = '2013-04-26'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
@@ -65,6 +65,7 @@ Gem::Specification.new do |s|
|
|
65
65
|
lib/fed/feed/rss2.rb
|
66
66
|
lib/fed/http.rb
|
67
67
|
lib/fed/http/curb.rb
|
68
|
+
lib/fed/http/errors.rb
|
68
69
|
]
|
69
70
|
# = MANIFEST =
|
70
71
|
|
data/lib/fed.rb
CHANGED
@@ -5,6 +5,7 @@ require 'nokogiri'
|
|
5
5
|
require 'time'
|
6
6
|
|
7
7
|
require 'fed/http'
|
8
|
+
require 'fed/http/errors'
|
8
9
|
require 'fed/http/curb'
|
9
10
|
require 'fed/feed/base'
|
10
11
|
require 'fed/feed/atom'
|
@@ -13,7 +14,7 @@ require 'fed/feed/rss2'
|
|
13
14
|
require 'fed/feed/entry'
|
14
15
|
|
15
16
|
module Fed
|
16
|
-
VERSION = '0.0.
|
17
|
+
VERSION = '0.0.4'
|
17
18
|
|
18
19
|
class <<self
|
19
20
|
|
@@ -22,7 +23,12 @@ module Fed
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def fetch(feed_url)
|
25
|
-
Fed::Http.client.get(feed_url)
|
26
|
+
response = Fed::Http.client.get(feed_url)
|
27
|
+
|
28
|
+
raise Fed::Http::Errors::NotFound if response == 404
|
29
|
+
raise Fed::Http::Errors::ServerError unless response.is_a?(String)
|
30
|
+
|
31
|
+
response
|
26
32
|
end
|
27
33
|
|
28
34
|
def parse(xml)
|
@@ -33,14 +39,14 @@ module Fed
|
|
33
39
|
def parser_for(doc)
|
34
40
|
if is_atom?(doc)
|
35
41
|
Fed::Feed::Atom.new(doc)
|
36
|
-
elsif is_rss1?(doc)
|
37
|
-
Fed::Feed::Rss1.new(doc)
|
38
42
|
elsif is_rss2?(doc)
|
39
43
|
Fed::Feed::Rss2.new(doc)
|
44
|
+
elsif is_rss1?(doc)
|
45
|
+
Fed::Feed::Rss1.new(doc)
|
40
46
|
elsif (new_url = find_link_in_html(doc))
|
41
47
|
parser_for(fetch(new_url))
|
42
48
|
else
|
43
|
-
raise
|
49
|
+
raise Fed::Http::Errors::BadFeed
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
@@ -49,7 +55,7 @@ module Fed
|
|
49
55
|
end
|
50
56
|
|
51
57
|
def is_rss1?(document)
|
52
|
-
document.xpath('/rdf:RDF').any?
|
58
|
+
document.xpath('/rdf:RDF').any? rescue false
|
53
59
|
end
|
54
60
|
|
55
61
|
def is_rss2?(document)
|
data/lib/fed/http/curb.rb
CHANGED
@@ -3,10 +3,12 @@ module Fed
|
|
3
3
|
module Http
|
4
4
|
class Curb
|
5
5
|
def self.get(url)
|
6
|
-
Curl.get(url) do|http|
|
6
|
+
c = Curl.get(url) do|http|
|
7
7
|
http.headers['User-Agent'] = Fed::Http.options[:user_agent]
|
8
8
|
http.follow_location = true
|
9
|
-
end
|
9
|
+
end
|
10
|
+
|
11
|
+
c.status == "200 OK" ? c.body_str : c.status.to_i
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/fed/feed/rss2.rb
|
97
97
|
- lib/fed/http.rb
|
98
98
|
- lib/fed/http/curb.rb
|
99
|
+
- lib/fed/http/errors.rb
|
99
100
|
homepage: http://github.com/jm/fed
|
100
101
|
licenses: []
|
101
102
|
post_install_message:
|