Spectives-feedzirra 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.rdoc +169 -0
  2. data/README.textile +205 -0
  3. data/Rakefile +56 -0
  4. data/lib/core_ext/date.rb +21 -0
  5. data/lib/core_ext/string.rb +9 -0
  6. data/lib/feedzirra/feed.rb +334 -0
  7. data/lib/feedzirra/feed_entry_utilities.rb +45 -0
  8. data/lib/feedzirra/feed_utilities.rb +71 -0
  9. data/lib/feedzirra/parser/atom.rb +35 -0
  10. data/lib/feedzirra/parser/atom_entry.rb +41 -0
  11. data/lib/feedzirra/parser/itunes_category.rb +12 -0
  12. data/lib/feedzirra/parser/mrss_category.rb +11 -0
  13. data/lib/feedzirra/parser/mrss_content.rb +48 -0
  14. data/lib/feedzirra/parser/mrss_copyright.rb +10 -0
  15. data/lib/feedzirra/parser/mrss_credit.rb +11 -0
  16. data/lib/feedzirra/parser/mrss_group.rb +37 -0
  17. data/lib/feedzirra/parser/mrss_hash.rb +10 -0
  18. data/lib/feedzirra/parser/mrss_player.rb +11 -0
  19. data/lib/feedzirra/parser/mrss_rating.rb +10 -0
  20. data/lib/feedzirra/parser/mrss_restriction.rb +11 -0
  21. data/lib/feedzirra/parser/mrss_text.rb +13 -0
  22. data/lib/feedzirra/parser/mrss_thumbnail.rb +11 -0
  23. data/lib/feedzirra/parser/rss.rb +83 -0
  24. data/lib/feedzirra/parser/rss_entry.rb +83 -0
  25. data/lib/feedzirra/parser/rss_image.rb +15 -0
  26. data/lib/feedzirra.rb +44 -0
  27. data/spec/benchmarks/feed_benchmarks.rb +98 -0
  28. data/spec/benchmarks/feedzirra_benchmarks.rb +40 -0
  29. data/spec/benchmarks/fetching_benchmarks.rb +28 -0
  30. data/spec/benchmarks/parsing_benchmark.rb +30 -0
  31. data/spec/benchmarks/updating_benchmarks.rb +33 -0
  32. data/spec/feedzirra/feed_entry_utilities_spec.rb +52 -0
  33. data/spec/feedzirra/feed_spec.rb +546 -0
  34. data/spec/feedzirra/feed_utilities_spec.rb +149 -0
  35. data/spec/feedzirra/parser/atom_entry_spec.rb +49 -0
  36. data/spec/feedzirra/parser/atom_feed_burner_entry_spec.rb +42 -0
  37. data/spec/feedzirra/parser/atom_feed_burner_spec.rb +39 -0
  38. data/spec/feedzirra/parser/atom_spec.rb +43 -0
  39. data/spec/feedzirra/parser/mrss_content_spec.rb +32 -0
  40. data/spec/feedzirra/parser/rss_entry_spec.rb +154 -0
  41. data/spec/feedzirra/parser/rss_spec.rb +93 -0
  42. data/spec/sample_feeds/run_against_sample.rb +20 -0
  43. data/spec/spec_helper.rb +62 -0
  44. metadata +154 -0
