fed 0.0.2 → 0.0.3

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.
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.2'
16
+ s.version = '0.0.3'
17
17
  s.date = '2013-04-26'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
@@ -59,8 +59,10 @@ Gem::Specification.new do |s|
59
59
  lib/fed.rb
60
60
  lib/fed/feed/atom.rb
61
61
  lib/fed/feed/base.rb
62
+ lib/fed/feed/enclosure.rb
62
63
  lib/fed/feed/entry.rb
63
- lib/fed/feed/rss.rb
64
+ lib/fed/feed/rss1.rb
65
+ lib/fed/feed/rss2.rb
64
66
  lib/fed/http.rb
65
67
  lib/fed/http/curb.rb
66
68
  ]
data/lib/fed/feed/atom.rb CHANGED
@@ -24,7 +24,16 @@ module Fed
24
24
  ""
25
25
  end
26
26
 
27
- Entry.new(entry_title, entry_link, entry_guid, entry_published, entry_author, entry_summary, entry_content)
27
+ enclosure_elem = item.css("link[rel='enclosure']").first
28
+ entry_enclosure = if !enclosure_elem.nil?
29
+ url = enclosure_elem.attributes['href'] ? enclosure_elem.attributes['href'].value : ''
30
+ content_type = enclosure_elem.attributes['type'] ? enclosure_elem.attributes['type'].value : ''
31
+ Enclosure.new(url, content_type)
32
+ else
33
+ nil
34
+ end
35
+
36
+ Entry.new(entry_title, entry_link, entry_guid, entry_published, entry_author, entry_summary, entry_content, entry_enclosure)
28
37
  end
29
38
 
30
39
  self
@@ -0,0 +1,6 @@
1
+ module Fed
2
+ module Feed
3
+ class Enclosure < Struct.new(:url, :type)
4
+ end
5
+ end
6
+ end
@@ -1,6 +1,6 @@
1
1
  module Fed
2
2
  module Feed
3
- class Entry < Struct.new(:title, :link, :guid, :published, :author, :summary, :content)
3
+ class Entry < Struct.new(:title, :link, :guid, :published, :author, :summary, :content, :enclosure)
4
4
  end
5
5
  end
6
6
  end
@@ -0,0 +1,40 @@
1
+ module Fed
2
+ module Feed
3
+ class Rss1 < Base
4
+ def parse
5
+ channel = @document.xpath('/rdf:RDF').css('channel').first
6
+
7
+ @title = channel.css('/title').text
8
+ @description = channel.css('/description').text
9
+ @link = channel.css('/link').text
10
+ @updated = DateTime.parse(channel.css('/pubDate').text) rescue nil
11
+
12
+ entry_list = @document.at('channel items').xpath('rdf:Seq/rdf:li').map {|e| e.attributes['resource'].value }
13
+ @entries = entry_list.map {|i| @document.css("item[rdf|about='#{i}']")}
14
+
15
+ @entries.map! do |item|
16
+ item_title = item.css('/title').text
17
+ item_summary = item.css('/description').text
18
+ item_content = item.css('/description').text
19
+ item_link = item.css('/link').text
20
+ item_published = DateTime.parse(item.css('/pubDate').text) rescue nil
21
+ item_guid = item.css('/guid').text
22
+ item_author = item.css('/author').text
23
+
24
+ enclosure_elem = item.css('/enclosure').first
25
+ item_enclosure = if !enclosure_elem.nil?
26
+ url = enclosure_elem.attributes['url'] ? enclosure_elem.attributes['url'].value : ''
27
+ content_type = enclosure_elem.attributes['type'] ? enclosure_elem.attributes['type'].value : ''
28
+ Enclosure.new(url, content_type)
29
+ else
30
+ nil
31
+ end
32
+
33
+ Entry.new(item_title, item_link, item_guid, item_published, item_author, item_summary, item_content, item_enclosure)
34
+ end
35
+
36
+ self
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,6 @@
1
1
  module Fed
2
2
  module Feed
3
- class Rss < Base
3
+ class Rss2 < Base
4
4
  def parse
5
5
  channel = @document.css('rss channel').first
6
6
 
@@ -17,8 +17,17 @@ module Fed
17
17
  item_published = DateTime.parse(item.css('/pubDate').text) rescue nil
18
18
  item_guid = item.css('/guid').text
19
19
  item_author = item.css('/author').text
20
+
21
+ enclosure_elem = item.css('/enclosure').first
22
+ item_enclosure = if !enclosure_elem.nil?
23
+ url = enclosure_elem.attributes['url'] ? enclosure_elem.attributes['url'].value : ''
24
+ content_type = enclosure_elem.attributes['type'] ? enclosure_elem.attributes['type'].value : ''
25
+ Enclosure.new(url, content_type)
26
+ else
27
+ nil
28
+ end
20
29
 
21
- Entry.new(item_title, item_link, item_guid, item_published, item_author, item_summary, item_content)
30
+ Entry.new(item_title, item_link, item_guid, item_published, item_author, item_summary, item_content, item_enclosure)
22
31
  end
23
32
 
24
33
  self
data/lib/fed.rb CHANGED
@@ -8,11 +8,12 @@ require 'fed/http'
8
8
  require 'fed/http/curb'
9
9
  require 'fed/feed/base'
10
10
  require 'fed/feed/atom'
11
- require 'fed/feed/rss'
11
+ require 'fed/feed/rss1'
12
+ require 'fed/feed/rss2'
12
13
  require 'fed/feed/entry'
13
14
 
14
15
  module Fed
15
- VERSION = '0.0.2'
16
+ VERSION = '0.0.3'
16
17
 
17
18
  class <<self
18
19
 
@@ -32,8 +33,10 @@ module Fed
32
33
  def parser_for(doc)
33
34
  if is_atom?(doc)
34
35
  Fed::Feed::Atom.new(doc)
35
- elsif is_rss?(doc)
36
- Fed::Feed::Rss.new(doc)
36
+ elsif is_rss1?(doc)
37
+ Fed::Feed::Rss1.new(doc)
38
+ elsif is_rss2?(doc)
39
+ Fed::Feed::Rss2.new(doc)
37
40
  elsif (new_url = find_link_in_html(doc))
38
41
  parser_for(fetch(new_url))
39
42
  else
@@ -45,7 +48,11 @@ module Fed
45
48
  document.css('feed entry').any?
46
49
  end
47
50
 
48
- def is_rss?(document)
51
+ def is_rss1?(document)
52
+ document.xpath('/rdf:RDF').any?
53
+ end
54
+
55
+ def is_rss2?(document)
49
56
  document.css('rss channel').any?
50
57
  end
51
58
 
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -90,8 +90,10 @@ files:
90
90
  - lib/fed.rb
91
91
  - lib/fed/feed/atom.rb
92
92
  - lib/fed/feed/base.rb
93
+ - lib/fed/feed/enclosure.rb
93
94
  - lib/fed/feed/entry.rb
94
- - lib/fed/feed/rss.rb
95
+ - lib/fed/feed/rss1.rb
96
+ - lib/fed/feed/rss2.rb
95
97
  - lib/fed/http.rb
96
98
  - lib/fed/http/curb.rb
97
99
  homepage: http://github.com/jm/fed