feedzirra 0.0.24 → 0.0.30
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/README.rdoc +207 -0
- data/Rakefile +19 -24
- data/lib/feedzirra.rb +7 -28
- data/lib/feedzirra/core_ext.rb +3 -0
- data/lib/{core_ext → feedzirra/core_ext}/date.rb +2 -4
- data/lib/{core_ext → feedzirra/core_ext}/string.rb +0 -0
- data/lib/feedzirra/feed.rb +99 -41
- data/lib/feedzirra/feed_entry_utilities.rb +12 -11
- data/lib/feedzirra/parser.rb +15 -0
- data/lib/feedzirra/parser/atom.rb +7 -13
- data/lib/feedzirra/parser/atom_entry.rb +4 -14
- data/lib/feedzirra/parser/atom_feed_burner.rb +4 -10
- data/lib/feedzirra/parser/atom_feed_burner_entry.rb +8 -13
- data/lib/feedzirra/parser/itunes_rss.rb +4 -4
- data/lib/feedzirra/parser/itunes_rss_item.rb +1 -1
- data/lib/feedzirra/parser/rss.rb +4 -10
- data/lib/feedzirra/parser/rss_entry.rb +2 -12
- data/lib/feedzirra/version.rb +3 -0
- data/spec/benchmarks/feed_benchmarks.rb +98 -0
- data/spec/benchmarks/feedzirra_benchmarks.rb +40 -0
- data/spec/benchmarks/fetching_benchmarks.rb +28 -0
- data/spec/benchmarks/parsing_benchmark.rb +30 -0
- data/spec/benchmarks/updating_benchmarks.rb +33 -0
- data/spec/feedzirra/feed_entry_utilities_spec.rb +1 -1
- data/spec/feedzirra/feed_spec.rb +38 -5
- data/spec/feedzirra/feed_utilities_spec.rb +7 -4
- data/spec/feedzirra/parser/atom_feed_burner_entry_spec.rb +5 -0
- data/spec/feedzirra/parser/atom_feed_burner_spec.rb +5 -1
- data/spec/feedzirra/parser/atom_spec.rb +5 -1
- data/spec/feedzirra/parser/itunes_rss_item_spec.rb +1 -1
- data/spec/feedzirra/parser/rss_entry_spec.rb +2 -1
- data/spec/feedzirra/parser/rss_spec.rb +5 -1
- data/spec/sample_feeds/run_against_sample.rb +20 -0
- data/spec/spec_helper.rb +10 -2
- metadata +141 -59
- data/README.textile +0 -208
- data/spec/spec.opts +0 -2
data/README.textile
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
h1. Feedzirra
|
2
|
-
|
3
|
-
"http://github.com/pauldix/feedzirra/tree/master":http://github.com/pauldix/feedzirra/tree/master
|
4
|
-
|
5
|
-
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.
|
6
|
-
|
7
|
-
h2. Summary
|
8
|
-
|
9
|
-
A feed fetching and parsing library that treats the internet like Godzilla treats Japan: it dominates and eats all.
|
10
|
-
|
11
|
-
h2. Description
|
12
|
-
|
13
|
-
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.
|
14
|
-
|
15
|
-
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.
|
16
|
-
|
17
|
-
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.
|
18
|
-
|
19
|
-
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.
|
20
|
-
|
21
|
-
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.
|
22
|
-
|
23
|
-
h2. Installation
|
24
|
-
|
25
|
-
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:
|
26
|
-
|
27
|
-
<pre>
|
28
|
-
gem sources -a http://gems.github.com # if you haven't already
|
29
|
-
gem install pauldix-feedzirra
|
30
|
-
</pre>
|
31
|
-
|
32
|
-
<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.
|
33
|
-
|
34
|
-
If you see this error when doing a require:
|
35
|
-
|
36
|
-
<pre>
|
37
|
-
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- curb_core (LoadError)
|
38
|
-
</pre>
|
39
|
-
|
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
|
-
|
44
|
-
<pre>
|
45
|
-
NoMethodError: undefined method `on_success' for #<Curl::Easy:0x1182724>
|
46
|
-
from ./lib/feedzirra/feed.rb:88:in `add_url_to_multi'
|
47
|
-
</pre>
|
48
|
-
|
49
|
-
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.
|
50
|
-
|
51
|
-
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:
|
52
|
-
|
53
|
-
<pre>
|
54
|
-
sudo apt-get install libcurl4-gnutls-dev
|
55
|
-
</pre>
|
56
|
-
|
57
|
-
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.
|
58
|
-
|
59
|
-
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.
|
60
|
-
|
61
|
-
h2. Usage
|
62
|
-
|
63
|
-
"A gist of the following code":http://gist.github.com/57285
|
64
|
-
"A gist of how to do updates on feeds":http://gist.github.com/132671
|
65
|
-
|
66
|
-
<pre>
|
67
|
-
require 'feedzirra'
|
68
|
-
|
69
|
-
# fetching a single feed
|
70
|
-
feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing")
|
71
|
-
|
72
|
-
# feed and entries accessors
|
73
|
-
feed.title # => "Paul Dix Explains Nothing"
|
74
|
-
feed.url # => "http://www.pauldix.net"
|
75
|
-
feed.feed_url # => "http://feeds.feedburner.com/PaulDixExplainsNothing"
|
76
|
-
feed.etag # => "GunxqnEP4NeYhrqq9TyVKTuDnh0"
|
77
|
-
feed.last_modified # => Sat Jan 31 17:58:16 -0500 2009 # it's a Time object
|
78
|
-
|
79
|
-
entry = feed.entries.first
|
80
|
-
entry.title # => "Ruby Http Client Library Performance"
|
81
|
-
entry.url # => "http://www.pauldix.net/2009/01/ruby-http-client-library-performance.html"
|
82
|
-
entry.author # => "Paul Dix"
|
83
|
-
entry.summary # => "..."
|
84
|
-
entry.content # => "..."
|
85
|
-
entry.published # => Thu Jan 29 17:00:19 UTC 2009 # it's a Time object
|
86
|
-
entry.categories # => ["...", "..."]
|
87
|
-
|
88
|
-
# sanitizing an entry's content
|
89
|
-
entry.title.sanitize # => returns the title with harmful stuff escaped
|
90
|
-
entry.author.sanitize # => returns the author with harmful stuff escaped
|
91
|
-
entry.content.sanitize # => returns the content with harmful stuff escaped
|
92
|
-
entry.content.sanitize! # => returns content with harmful stuff escaped and replaces original (also exists for author and title)
|
93
|
-
entry.sanitize! # => sanitizes the entry's title, author, and content in place (as in, it changes the value to clean versions)
|
94
|
-
feed.sanitize_entries! # => sanitizes all entries in place
|
95
|
-
|
96
|
-
# updating a single feed
|
97
|
-
updated_feed = Feedzirra::Feed.update(feed)
|
98
|
-
|
99
|
-
# an updated feed has the following extra accessors
|
100
|
-
updated_feed.updated? # returns true if any of the feed attributes have been modified. will return false if only new entries
|
101
|
-
updated_feed.new_entries # a collection of the entry objects that are newer than the latest in the feed before update
|
102
|
-
|
103
|
-
# fetching multiple feeds
|
104
|
-
feed_urls = ["http://feeds.feedburner.com/PaulDixExplainsNothing", "http://feeds.feedburner.com/trottercashion"]
|
105
|
-
feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
|
106
|
-
|
107
|
-
# feeds is now a hash with the feed_urls as keys and the parsed feed objects as values. If an error was thrown
|
108
|
-
# there will be a Fixnum of the http response code instead of a feed object
|
109
|
-
|
110
|
-
# updating multiple feeds. it expects a collection of feed objects
|
111
|
-
updated_feeds = Feedzirra::Feed.update(feeds.values)
|
112
|
-
|
113
|
-
# defining custom behavior on failure or success. note that a return status of 304 (not updated) will call the on_success handler
|
114
|
-
feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing",
|
115
|
-
:on_success => lambda {|feed| puts feed.title },
|
116
|
-
:on_failure => lambda {|url, response_code, response_header, response_body| puts response_body })
|
117
|
-
# if a collection was passed into fetch_and_parse, the handlers will be called for each one
|
118
|
-
|
119
|
-
# the behavior for the handlers when using Feedzirra::Feed.update is slightly different. The feed passed into on_success will be
|
120
|
-
# the updated feed with the standard updated accessors. on failure it will be the original feed object passed into update
|
121
|
-
|
122
|
-
# You can add custom parsing to the feed entry classes. Say you want the wfw:comments fields in an entry
|
123
|
-
Feedzirra::Feed.add_common_feed_entry_element("wfw:commentRss", :as => :comment_rss)
|
124
|
-
# The arguments are the same as the SAXMachine arguments for the element method. For more example usage look at the RSSEntry and
|
125
|
-
# AtomEntry classes. Now you can access those in an atom feed:
|
126
|
-
Feedzirra::Feed.parse(some_atom_xml).entries.first.comment_rss_ # => wfw:commentRss is now parsed!
|
127
|
-
|
128
|
-
|
129
|
-
# You can also define your own parsers and add them to the ones Feedzirra knows about. Here's an example that adds
|
130
|
-
# ITunesRSS parsing. It's included in the library, but not part of Feedzirra by default because some of the field names
|
131
|
-
# differ from other classes, thus breaking normalization.
|
132
|
-
Feedzirra::Feed.add_feed_class(ITunesRSS) # now all feeds will be checked to see if they match ITunesRSS before others
|
133
|
-
|
134
|
-
# 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.
|
135
|
-
# You'll have to do it on its own like so:
|
136
|
-
Feedzirra::Feed.fetch_and_parse(some_url, :http_authentication => ["myusername", "mypassword"])
|
137
|
-
|
138
|
-
# Defining custom parsers
|
139
|
-
# TODO: the functionality is here, just write some good examples that show how to do this
|
140
|
-
</pre>
|
141
|
-
|
142
|
-
h2. Benchmarks
|
143
|
-
|
144
|
-
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
|
145
|
-
|
146
|
-
<pre>
|
147
|
-
feedzirra 5.170000 1.290000 6.460000 ( 18.917796)
|
148
|
-
rfeedparser 104.260000 12.220000 116.480000 (244.799063)
|
149
|
-
feed-normalizer 66.250000 4.010000 70.260000 (191.589862)
|
150
|
-
</pre>
|
151
|
-
|
152
|
-
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.
|
153
|
-
|
154
|
-
<pre>
|
155
|
-
feedzirra 0.500000 0.030000 0.530000 ( 0.658744)
|
156
|
-
rfeedparser 8.400000 1.110000 9.510000 ( 11.839827)
|
157
|
-
feed-normalizer 5.980000 0.160000 6.140000 ( 7.576140)
|
158
|
-
</pre>
|
159
|
-
|
160
|
-
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.
|
161
|
-
|
162
|
-
<pre>
|
163
|
-
feedzirra fetch and parse 4.010000 0.710000 4.720000 ( 15.110101)
|
164
|
-
feedzirra update 0.660000 0.280000 0.940000 ( 5.152709)
|
165
|
-
</pre>
|
166
|
-
|
167
|
-
h2. Next Steps
|
168
|
-
|
169
|
-
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.
|
170
|
-
|
171
|
-
Here are some more specific TODOs.
|
172
|
-
* Fix the iTunes parser so things are normalized again
|
173
|
-
* Fix the Zlib deflate error
|
174
|
-
* Fix this error: http://github.com/inbox/70508
|
175
|
-
* Convert to use Typhoeus instead of taf2-curb
|
176
|
-
* Make the entries parse all link fields
|
177
|
-
* Make a feedzirra-rails gem to integrate feedzirra seamlessly with Rails and ActiveRecord.
|
178
|
-
* Create a super sweet DSL for defining new parsers.
|
179
|
-
* Test against Ruby 1.9.1 and fix any bugs.
|
180
|
-
* Clean up the fetching code inside feed.rb so it doesn't suck so hard.
|
181
|
-
* Readdress how feeds determine if they can parse a document. Maybe I should use namespaces instead?
|
182
|
-
|
183
|
-
h2. LICENSE
|
184
|
-
|
185
|
-
(The MIT License)
|
186
|
-
|
187
|
-
Copyright (c) 2009:
|
188
|
-
|
189
|
-
"Paul Dix":http://pauldix.net
|
190
|
-
|
191
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
192
|
-
a copy of this software and associated documentation files (the
|
193
|
-
'Software'), to deal in the Software without restriction, including
|
194
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
195
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
196
|
-
permit persons to whom the Software is furnished to do so, subject to
|
197
|
-
the following conditions:
|
198
|
-
|
199
|
-
The above copyright notice and this permission notice shall be
|
200
|
-
included in all copies or substantial portions of the Software.
|
201
|
-
|
202
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
203
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
204
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
205
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
206
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
207
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
208
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/spec/spec.opts
DELETED