data/README.rdoc ADDED
@@ -0,0 +1,169 @@
1
+ == Feedzirra
2
+
3
+ I'd like feedback on the api and any bugs encountered on feeds in the wild. I've set up a {google group here}[http://groups.google.com/group/feedzirra].
4
+
5
+ === Description
6
+
7
+ Feedzirra is a feed library that is designed to get and update many feeds as quickly as possible. This includes using libcurl-multi through the taf2-curb[link:http://github.com/taf2/curb/tree/master] gem for faster http gets, and libxml through nokogiri[link:http://github.com/tenderlove/nokogiri/tree/master] and sax-machine[link:http://github.com/pauldix/sax-machine/tree/master] for faster parsing.
8
+
9
+ Once you have fetched feeds using Feedzirra, they can be updated using the feed objects. Feedzirra automatically inserts etag and last-modified information from the http response headers to lower bandwidth usage, eliminate unnecessary parsing, and make things speedier in general.
10
+
11
+ Another feature present in Feedzirra is the ability to create callback functions that get called "on success" and "on failure" when getting a feed. This makes it easy to do things like log errors or update data stores.
12
+
13
+ The fetching and parsing logic have been decoupled so that either of them can be used in isolation if you'd prefer not to use everything that Feedzirra offers. However, the code examples below use helper methods in the Feed class that put everything together to make things as simple as possible.
14
+
15
+ The final feature of Feedzirra is the ability to define custom parsing classes. In truth, Feedzirra could be used to parse much more than feeds. Microformats, page scraping, and almost anything else are fair game.
16
+
17
+ === Installation
18
+
19
+ For now Feedzirra exists only on github. It also has a few gem requirements that are only on github. Before you start you need to have libcurl[link:http://curl.haxx.se/] and libxml[link:http://xmlsoft.org/] installed. If you're on Leopard you have both. Otherwise, you'll need to grab them. Once you've got those libraries, these are the gems that get used: nokogiri, pauldix-sax-machine, taf2-curb (note that this is a fork that lives on github and not the Ruby Forge version of curb), and pauldix-feedzirra. The feedzirra gemspec has all the dependencies so you should be able to get up and running with the standard github gem install routine:
20
+
21
+ gem sources -a http://gems.github.com # if you haven't already
22
+ gem install pauldix-feedzirra
23
+
24
+ *NOTE:*Some people have been reporting a few issues related to installation. First, the Ruby Forge version of curb is not what you want. It will not work. Nor will the curl-multi gem that lives on Ruby Forge. You have to get the taf2-curb[link:http://github.com/taf2/curb/tree/master] fork installed.
25
+
26
+ If you see this error when doing a require:
27
+
28
+ /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- curb_core (LoadError)
29
+
30
+ It means that the taf2-curb gem didn't build correctly. To resolve this you can do a git clone git://github.com/taf2/curb.git then run rake gem in the curb directory, then sudo gem install pkg/curb-0.2.4.0.gem. After that you should be good.
31
+
32
+ If you see something like this when trying to run it:
33
+
34
+ NoMethodError: undefined method `on_success' for #<Curl::Easy:0x1182724>
35
+ from ./lib/feedzirra/feed.rb:88:in `add_url_to_multi'
36
+
37
+ This means that you are requiring curl-multi or the Ruby Forge version of Curb somewhere. You can't use those and need to get the taf2 version up and running.
38
+
39
+ If you're on Debian or Ubuntu and getting errors while trying to install the taf2-curb gem, it could be because you don't have the latest version of libcurl installed. Do this to fix:
40
+
41
+ sudo apt-get install libcurl4-gnutls-dev
42
+
43
+ Another problem could be if you are running Mac Ports and you have libcurl installed through there. You need to uninstall it for curb to work! The version in Mac Ports is old and doesn't play nice with curb. If you're running Leopard, you can just uninstall and you should be golden. If you're on an older version of OS X, you'll then need to {download curl}[http://curl.haxx.se/download.html] and build from source. Then you'll have to install the taf2-curb gem again. You might have to perform the step above.
44
+
45
+ If you're still having issues, please let me know on the mailing list. Also, {Todd Fisher (taf2)}[link:http://github.com/taf2] is working on fixing the gem install. Please send him a full error report.
46
+
47
+ === Usage
48
+
49
+ {A gist of the following code}[link:http://gist.github.com/57285]
50
+
51
+ require 'feedzirra'
52
+
53
+ # fetching a single feed
54
+ feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing")
55
+
56
+ # feed and entries accessors
57
+ feed.title # => "Paul Dix Explains Nothing"
58
+ feed.url # => "http://www.pauldix.net"
59
+ feed.feed_url # => "http://feeds.feedburner.com/PaulDixExplainsNothing"
60
+ feed.etag # => "GunxqnEP4NeYhrqq9TyVKTuDnh0"
61
+ feed.last_modified # => Sat Jan 31 17:58:16 -0500 2009 # it's a Time object
62
+
63
+ entry = feed.entries.first
64
+ entry.title # => "Ruby Http Client Library Performance"
65
+ entry.url # => "http://www.pauldix.net/2009/01/ruby-http-client-library-performance.html"
66
+ entry.author # => "Paul Dix"
67
+ entry.summary # => "..."
68
+ entry.content # => "..."
69
+ entry.published # => Thu Jan 29 17:00:19 UTC 2009 # it's a Time object
70
+ entry.categories # => ["...", "..."]
71
+
72
+ # sanitizing an entry's content
73
+ entry.title.sanitize # => returns the title with harmful stuff escaped
74
+ entry.author.sanitize # => returns the author with harmful stuff escaped
75
+ entry.content.sanitize # => returns the content with harmful stuff escaped
76
+ entry.content.sanitize! # => returns content with harmful stuff escaped and replaces original (also exists for author and title)
77
+ entry.sanitize! # => sanitizes the entry's title, author, and content in place (as in, it changes the value to clean versions)
78
+ feed.sanitize_entries! # => sanitizes all entries in place
79
+
80
+ # updating a single feed
81
+ updated_feed = Feedzirra::Feed.update(feed)
82
+
83
+ # an updated feed has the following extra accessors
84
+ updated_feed.updated? # returns true if any of the feed attributes have been modified. will return false if only new entries
85
+ updated_feed.new_entries # a collection of the entry objects that are newer than the latest in the feed before update
86
+
87
+ # fetching multiple feeds
88
+ feed_urls = ["http://feeds.feedburner.com/PaulDixExplainsNothing", "http://feeds.feedburner.com/trottercashion"]
89
+ feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
90
+
91
+ # feeds is now a hash with the feed_urls as keys and the parsed feed objects as values. If an error was thrown
92
+ # there will be a Fixnum of the http response code instead of a feed object
93
+
94
+ # updating multiple feeds. it expects a collection of feed objects
95
+ updated_feeds = Feedzirra::Feed.update(feeds.values)
96
+
97
+ # defining custom behavior on failure or success. note that a return status of 304 (not updated) will call the on_success handler
98
+ feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing",
99
+ :on_success => lambda {|feed| puts feed.title },
100
+ :on_failure => lambda {|url, response_code, response_header, response_body| puts response_body })
101
+ # if a collection was passed into fetch_and_parse, the handlers will be called for each one
102
+
103
+ # the behavior for the handlers when using Feedzirra::Feed.update is slightly different. The feed passed into on_success will be
104
+ # the updated feed with the standard updated accessors. on failure it will be the original feed object passed into update
105
+
106
+ # Defining custom parsers
107
+ # TODO: the functionality is here, just write some good examples that show how to do this
108
+
109
+ === Extending
110
+
111
+ === Benchmarks
112
+
113
+ One of the goals of Feedzirra is speed. This includes not only parsing, but fetching multiple feeds as quickly as possible. I ran a benchmark getting 20 feeds 10 times using Feedzirra, rFeedParser, and FeedNormalizer. For more details the {benchmark code can be found in the project in spec/benchmarks/feedzirra_benchmarks.rb}[http://github.com/pauldix/feedzirra/blob/7fb5634c5c16e9c6ec971767b462c6518cd55f5d/spec/benchmarks/feedzirra_benchmarks.rb]
114
+
115
+ feedzirra 5.170000 1.290000 6.460000 ( 18.917796)
116
+ rfeedparser 104.260000 12.220000 116.480000 (244.799063)
117
+ feed-normalizer 66.250000 4.010000 70.260000 (191.589862)
118
+
119
+ The result of that benchmark is a bit sketchy because of the network variability. Running 10 times against the same 20 feeds was meant to smooth some of that out. However, there is also a {benchmark comparing parsing speed in spec/benchmarks/parsing_benchmark.rb}[http://github.com/pauldix/feedzirra/blob/7fb5634c5c16e9c6ec971767b462c6518cd55f5d/spec/benchmarks/parsing_benchmark.rb] on an atom feed.
120
+
121
+ feedzirra 0.500000 0.030000 0.530000 ( 0.658744)
122
+ rfeedparser 8.400000 1.110000 9.510000 ( 11.839827)
123
+ feed-normalizer 5.980000 0.160000 6.140000 ( 7.576140)
124
+
125
+ There's also a {benchmark that shows the results of using Feedzirra to perform updates on feeds}[http://github.com/pauldix/feedzirra/blob/45d64319544c61a4c9eb9f7f825c73b9f9030cb3/spec/benchmarks/updating_benchmarks.rb] you've already pulled in. I tested against 179 feeds. The first is the initial pull and the second is an update 65 seconds later. I'm not sure how many of them support etag and last-modified, so performance may be better or worse depending on what feeds you're requesting.
126
+
127
+ feedzirra fetch and parse 4.010000 0.710000 4.720000 ( 15.110101)
128
+ feedzirra update 0.660000 0.280000 0.940000 ( 5.152709)
129
+
130
+ === TODO
131
+
132
+ This thing needs to hammer on many different feeds in the wild. I'm sure there will be bugs. I want to find them and crush them. I didn't bother using the test suite for feedparser. i wanted to start fresh.
133
+
134
+ Here are some more specific TODOs.
135
+ * Make a feedzirra-rails gem to integrate feedzirra seamlessly with Rails and ActiveRecord.
136
+ * Add support for authenticated feeds.
137
+ * Create a super sweet DSL for defining new parsers.
138
+ * Test against Ruby 1.9.1 and fix any bugs.
139
+ * I'm not keeping track of modified on entries. Should I add this?
140
+ * Clean up the fetching code inside feed.rb so it doesn't suck so hard.
141
+ * Make the feed_spec actually mock stuff out so it doesn't hit the net.
142
+ * Readdress how feeds determine if they can parse a document. Maybe I should use namespaces instead?
143
+
144
+ === LICENSE
145
+
146
+ (The MIT License)
147
+
148
+ Copyright (c) 2009:
149
+
150
+ {Paul Dix}[http://pauldix.net]
151
+
152
+ Permission is hereby granted, free of charge, to any person obtaining
153
+ a copy of this software and associated documentation files (the
154
+ 'Software'), to deal in the Software without restriction, including
155
+ without limitation the rights to use, copy, modify, merge, publish,
156
+ distribute, sublicense, and/or sell copies of the Software, and to
157
+ permit persons to whom the Software is furnished to do so, subject to
158
+ the following conditions:
159
+
160
+ The above copyright notice and this permission notice shall be
161
+ included in all copies or substantial portions of the Software.
162
+
163
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
164
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
165
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
166
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
167
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
168
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
169
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,205 @@
1
+ "Changes made from Paul's tree":#changes
2
+
3
+ h1. Feedzirra
4
+
5
+ "http://github.com/pauldix/feedzirra/tree/master":http://github.com/pauldix/feedzirra/tree/master
6
+
7
+ I'd like feedback on the api and any bugs encountered on feeds in the wild. I've set up a "google group here":http://groups.google.com/group/feedzirra.
8
+
9
+ h2. Summary
10
+
11
+ A feed fetching and parsing library that treats the internet like Godzilla treats Japan: it dominates and eats all.
12
+
13
+ h2. Description
14
+
15
+ Feedzirra is a feed library that is designed to get and update many feeds as quickly as possible. This includes using libcurl-multi through the "taf2-curb":http://github.com/taf2/curb/tree/master gem for faster http gets, and libxml through "nokogiri":http://github.com/tenderlove/nokogiri/tree/master and "sax-machine":http://github.com/pauldix/sax-machine/tree/master for faster parsing.
16
+
17
+ Once you have fetched feeds using Feedzirra, they can be updated using the feed objects. Feedzirra automatically inserts etag and last-modified information from the http response headers to lower bandwidth usage, eliminate unnecessary parsing, and make things speedier in general.
18
+
19
+ Another feature present in Feedzirra is the ability to create callback functions that get called "on success" and "on failure" when getting a feed. This makes it easy to do things like log errors or update data stores.
20
+
21
+ The fetching and parsing logic have been decoupled so that either of them can be used in isolation if you'd prefer not to use everything that Feedzirra offers. However, the code examples below use helper methods in the Feed class that put everything together to make things as simple as possible.
22
+
23
+ The final feature of Feedzirra is the ability to define custom parsing classes. In truth, Feedzirra could be used to parse much more than feeds. Microformats, page scraping, and almost anything else are fair game.
24
+
25
+ h2. Installation
26
+
27
+ For now Feedzirra exists only on github. It also has a few gem requirements that are only on github. Before you start you need to have "libcurl":http://curl.haxx.se/ and "libxml":http://xmlsoft.org/ installed. If you're on Leopard you have both. Otherwise, you'll need to grab them. Once you've got those libraries, these are the gems that get used: nokogiri, pauldix-sax-machine, taf2-curb (note that this is a fork that lives on github and not the Ruby Forge version of curb), and pauldix-feedzirra. The feedzirra gemspec has all the dependencies so you should be able to get up and running with the standard github gem install routine:
28
+
29
+ <pre>
30
+ gem sources -a http://gems.github.com # if you haven't already
31
+ gem install pauldix-feedzirra
32
+ </pre>
33
+
34
+ <b>NOTE:</b>Some people have been reporting a few issues related to installation. First, the Ruby Forge version of curb is not what you want. It will not work. Nor will the curl-multi gem that lives on Ruby Forge. You have to get the "taf2-curb":http://github.com/taf2/curb/tree/master fork installed.
35
+
36
+ If you see this error when doing a require:
37
+ <pre>
38
+ /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- curb_core (LoadError)
39
+ </pre>
40
+ It means that the taf2-curb gem didn't build correctly. To resolve this you can do a git clone git://github.com/taf2/curb.git then run rake gem in the curb directory, then sudo gem install pkg/curb-0.2.4.0.gem. After that you should be good.
41
+
42
+ If you see something like this when trying to run it:
43
+ <pre>
44
+ NoMethodError: undefined method `on_success' for #<Curl::Easy:0x1182724>
45
+ from ./lib/feedzirra/feed.rb:88:in `add_url_to_multi'
46
+ </pre>
47
+ This means that you are requiring curl-multi or the Ruby Forge version of Curb somewhere. You can't use those and need to get the taf2 version up and running.
48
+
49
+ If you're on Debian or Ubuntu and getting errors while trying to install the taf2-curb gem, it could be because you don't have the latest version of libcurl installed. Do this to fix:
50
+ <pre>
51
+ sudo apt-get install libcurl4-gnutls-dev
52
+ </pre>
53
+
54
+ Another problem could be if you are running Mac Ports and you have libcurl installed through there. You need to uninstall it for curb to work! The version in Mac Ports is old and doesn't play nice with curb. If you're running Leopard, you can just uninstall and you should be golden. If you're on an older version of OS X, you'll then need to "download curl":http://curl.haxx.se/download.html and build from source. Then you'll have to install the taf2-curb gem again. You might have to perform the step above.
55
+
56
+ If you're still having issues, please let me know on the mailing list. Also, "Todd Fisher (taf2)":http://github.com/taf2 is working on fixing the gem install. Please send him a full error report.
57
+
58
+ h2. Usage
59
+
60
+ "A gist of the following code":http://gist.github.com/57285
61
+ <pre>
62
+ require 'feedzirra'
63
+
64
+ # fetching a single feed
65
+ feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing")
66
+
67
+ # feed and entries accessors
68
+ feed.title # => "Paul Dix Explains Nothing"
69
+ feed.url # => "http://www.pauldix.net"
70
+ feed.feed_url # => "http://feeds.feedburner.com/PaulDixExplainsNothing"
71
+ feed.etag # => "GunxqnEP4NeYhrqq9TyVKTuDnh0"
72
+ feed.last_modified # => Sat Jan 31 17:58:16 -0500 2009 # it's a Time object
73
+
74
+ entry = feed.entries.first
75
+ entry.title # => "Ruby Http Client Library Performance"
76
+ entry.url # => "http://www.pauldix.net/2009/01/ruby-http-client-library-performance.html"
77
+ entry.author # => "Paul Dix"
78
+ entry.summary # => "..."
79
+ entry.content # => "..."
80
+ entry.published # => Thu Jan 29 17:00:19 UTC 2009 # it's a Time object
81
+ entry.categories # => ["...", "..."]
82
+
83
+ # sanitizing an entry's content
84
+ entry.title.sanitize # => returns the title with harmful stuff escaped
85
+ entry.author.sanitize # => returns the author with harmful stuff escaped
86
+ entry.content.sanitize # => returns the content with harmful stuff escaped
87
+ entry.content.sanitize! # => returns content with harmful stuff escaped and replaces original (also exists for author and title)
88
+ entry.sanitize! # => sanitizes the entry's title, author, and content in place (as in, it changes the value to clean versions)
89
+ feed.sanitize_entries! # => sanitizes all entries in place
90
+
91
+ # updating a single feed
92
+ updated_feed = Feedzirra::Feed.update(feed)
93
+
94
+ # an updated feed has the following extra accessors
95
+ updated_feed.updated? # returns true if any of the feed attributes have been modified. will return false if only new entries
96
+ updated_feed.new_entries # a collection of the entry objects that are newer than the latest in the feed before update
97
+
98
+ # fetching multiple feeds
99
+ feed_urls = ["http://feeds.feedburner.com/PaulDixExplainsNothing", "http://feeds.feedburner.com/trottercashion"]
100
+ feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
101
+
102
+ # feeds is now a hash with the feed_urls as keys and the parsed feed objects as values. If an error was thrown
103
+ # there will be a Fixnum of the http response code instead of a feed object
104
+
105
+ # updating multiple feeds. it expects a collection of feed objects
106
+ updated_feeds = Feedzirra::Feed.update(feeds.values)
107
+
108
+ # defining custom behavior on failure or success. note that a return status of 304 (not updated) will call the on_success handler
109
+ feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing",
110
+ :on_success => lambda {|feed| puts feed.title },
111
+ :on_failure => lambda {|url, response_code, response_header, response_body| puts response_body })
112
+ # if a collection was passed into fetch_and_parse, the handlers will be called for each one
113
+
114
+ # the behavior for the handlers when using Feedzirra::Feed.update is slightly different. The feed passed into on_success will be
115
+ # the updated feed with the standard updated accessors. on failure it will be the original feed object passed into update
116
+
117
+ # You can add custom parsing to the feed entry classes. Say you want the wfw:comments fields in an entry
118
+ Feedzirra::Feed.add_common_feed_entry_element("wfw:commentRss", :as => :comment_rss)
119
+ # The arguments are the same as the SAXMachine arguments for the element method. For more example usage look at the RSSEntry and
120
+ # AtomEntry classes. Now you can access those in an atom feed:
121
+ Feedzirra::Feed.parse(some_atom_xml).entries.first.comment_rss_ # => wfw:commentRss is now parsed!
122
+
123
+
124
+ # You can also define your own parsers and add them to the ones Feedzirra knows about. Here's an example that adds
125
+ # ITunesRSS parsing. It's included in the library, but not part of Feedzirra by default because some of the field names
126
+ # differ from other classes, thus breaking normalization.
127
+ Feedzirra::Feed.add_feed_class(ITunesRSS) # now all feeds will be checked to see if they match ITunesRSS before others
128
+
129
+ # You can also access http basic auth feeds. Unfortunately, you can't get to these inside of a bulk get of a bunch of feeds.
130
+ # You'll have to do it on its own like so:
131
+ Feedzirra::Feed.fetch_and_parse(some_url, :http_authentication => ["myusername", "mypassword"])
132
+
133
+ # Defining custom parsers
134
+ # TODO: the functionality is here, just write some good examples that show how to do this
135
+ </pre>
136
+
137
+ h2. Benchmarks
138
+
139
+ One of the goals of Feedzirra is speed. This includes not only parsing, but fetching multiple feeds as quickly as possible. I ran a benchmark getting 20 feeds 10 times using Feedzirra, rFeedParser, and FeedNormalizer. For more details the "benchmark code can be found in the project in spec/benchmarks/feedzirra_benchmarks.rb":http://github.com/pauldix/feedzirra/blob/7fb5634c5c16e9c6ec971767b462c6518cd55f5d/spec/benchmarks/feedzirra_benchmarks.rb
140
+ <pre>
141
+ feedzirra 5.170000 1.290000 6.460000 ( 18.917796)
142
+ rfeedparser 104.260000 12.220000 116.480000 (244.799063)
143
+ feed-normalizer 66.250000 4.010000 70.260000 (191.589862)
144
+ </pre>
145
+ The result of that benchmark is a bit sketchy because of the network variability. Running 10 times against the same 20 feeds was meant to smooth some of that out. However, there is also a "benchmark comparing parsing speed in spec/benchmarks/parsing_benchmark.rb":http://github.com/pauldix/feedzirra/blob/7fb5634c5c16e9c6ec971767b462c6518cd55f5d/spec/benchmarks/parsing_benchmark.rb on an atom feed.
146
+ <pre>
147
+ feedzirra 0.500000 0.030000 0.530000 ( 0.658744)
148
+ rfeedparser 8.400000 1.110000 9.510000 ( 11.839827)
149
+ feed-normalizer 5.980000 0.160000 6.140000 ( 7.576140)
150
+ </pre>
151
+ There's also a "benchmark that shows the results of using Feedzirra to perform updates on feeds":http://github.com/pauldix/feedzirra/blob/45d64319544c61a4c9eb9f7f825c73b9f9030cb3/spec/benchmarks/updating_benchmarks.rb you've already pulled in. I tested against 179 feeds. The first is the initial pull and the second is an update 65 seconds later. I'm not sure how many of them support etag and last-modified, so performance may be better or worse depending on what feeds you're requesting.
152
+ <pre>
153
+ feedzirra fetch and parse 4.010000 0.710000 4.720000 ( 15.110101)
154
+ feedzirra update 0.660000 0.280000 0.940000 ( 5.152709)
155
+ </pre>
156
+
157
+ h2. Next Steps
158
+
159
+ This thing needs to hammer on many different feeds in the wild. I'm sure there will be bugs. I want to find them and crush them. I didn't bother using the test suite for feedparser. i wanted to start fresh.
160
+
161
+ Here are some more specific TODOs.
162
+ * Fix the iTunes parser so things are normalized again
163
+ * Fix the Zlib deflate error
164
+ * Fix this error: http://github.com/inbox/70508
165
+ * Convert to use Typhoeus instead of taf2-curb
166
+ * Make the entries parse all link fields
167
+ * Make a feedzirra-rails gem to integrate feedzirra seamlessly with Rails and ActiveRecord.
168
+ * Create a super sweet DSL for defining new parsers.
169
+ * Test against Ruby 1.9.1 and fix any bugs.
170
+ * Clean up the fetching code inside feed.rb so it doesn't suck so hard.
171
+ * Readdress how feeds determine if they can parse a document. Maybe I should use namespaces instead?
172
+
173
+ h2(#changes). Updates from Paul's tree
174
+
175
+ * Add in Media RSS support that should handle the spec with multiple content entries.
176
+ * Add in the missing support for nested iTunes Categories
177
+ * Combined iTunes into RSS, removed extra files
178
+ * Made element names more consistent across RSS and iTunes
179
+
180
+ h2. LICENSE
181
+
182
+ (The MIT License)
183
+
184
+ Copyright (c) 2009:
185
+
186
+ "Paul Dix":http://pauldix.net
187
+
188
+ Permission is hereby granted, free of charge, to any person obtaining
189
+ a copy of this software and associated documentation files (the
190
+ 'Software'), to deal in the Software without restriction, including
191
+ without limitation the rights to use, copy, modify, merge, publish,
192
+ distribute, sublicense, and/or sell copies of the Software, and to
193
+ permit persons to whom the Software is furnished to do so, subject to
194
+ the following conditions:
195
+
196
+ The above copyright notice and this permission notice shall be
197
+ included in all copies or substantial portions of the Software.
198
+
199
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
200
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
201
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
202
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
203
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
204
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
205
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require "spec"
2
+ require "spec/rake/spectask"
3
+ require 'rake/rdoctask'
4
+ require 'lib/feedzirra.rb'
5
+
6
+ # Grab recently touched specs
7
+ def recent_specs(touched_since)
8
+ recent_specs = FileList['app/**/*'].map do |path|
9
+
10
+ if File.mtime(path) > touched_since
11
+ spec = File.join('spec', File.dirname(path).split("/")[1..-1].join('/'),
12
+ "#{File.basename(path, ".*")}_spec.rb")
13
+ spec if File.exists?(spec)
14
+ end
15
+ end.compact
16
+
17
+ recent_specs += FileList['spec/**/*_spec.rb'].select do |path|
18
+ File.mtime(path) > touched_since
19
+ end
20
+ recent_specs.uniq
21
+ end
22
+
23
+ desc "Run all the tests"
24
+ task :default => :spec
25
+
26
+ # Tasks
27
+ Spec::Rake::SpecTask.new do |t|
28
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
29
+ t.spec_files = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ desc 'Run recent specs'
33
+ Spec::Rake::SpecTask.new("spec:recent") do |t|
34
+ t.spec_opts = ["--format","specdoc","--color"]
35
+ t.spec_files = recent_specs(Time.now - 600) # 10 min.
36
+ end
37
+
38
+ Spec::Rake::SpecTask.new('spec:rcov') do |t|
39
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
40
+ t.spec_files = FileList['spec/**/*_spec.rb']
41
+ t.rcov = true
42
+ t.rcov_opts = ['--exclude', 'spec,/usr/lib/ruby,/usr/local,/var/lib,/Library', '--text-report']
43
+ end
44
+
45
+ Rake::RDocTask.new do |rd|
46
+ rd.title = 'Feedzirra'
47
+ rd.rdoc_dir = 'rdoc'
48
+ rd.rdoc_files.include('README.rdoc', 'lib/feedzirra.rb', 'lib/feedzirra/**/*.rb')
49
+ rd.options = ["--quiet", "--opname", "index.html", "--line-numbers", "--inline-source", '--main', 'README.rdoc']
50
+ end
51
+
52
+ task :install do
53
+ rm_rf "*.gem"
54
+ puts `gem build feedzirra.gemspec`
55
+ puts `sudo gem install feedzirra-#{Feedzirra::VERSION}.gem`
56
+ end
@@ -0,0 +1,21 @@
1
+ # Date code pulled from:
2
+ # Ruby Cookbook by Lucas Carlson and Leonard Richardson
3
+ # Published by O'Reilly
4
+ # ISBN: 0-596-52369-6
5
+ class Date
6
+ def feed_utils_to_gm_time
7
+ feed_utils_to_time(new_offset, :gm)
8
+ end
9
+
10
+ def feed_utils_to_local_time
11
+ feed_utils_to_time(new_offset(DateTime.now.offset-offset), :local)
12
+ end
13
+
14
+ private
15
+ def feed_utils_to_time(dest, method)
16
+ #Convert a fraction of a day to a number of microseconds
17
+ usec = (dest.sec_fraction * 60 * 60 * 24 * (10**6)).to_i
18
+ Time.send(method, dest.year, dest.month, dest.day, dest.hour, dest.min,
19
+ dest.sec, usec)
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class String
2
+ def sanitize!
3
+ self.replace(sanitize)
4
+ end
5
+
6
+ def sanitize
7
+ Dryopteris.sanitize(self)
8
+ end
9
+ end