feedutils 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/feedutils.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'rss'
4
4
  require 'pp'
5
+ require 'date'
5
6
 
6
7
  # 3rd party gems/libs
7
8
 
@@ -29,7 +29,10 @@ class AtomFeedBuilder
29
29
  if atom_feed.updated
30
30
  # NOTE: empty updated.content e.g. used by google groups feed
31
31
  # will return nil : NilClass
32
- feed.updated = atom_feed.updated.content # .utc.strftime( "%Y-%m-%d %H:%M" )
32
+
33
+ ## convert from time to to_datetime (avoid errors on windows w/ builtin rss lib)
34
+
35
+ feed.updated = atom_feed.updated.content.nil? ? nil : atom_feed.updated.content.to_datetime # .utc.strftime( "%Y-%m-%d %H:%M" )
33
36
  logger.debug " atom | updated.content >#{atom_feed.updated.content}< : #{atom_feed.updated.content.class.name}"
34
37
  end
35
38
 
@@ -65,7 +68,9 @@ class AtomFeedBuilder
65
68
 
66
69
 
67
70
  if atom_item.updated
68
- item.updated = atom_item.updated.content # .utc.strftime( "%Y-%m-%d %H:%M" )
71
+ ## convert from time to to_datetime (avoid errors on windows w/ builtin rss lib)
72
+
73
+ item.updated = atom_item.updated.content.nil? ? nil : atom_item.updated.content.to_datetime # .utc.strftime( "%Y-%m-%d %H:%M" )
69
74
 
70
75
  ## change time to utc if present? why? why not?
71
76
 
@@ -73,7 +78,9 @@ class AtomFeedBuilder
73
78
  end
74
79
 
75
80
  if atom_item.published
76
- item.published = atom_item.published.content # .utc.strftime( "%Y-%m-%d %H:%M" )
81
+ ## convert from time to to_datetime (avoid errors on windows w/ builtin rss lib)
82
+
83
+ item.published = atom_item.published.content.nil? ? nil : atom_item.published.content.to_datetime # .utc.strftime( "%Y-%m-%d %H:%M" )
77
84
  logger.debug " atom | item.published.content >#{atom_item.published.content}< : #{atom_item.published.content.class.name}"
78
85
  end
79
86
 
@@ -97,17 +104,16 @@ class AtomFeedBuilder
97
104
 
98
105
  if atom_item.summary
99
106
  item.summary = atom_item.summary.content
100
- else
101
- if atom_item.content
102
- text = atom_item.content.content
103
- ## strip all html tags
104
- text = text.gsub( /<[^>]+>/, '' )
105
- text = text[ 0..400 ] # get first 400 chars
106
- ## todo: check for length if > 400 add ... at the end???
107
- item.summary = text
108
- end
109
107
  end
110
108
 
109
+ # let client deal w/ missing summary - move to attic - delete
110
+ # text = atom_item.content.content
111
+ # ## strip all html tags
112
+ # text = text.gsub( /<[^>]+>/, '' )
113
+ # text = text[ 0..400 ] # get first 400 chars
114
+ # ## todo: check for length if > 400 add ... at the end???
115
+ # item.summary = text
116
+
111
117
  item
112
118
  end # method build_feed_item
113
119
 
@@ -31,14 +31,18 @@ class RssFeedBuilder
31
31
  feed.url = rss_feed.channel.link # required
32
32
  feed.summary = rss_feed.channel.description # required
33
33
 
34
+ logger.debug " rss | channel.description: >#{rss_feed.channel.description}< : #{rss_feed.channel.description.class.name}"
35
+
34
36
  # NOTE:
35
37
  # All date-times in RSS conform
36
38
  # to the Date and Time Specification of RFC 822
37
39
  # e.g. Sun, 19 May 2012 15:21:36 GMT or
38
40
  # Sat, 07 Sep 2013 00:00:01 GMT
39
41
 
40
- feed.built = rss_feed.channel.lastBuildDate # optional
41
- feed.published = rss_feed.channel.pubDate # optional
42
+ ## convert from time to to_datetime (avoid errors on windows w/ builtin rss lib)
43
+
44
+ feed.built = rss_feed.channel.lastBuildDate.nil? ? nil : rss_feed.channel.lastBuildDate.to_datetime # optional
45
+ feed.published = rss_feed.channel.pubDate.nil? ? nil : rss_feed.channel.pubDate.to_datetime # optional
42
46
 
43
47
  logger.debug " rss | channel.lastBuildDate: >#{rss_feed.channel.lastBuildDate}< : #{rss_feed.channel.lastBuildDate.class.name}"
44
48
  logger.debug " rss | channel.pubDate: >#{rss_feed.channel.pubDate}< : #{rss_feed.channel.pubDate.class.name}"
@@ -85,7 +89,9 @@ class RssFeedBuilder
85
89
  # e.g. Sun, 19 May 2012 15:21:36 GMT or
86
90
  # Sat, 07 Sep 2013 00:00:01 GMT
87
91
 
88
- item.published = rss_item.pubDate # .utc.strftime( "%Y-%m-%d %H:%M" )
92
+ ## convert from time to to_datetime (avoid errors on windows w/ builtin rss lib)
93
+
94
+ item.published = rss_item.pubDate.nil? ? nil : rss_item.pubDate.to_datetime # .utc.strftime( "%Y-%m-%d %H:%M" )
89
95
 
90
96
  logger.debug " rss | item.pubDate: >#{rss_item.pubDate}< : #{rss_item.pubDate.class.name}"
91
97
 
@@ -99,9 +105,16 @@ class RssFeedBuilder
99
105
  # end
100
106
 
101
107
  ## fix/todo: check if rss_item.guid present? !!!!
102
- item.guid = rss_item.guid.content
103
-
104
- logger.debug " rss | item.guid.content: >#{rss_item.guid.content}< : #{rss_item.guid.content.class.name}"
108
+ ##
109
+ ## might be the case e.g. check lambda-the-ultimate.org, for example
110
+
111
+ if rss_item.guid && rss_item.guid.content
112
+ item.guid = rss_item.guid.content
113
+ logger.debug " rss | item.guid.content: >#{rss_item.guid.content}< : #{rss_item.guid.content.class.name}"
114
+ else
115
+ item.guid = rss_item.link
116
+ logger.warn " rss | item.guid.content missing !!!! - using link for guid"
117
+ end
105
118
 
106
119
  ### todo: add support or authors (incl. dc:creator)
107
120
  ## <dc:creator>Dhaivat Pandya</dc:creator>
@@ -1,4 +1,4 @@
1
1
 
2
2
  module FeedUtils
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
data/test/test_rss.rb CHANGED
@@ -19,5 +19,10 @@ class TestRss < MiniTest::Unit::TestCase
19
19
  assert( feed.format == 'rss 2.0' )
20
20
  end
21
21
 
22
+ def test_lambdatheultimate
23
+ ## check - has no item.guid - will use item.link for guid
24
+ feed = parse_feed( 'http://lambda-the-ultimate.org/rss.xml' )
25
+ assert( feed.format == 'rss 2.0' )
26
+ end
22
27
 
23
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feedutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-21 00:00:00.000000000 Z
12
+ date: 2013-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logutils
16
- requirement: &74860390 !ruby/object:Gem::Requirement
16
+ requirement: &74300430 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *74860390
24
+ version_requirements: *74300430
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &74859360 !ruby/object:Gem::Requirement
27
+ requirement: &74300030 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.10'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *74859360
35
+ version_requirements: *74300030
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hoe
38
- requirement: &74858200 !ruby/object:Gem::Requirement
38
+ requirement: &74299400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '3.3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *74858200
46
+ version_requirements: *74299400
47
47
  description: feedutils - web feed parser and normalizer (RSS 2.0, Atom, etc.)
48
48
  email: webslideshow@googlegroups.com
49
49
  executables: []