feedjira 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -10
- data/.travis.yml +1 -1
- data/CHANGELOG.md +76 -60
- data/Gemfile +3 -6
- data/LICENSE +26 -0
- data/README.md +6 -234
- data/Rakefile +6 -5
- data/lib/feedjira/feed.rb +2 -0
- data/lib/feedjira/parser.rb +1 -20
- data/lib/feedjira/version.rb +1 -1
- data/lib/feedjira.rb +18 -5
- data/spec/feedjira/feed_spec.rb +6 -1
- data/spec/sample_feeds.rb +29 -0
- data/spec/spec_helper.rb +3 -85
- metadata +19 -17
- data/Guardfile +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a95a55c16d70ffd628b86e4063a4a6bd5507451
|
4
|
+
data.tar.gz: e8b27d65d8e3734db3de73d85d0793f9c4aaba84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30e378d04980d3d60e21fbb2dddeb64c5db9dac7c83e0927fb7c6220201f86873432c738b7936c9dff5b00e1e19f782a8844a11225411891a3527b9ecc2494f6
|
7
|
+
data.tar.gz: 59f3590bea5343fa5e619d711e67e34ba8b33490b7d12a96bf456bcbe506e087ddac1662ced445e4ce8b779cb011496e22086fd951874c8b0468290a5ae17906
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Feedjira Changelog
|
2
2
|
|
3
|
+
## 1.1.0
|
4
|
+
|
5
|
+
* General
|
6
|
+
* Add 2.1 to list of supported Rubies, drop 1.9.2
|
7
|
+
* Remove Guard and Simplecov
|
8
|
+
* Extract sample feeds into RSpec helper module
|
9
|
+
* Random cleanup
|
10
|
+
* Quiet down default rake task
|
11
|
+
* Fix CHANGELOG links
|
12
|
+
* Point README at new site
|
13
|
+
|
14
|
+
* Enhancements
|
15
|
+
* Add language setting to curl options [#206][]
|
16
|
+
|
17
|
+
[#206]: https://github.com/feedjira/feedjira/pull/206
|
18
|
+
|
3
19
|
## 1.0.0
|
4
20
|
|
5
21
|
* Removed deprecated features
|
@@ -11,44 +27,44 @@
|
|
11
27
|
## 0.7.1
|
12
28
|
|
13
29
|
* Bugfix
|
14
|
-
* Don't use entry id for updating when feed doesn't provide it [
|
30
|
+
* Don't use entry id for updating when feed doesn't provide it [#205][]
|
15
31
|
|
16
|
-
[#205]: https://github.com/
|
32
|
+
[#205]: https://github.com/feedjira/feedjira/pull/205
|
17
33
|
|
18
34
|
## 0.7.0
|
19
35
|
|
20
36
|
* General
|
21
|
-
* README update for callback arity [
|
37
|
+
* README update for callback arity [#202][]
|
22
38
|
|
23
39
|
* Enhancements
|
24
|
-
* Add error info to `on_failure` callback [
|
40
|
+
* Add error info to `on_failure` callback [#194][]
|
25
41
|
* On failure callbacks get curl and error as args
|
26
|
-
* Bugfix for parsing dates that are ISO 8601 with milliseconds [
|
42
|
+
* Bugfix for parsing dates that are ISO 8601 with milliseconds [#203][]
|
27
43
|
|
28
|
-
[#194]: https://github.com/
|
29
|
-
[#202]: https://github.com/
|
30
|
-
[#203]: https://github.com/
|
44
|
+
[#194]: https://github.com/feedjira/feedjira/pull/194
|
45
|
+
[#202]: https://github.com/feedjira/feedjira/pull/202
|
46
|
+
[#203]: https://github.com/feedjira/feedjira/pull/203
|
31
47
|
|
32
48
|
## 0.6.0
|
33
49
|
|
34
50
|
* General
|
35
|
-
* Update expected parser classes in docs [
|
51
|
+
* Update expected parser classes in docs [#200][]
|
36
52
|
* Fix Rubinius issue with Travis
|
37
53
|
|
38
54
|
* Enhancements
|
39
|
-
* Added content to `itunes_rss_item` [
|
55
|
+
* Added content to `itunes_rss_item` [#198][]
|
40
56
|
* Allow user to pass a particular parser using `parse_with`
|
41
|
-
* Strip leading whitespace from XML [
|
42
|
-
* Parse out RSS version [
|
57
|
+
* Strip leading whitespace from XML [#196][]
|
58
|
+
* Parse out RSS version [#172][]
|
43
59
|
* Add generic preprocessing hook for Parsers
|
44
|
-
* Add preprocessing hook for Atom XHTML content [
|
60
|
+
* Add preprocessing hook for Atom XHTML content [#58][] [#130][]
|
45
61
|
|
46
|
-
[#58]: https://github.com/
|
47
|
-
[#130]: https://github.com/
|
48
|
-
[#172]: https://github.com/
|
49
|
-
[#196]: https://github.com/
|
50
|
-
[#198]: https://github.com/
|
51
|
-
[#200]: https://github.com/
|
62
|
+
[#58]: https://github.com/feedjira/feedjira/pull/58
|
63
|
+
[#130]: https://github.com/feedjira/feedjira/issues/130
|
64
|
+
[#172]: https://github.com/feedjira/feedjira/issues/172
|
65
|
+
[#196]: https://github.com/feedjira/feedjira/pull/196
|
66
|
+
[#198]: https://github.com/feedjira/feedjira/pull/198
|
67
|
+
[#200]: https://github.com/feedjira/feedjira/pull/200
|
52
68
|
|
53
69
|
## 0.5.0
|
54
70
|
|
@@ -59,45 +75,45 @@
|
|
59
75
|
* Upgrade to latest Rspec
|
60
76
|
|
61
77
|
* Enhancements
|
62
|
-
* Allow spaces in rss tag when checking parse-ability [
|
63
|
-
* Compare `entry_id` and `url` for finding new entries [
|
64
|
-
* Add closed captioned and order tags for iTunesRSSItem [
|
78
|
+
* Allow spaces in rss tag when checking parse-ability [#127][]
|
79
|
+
* Compare `entry_id` and `url` for finding new entries [#195][]
|
80
|
+
* Add closed captioned and order tags for iTunesRSSItem [#160][]
|
65
81
|
|
66
|
-
[#127]: https://github.com/
|
67
|
-
[#160]: https://github.com/
|
68
|
-
[#195]: https://github.com/
|
82
|
+
[#127]: https://github.com/feedjira/feedjira/pull/127
|
83
|
+
[#160]: https://github.com/feedjira/feedjira/pull/160
|
84
|
+
[#195]: https://github.com/feedjira/feedjira/pull/195
|
69
85
|
|
70
86
|
## 0.4.0
|
71
87
|
|
72
88
|
* Enhancements
|
73
|
-
* Raise when parser invokes its failure callback [
|
74
|
-
* Add PubSubHubbub hub urls as feed element [
|
75
|
-
* Add support for iTunes image in iTunes RSS item [
|
89
|
+
* Raise when parser invokes its failure callback [#159][]
|
90
|
+
* Add PubSubHubbub hub urls as feed element [#138][]
|
91
|
+
* Add support for iTunes image in iTunes RSS item [#164][]
|
76
92
|
|
77
93
|
* Bug fixes
|
78
|
-
* Use curb callbacks rather than response codes [
|
94
|
+
* Use curb callbacks rather than response codes [#161][]
|
79
95
|
|
80
|
-
[#138]: https://github.com/
|
81
|
-
[#159]: https://github.com/
|
82
|
-
[#161]: https://github.com/
|
83
|
-
[#164]: https://github.com/
|
96
|
+
[#138]: https://github.com/feedjira/feedjira/pull/138
|
97
|
+
[#159]: https://github.com/feedjira/feedjira/issues/159
|
98
|
+
[#161]: https://github.com/feedjira/feedjira/pull/161
|
99
|
+
[#164]: https://github.com/feedjira/feedjira/pull/164
|
84
100
|
|
85
101
|
## 0.3.0
|
86
102
|
|
87
103
|
* General
|
88
|
-
* Add CodeClimate badge [
|
104
|
+
* Add CodeClimate badge [#192][]
|
89
105
|
|
90
106
|
* Enhancements
|
91
|
-
* CURL SSL Version option [
|
92
|
-
* Cookie support for Curb [
|
107
|
+
* CURL SSL Version option [#156][]
|
108
|
+
* Cookie support for Curb [#98][]
|
93
109
|
|
94
110
|
* Deprecations
|
95
|
-
* For `ITunesRSSItem`, use `id` instead of `guid` [
|
111
|
+
* For `ITunesRSSItem`, use `id` instead of `guid` [#169][]
|
96
112
|
|
97
|
-
[#98]: https://github.com/
|
98
|
-
[#156]: https://github.com/
|
99
|
-
[#169]: https://github.com/
|
100
|
-
[#192]: https://github.com/
|
113
|
+
[#98]: https://github.com/feedjira/feedjira/pull/98
|
114
|
+
[#156]: https://github.com/feedjira/feedjira/pull/156
|
115
|
+
[#169]: https://github.com/feedjira/feedjira/pull/169
|
116
|
+
[#192]: https://github.com/feedjira/feedjira/pull/192
|
101
117
|
|
102
118
|
## 0.2.2
|
103
119
|
|
@@ -108,35 +124,35 @@
|
|
108
124
|
* README updates
|
109
125
|
|
110
126
|
* Enhancements
|
111
|
-
* Also use dc:identifier for `entry_id` [
|
127
|
+
* Also use dc:identifier for `entry_id` [#182][]
|
112
128
|
|
113
129
|
* Bug fixes
|
114
|
-
* Don't try to sanitize non-existent elements [
|
115
|
-
* Fix Rspec deprecations [
|
116
|
-
* Fix Travis [
|
130
|
+
* Don't try to sanitize non-existent elements [#174][]
|
131
|
+
* Fix Rspec deprecations [#188][]
|
132
|
+
* Fix Travis [#191][]
|
117
133
|
|
118
|
-
[#174]: https://github.com/
|
119
|
-
[#182]: https://github.com/
|
120
|
-
[#188]: https://github.com/
|
121
|
-
[#191]: https://github.com/
|
134
|
+
[#174]: https://github.com/feedjira/feedjira/pull/174
|
135
|
+
[#182]: https://github.com/feedjira/feedjira/pull/182
|
136
|
+
[#188]: https://github.com/feedjira/feedjira/pull/188
|
137
|
+
[#191]: https://github.com/feedjira/feedjira/pull/191
|
122
138
|
|
123
139
|
## 0.2.1
|
124
140
|
|
125
|
-
* Use `Time.parse_safely` in `Feed.last_modified_from_header` [
|
126
|
-
* Added image to the RSS Entry Parser [
|
127
|
-
* Compatibility fixes for Ruby 2.0 [
|
128
|
-
* Remove gorillib dependency [
|
141
|
+
* Use `Time.parse_safely` in `Feed.last_modified_from_header` [#129][]
|
142
|
+
* Added image to the RSS Entry Parser [#103][]
|
143
|
+
* Compatibility fixes for Ruby 2.0 [#136][]
|
144
|
+
* Remove gorillib dependency [#113][]
|
129
145
|
|
130
|
-
[#103]: https://github.com/
|
131
|
-
[#113]: https://github.com/
|
132
|
-
[#129]: https://github.com/
|
133
|
-
[#136]: https://github.com/
|
146
|
+
[#103]: https://github.com/feedjira/feedjira/pull/103
|
147
|
+
[#113]: https://github.com/feedjira/feedjira/pull/113
|
148
|
+
[#129]: https://github.com/feedjira/feedjira/pull/129
|
149
|
+
[#136]: https://github.com/feedjira/feedjira/pull/136
|
134
150
|
|
135
151
|
## 0.2.0.rc2
|
136
152
|
|
137
|
-
* Bump sax-machine to `v0.2.0.rc1`, fixes encoding issues [
|
153
|
+
* Bump sax-machine to `v0.2.0.rc1`, fixes encoding issues [#76][]
|
138
154
|
|
139
|
-
[#76]: https://github.com/
|
155
|
+
[#76]: https://github.com/feedjira/feedjira/issues/76
|
140
156
|
|
141
157
|
## 0.2.0.rc1
|
142
158
|
|
@@ -147,7 +163,7 @@
|
|
147
163
|
* Add Travis-CI integration
|
148
164
|
* General repository and gem maintenance
|
149
165
|
|
150
|
-
[3008ceb]: https://github.com/
|
166
|
+
[3008ceb]: https://github.com/feedjira/feedjira/commit/3008ceb338df1f4c37a211d0aab8a6ad4f584dbc
|
151
167
|
|
152
168
|
## 0.1.3
|
153
169
|
|
data/Gemfile
CHANGED
@@ -2,13 +2,10 @@ source 'https://rubygems.org/'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
gem 'rake'
|
7
|
-
end
|
5
|
+
gem 'pry'
|
8
6
|
|
9
|
-
group :
|
10
|
-
gem '
|
11
|
-
gem 'simplecov', :require => false, :platforms => :mri_19
|
7
|
+
group :test do
|
8
|
+
gem 'rake'
|
12
9
|
end
|
13
10
|
|
14
11
|
platforms :rbx do
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2009-2014:
|
4
|
+
|
5
|
+
- Paul Dix
|
6
|
+
- Julien Kirch
|
7
|
+
- Ezekiel Templin
|
8
|
+
- Jon Allured
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
12
|
+
in the Software without restriction, including without limitation the rights
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
15
|
+
furnished to do so, subject to the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,242 +1,14 @@
|
|
1
1
|
# Feedjira [![Build Status][travis-badge]][travis] [![Code Climate][code-climate-badge]][code-climate]
|
2
2
|
|
3
|
-
[travis-badge]: https://
|
3
|
+
[travis-badge]: https://travis-ci.org/feedjira/feedjira.png
|
4
4
|
[travis]: http://travis-ci.org/feedjira/feedjira
|
5
5
|
[code-climate-badge]: https://codeclimate.com/github/feedjira/feedjira.png
|
6
6
|
[code-climate]: https://codeclimate.com/github/feedjira/feedjira
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
Feedjira (formerly Feedzilla) is a Ruby library designed to fetch and parse
|
9
|
+
feeds as quickly as possible. Version 1.0 was recently released and with it an
|
10
|
+
[awesome new website][f].
|
10
11
|
|
11
|
-
[
|
12
|
+
[f]: http://feedjira.com
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
Feedjira is a feed library that is designed to get and update many feeds as
|
16
|
-
quickly as possible. This includes using libcurl-multi through the [curb][] gem
|
17
|
-
for faster http gets, and libxml through [nokogiri][] and [sax-machine][] for
|
18
|
-
faster parsing. Feedjira requires at least Ruby 1.9.2.
|
19
|
-
|
20
|
-
[curb]: https://github.com/taf2/curb
|
21
|
-
[nokogiri]: https://github.com/sparklemotion/nokogiri
|
22
|
-
[sax-machine]: https://github.com/pauldix/sax-machine
|
23
|
-
|
24
|
-
Once you have fetched feeds using Feedjira, they can be updated using the feed
|
25
|
-
objects. Feedjira automatically inserts etag and last-modified information from
|
26
|
-
the http response headers to lower bandwidth usage, eliminate unnecessary
|
27
|
-
parsing, and make things speedier in general.
|
28
|
-
|
29
|
-
Another feature present in Feedjira is the ability to create callback functions
|
30
|
-
that get called "on success" and "on failure" when getting a feed. This makes it
|
31
|
-
easy to do things like log errors or update data stores.
|
32
|
-
|
33
|
-
The fetching and parsing logic have been decoupled so that either of them can be
|
34
|
-
used in isolation if you'd prefer not to use everything that Feedjira offers.
|
35
|
-
However, the code examples below use helper methods in the Feed class that put
|
36
|
-
everything together to make things as simple as possible.
|
37
|
-
|
38
|
-
The final feature of Feedjira is the ability to define custom parsing classes.
|
39
|
-
In truth, Feedjira could be used to parse much more than feeds. Microformats,
|
40
|
-
page scraping, and almost anything else are fair game.
|
41
|
-
|
42
|
-
## Speedup date parsing
|
43
|
-
|
44
|
-
In MRI before 1.9.3 the date parsing code was written in Ruby and was optimized
|
45
|
-
for readability over speed, to speed up this part you can install the
|
46
|
-
[home_run][] gem to replace it with an optimized C version. In most cases, if
|
47
|
-
you are using Ruby 1.9.3+, you will not need to use home\_run.
|
48
|
-
|
49
|
-
[home_run]: https://github.com/jeremyevans/home_run
|
50
|
-
|
51
|
-
## Usage
|
52
|
-
|
53
|
-
[A gist of the following code](http://gist.github.com/57285)
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
require 'feedjira'
|
57
|
-
|
58
|
-
# fetching a single feed
|
59
|
-
feed = Feedjira::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing")
|
60
|
-
|
61
|
-
# feed and entries accessors
|
62
|
-
feed.title # => "Paul Dix Explains Nothing"
|
63
|
-
feed.url # => "http://www.pauldix.net"
|
64
|
-
feed.feed_url # => "http://feeds.feedburner.com/PaulDixExplainsNothing"
|
65
|
-
feed.etag # => "GunxqnEP4NeYhrqq9TyVKTuDnh0"
|
66
|
-
feed.last_modified # => Sat Jan 31 17:58:16 -0500 2009 # it's a Time object
|
67
|
-
|
68
|
-
entry = feed.entries.first
|
69
|
-
entry.title # => "Ruby Http Client Library Performance"
|
70
|
-
entry.url # => "http://www.pauldix.net/2009/01/ruby-http-client-library-performance.html"
|
71
|
-
entry.author # => "Paul Dix"
|
72
|
-
entry.summary # => "..."
|
73
|
-
entry.content # => "..."
|
74
|
-
entry.published # => Thu Jan 29 17:00:19 UTC 2009 # it's a Time object
|
75
|
-
entry.categories # => ["...", "..."]
|
76
|
-
|
77
|
-
# sanitizing an entry's content
|
78
|
-
entry.title.sanitize # => returns the title with harmful stuff escaped
|
79
|
-
entry.author.sanitize # => returns the author with harmful stuff escaped
|
80
|
-
entry.content.sanitize # => returns the content with harmful stuff escaped
|
81
|
-
entry.content.sanitize! # => returns content with harmful stuff escaped and replaces original (also exists for author and title)
|
82
|
-
entry.sanitize! # => sanitizes the entry's title, author, and content in place (as in, it changes the value to clean versions)
|
83
|
-
feed.sanitize_entries! # => sanitizes all entries in place
|
84
|
-
|
85
|
-
# updating a single feed
|
86
|
-
updated_feed = Feedjira::Feed.update(feed)
|
87
|
-
|
88
|
-
# an updated feed has the following extra accessors
|
89
|
-
updated_feed.updated? # returns true if any of the feed attributes have been modified. will return false if no new entries
|
90
|
-
updated_feed.new_entries # a collection of the entry objects that are newer than the latest in the feed before update
|
91
|
-
|
92
|
-
# fetching multiple feeds
|
93
|
-
feed_urls = ["http://feeds.feedburner.com/PaulDixExplainsNothing", "http://feeds.feedburner.com/trottercashion"]
|
94
|
-
feeds = Feedjira::Feed.fetch_and_parse(feed_urls)
|
95
|
-
|
96
|
-
# feeds is now a hash with the feed_urls as keys and the parsed feed objects as values. If an error was thrown
|
97
|
-
# there will be a Fixnum of the http response code instead of a feed object
|
98
|
-
|
99
|
-
# updating multiple feeds. it expects a collection of feed objects
|
100
|
-
updated_feeds = Feedjira::Feed.update(feeds.values)
|
101
|
-
|
102
|
-
# defining custom behavior on failure or success. note that a return status of 304 (not updated) will call the on_success handler
|
103
|
-
feed = Feedjira::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing",
|
104
|
-
:on_success => lambda {|url, feed| puts feed.title },
|
105
|
-
:on_failure => lambda {|curl, error| puts error })
|
106
|
-
|
107
|
-
# if a collection was passed into fetch_and_parse, the handlers will be called for each one
|
108
|
-
|
109
|
-
# the behavior for the handlers when using Feedjira::Feed.update is slightly different. The feed passed into on_success will be
|
110
|
-
# the updated feed with the standard updated accessors. on failure it will be the original feed object passed into update
|
111
|
-
|
112
|
-
# fetching a feed via a proxy (optional)
|
113
|
-
feed = Feedjira::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing", {:proxy_url => '10.0.0.1', :proxy_port => 3084})
|
114
|
-
```
|
115
|
-
|
116
|
-
## Extending
|
117
|
-
|
118
|
-
### Adding a feed parsing class
|
119
|
-
|
120
|
-
When determining which parser to use for a given XML document, the following
|
121
|
-
list of parser classes is used:
|
122
|
-
|
123
|
-
* `Feedjira::Parser::RSSFeedBurner`
|
124
|
-
* `Feedjira::Parser::GoogleDocsAtom`
|
125
|
-
* `Feedjira::Parser::AtomFeedBurner`
|
126
|
-
* `Feedjira::Parser::Atom`
|
127
|
-
* `Feedjira::Parser::ITunesRSS`
|
128
|
-
* `Feedjira::Parser::RSS`
|
129
|
-
|
130
|
-
You can insert your own parser at the front of this stack by calling
|
131
|
-
`add_feed_class`, like this:
|
132
|
-
|
133
|
-
```ruby
|
134
|
-
Feedjira::Feed.add_feed_class MyAwesomeParser
|
135
|
-
```
|
136
|
-
|
137
|
-
Now when you `fetch_and_parse`, `MyAwesomeParser` will be the first one to get a
|
138
|
-
chance to parse the feed.
|
139
|
-
|
140
|
-
If you have the XML and just want to provide a parser class for one parse, you
|
141
|
-
can specify that using `parse_with`:
|
142
|
-
|
143
|
-
```ruby
|
144
|
-
Feedjira::Feed.parse_with MyAwesomeParser, xml
|
145
|
-
```
|
146
|
-
|
147
|
-
### Adding attributes to all feeds types / all entries types
|
148
|
-
|
149
|
-
```ruby
|
150
|
-
# Add the generator attribute to all feed types
|
151
|
-
Feedjira::Feed.add_common_feed_element('generator')
|
152
|
-
Feedjira::Feed.fetch_and_parse("href="http://www.pauldix.net/atom.xml").generator # => 'TypePad'
|
153
|
-
|
154
|
-
# Add some GeoRss information
|
155
|
-
Feedjira::Feed.add_common_feed_entry_element('geo:lat', :as => :lat)
|
156
|
-
Feedjira::Feed.fetch_and_parse("http://www.earthpublisher.com/georss.php").entries.each do |e|
|
157
|
-
p "lat: #[e.lat}, long: #{e.long]"
|
158
|
-
end
|
159
|
-
```
|
160
|
-
|
161
|
-
### Adding attributes to only one class
|
162
|
-
|
163
|
-
If you want to add attributes for only one class you simply have to declare them
|
164
|
-
in the class
|
165
|
-
|
166
|
-
```ruby
|
167
|
-
# Add some GeoRss information
|
168
|
-
require 'lib/feedjira/parser/rss_entry'
|
169
|
-
|
170
|
-
class Feedjira::Parser::RSSEntry
|
171
|
-
element 'geo:lat', :as => :lat
|
172
|
-
element 'geo:long', :as => :long
|
173
|
-
end
|
174
|
-
|
175
|
-
# Fetch a feed containing GeoRss info and print them
|
176
|
-
Feedjira::Feed.fetch_and_parse("http://www.earthpublisher.com/georss.php").entries.each do |e|
|
177
|
-
p "lat: #{e.lat}, long: #{e.long}"
|
178
|
-
end
|
179
|
-
```
|
180
|
-
|
181
|
-
## Testing
|
182
|
-
|
183
|
-
Feedjira uses [curb][] to perform requests. `curb` provides bindings for
|
184
|
-
[libcurl][] and supports numerous protocols, including FILE. To test Feedjira
|
185
|
-
with local file use `file://` protocol:
|
186
|
-
|
187
|
-
[libcurl]: http://curl.haxx.se/libcurl/
|
188
|
-
|
189
|
-
```ruby
|
190
|
-
feed = Feedjira::Feed.fetch_and_parse('file:///home/feedjira/examples/feed.rss')
|
191
|
-
```
|
192
|
-
|
193
|
-
## Benchmarks
|
194
|
-
|
195
|
-
Since a major goal of Feedjira is speed, benchmarks are provided--see the
|
196
|
-
[Benchmark README][benchmark_readme] for more details.
|
197
|
-
|
198
|
-
[benchmark_readme]: https://github.com/feedjira/feedjira/blob/master/benchmarks/README.md
|
199
|
-
|
200
|
-
## TODO
|
201
|
-
|
202
|
-
This thing needs to hammer on many different feeds in the wild. I'm sure there
|
203
|
-
will be bugs. I want to find them and crush them. I didn't bother using the test
|
204
|
-
suite for feedparser. i wanted to start fresh.
|
205
|
-
|
206
|
-
Here are some more specific TODOs.
|
207
|
-
|
208
|
-
* Make a feedjira-rails gem to integrate feedjira seamlessly with Rails and ActiveRecord.
|
209
|
-
* Add support for authenticated feeds.
|
210
|
-
* Create a super sweet DSL for defining new parsers.
|
211
|
-
* I'm not keeping track of modified on entries. Should I add this?
|
212
|
-
* Clean up the fetching code inside feed.rb so it doesn't suck so hard.
|
213
|
-
* Make the feed_spec actually mock stuff out so it doesn't hit the net.
|
214
|
-
* Readdress how feeds determine if they can parse a document. Maybe I should use namespaces instead?
|
215
|
-
|
216
|
-
## LICENSE
|
217
|
-
|
218
|
-
(The MIT License)
|
219
|
-
|
220
|
-
Copyright (c) 2009-2013:
|
221
|
-
|
222
|
-
- [Paul Dix](http://pauldix.net)
|
223
|
-
- [Julien Kirch](http://archiloque.net/)
|
224
|
-
- [Ezekiel Templin](http://zeke.templ.in/)
|
225
|
-
- [Jon Allured](http://jonallured.com/)
|
226
|
-
|
227
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
228
|
-
this software and associated documentation files (the 'Software'), to deal in
|
229
|
-
the Software without restriction, including without limitation the rights to
|
230
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
231
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
232
|
-
subject to the following conditions:
|
233
|
-
|
234
|
-
The above copyright notice and this permission notice shall be included in all
|
235
|
-
copies or substantial portions of the Software.
|
236
|
-
|
237
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
238
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
239
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
240
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
241
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
242
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
There you'll find documentation, examples, announcements and more.
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require "bundler/gem_tasks"
|
3
1
|
require 'rspec/core/rake_task'
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
|
3
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
4
|
+
t.verbose = false
|
5
|
+
end
|
6
|
+
|
7
|
+
task default: :spec
|
data/lib/feedjira/feed.rb
CHANGED
@@ -136,6 +136,7 @@ module Feedjira
|
|
136
136
|
# Setup curl from options.
|
137
137
|
# Possible parameters:
|
138
138
|
# * :user_agent - overrides the default user agent.
|
139
|
+
# * :language - accept language value.
|
139
140
|
# * :compress - any value to enable compression
|
140
141
|
# * :enable_cookies - boolean
|
141
142
|
# * :cookiefile - file to read cookies
|
@@ -151,6 +152,7 @@ module Feedjira
|
|
151
152
|
def self.setup_easy(curl, options={})
|
152
153
|
curl.headers["Accept-encoding"] = 'gzip, deflate' if options.has_key?(:compress)
|
153
154
|
curl.headers["User-Agent"] = (options[:user_agent] || USER_AGENT)
|
155
|
+
curl.headers["Accept-Language"] = options[:language] if options.has_key?(:language)
|
154
156
|
curl.enable_cookies = options[:enable_cookies] if options.has_key?(:enable_cookies)
|
155
157
|
curl.cookiefile = options[:cookiefile] if options.has_key?(:cookiefile)
|
156
158
|
curl.cookies = options[:cookies] if options.has_key?(:cookies)
|
data/lib/feedjira/parser.rb
CHANGED
@@ -1,20 +1 @@
|
|
1
|
-
module Feedjira
|
2
|
-
module Parser
|
3
|
-
autoload :RSS, 'feedjira/parser/rss'
|
4
|
-
autoload :RSSEntry, 'feedjira/parser/rss_entry'
|
5
|
-
autoload :RSSFeedBurner, 'feedjira/parser/rss_feed_burner'
|
6
|
-
autoload :RSSFeedBurnerEntry, 'feedjira/parser/rss_feed_burner_entry'
|
7
|
-
|
8
|
-
autoload :ITunesRSS, 'feedjira/parser/itunes_rss'
|
9
|
-
autoload :ITunesRSSItem, 'feedjira/parser/itunes_rss_item'
|
10
|
-
autoload :ITunesRSSOwner, 'feedjira/parser/itunes_rss_owner'
|
11
|
-
|
12
|
-
autoload :GoogleDocsAtom, 'feedjira/parser/google_docs_atom'
|
13
|
-
autoload :GoogleDocsAtomEntry, 'feedjira/parser/google_docs_atom_entry'
|
14
|
-
|
15
|
-
autoload :Atom, 'feedjira/parser/atom'
|
16
|
-
autoload :AtomEntry, 'feedjira/parser/atom_entry'
|
17
|
-
autoload :AtomFeedBurner, 'feedjira/parser/atom_feed_burner'
|
18
|
-
autoload :AtomFeedBurnerEntry, 'feedjira/parser/atom_feed_burner_entry'
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module Feedjira::Parser; end
|
data/lib/feedjira/version.rb
CHANGED
data/lib/feedjira.rb
CHANGED
@@ -4,13 +4,26 @@ require 'sax-machine'
|
|
4
4
|
require 'loofah'
|
5
5
|
|
6
6
|
require 'feedjira/core_ext'
|
7
|
+
require 'feedjira/feed_entry_utilities'
|
8
|
+
require 'feedjira/feed_utilities'
|
9
|
+
require 'feedjira/feed'
|
10
|
+
require 'feedjira/parser'
|
11
|
+
require 'feedjira/parser/rss_entry'
|
12
|
+
require 'feedjira/parser/rss'
|
13
|
+
require 'feedjira/parser/atom_entry'
|
14
|
+
require 'feedjira/parser/atom'
|
7
15
|
require 'feedjira/version'
|
8
16
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
require 'feedjira/parser/rss_feed_burner_entry'
|
18
|
+
require 'feedjira/parser/rss_feed_burner'
|
19
|
+
require 'feedjira/parser/itunes_rss_owner'
|
20
|
+
require 'feedjira/parser/itunes_rss_item'
|
21
|
+
require 'feedjira/parser/itunes_rss'
|
22
|
+
require 'feedjira/parser/atom_feed_burner_entry'
|
23
|
+
require 'feedjira/parser/atom_feed_burner'
|
24
|
+
require 'feedjira/parser/google_docs_atom_entry'
|
25
|
+
require 'feedjira/parser/google_docs_atom'
|
14
26
|
|
27
|
+
module Feedjira
|
15
28
|
class NoParserAvailable < StandardError; end
|
16
29
|
end
|
data/spec/feedjira/feed_spec.rb
CHANGED
@@ -174,6 +174,11 @@ describe Feedjira::Feed do
|
|
174
174
|
curl.headers["User-Agent"].should eq '007'
|
175
175
|
end
|
176
176
|
|
177
|
+
it "allows to set language" do
|
178
|
+
Feedjira::Feed.setup_easy(curl, language: 'en-US')
|
179
|
+
curl.headers["Accept-Language"].should eq 'en-US'
|
180
|
+
end
|
181
|
+
|
177
182
|
it "enables compression" do
|
178
183
|
Feedjira::Feed.setup_easy(curl, compress: true)
|
179
184
|
curl.headers["Accept-encoding"].should eq 'gzip, deflate'
|
@@ -755,7 +760,7 @@ describe Feedjira::Feed do
|
|
755
760
|
Feedjira::Feed.should_receive(:add_feed_to_multi).
|
756
761
|
with(anything, anything, anything, anything, options)
|
757
762
|
|
758
|
-
Feedjira::Feed.update(
|
763
|
+
Feedjira::Feed.update([nil], options)
|
759
764
|
end
|
760
765
|
end
|
761
766
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SampleFeeds
|
2
|
+
FEEDS = {
|
3
|
+
sample_atom_feed: "AmazonWebServicesBlog.xml",
|
4
|
+
sample_atom_xhtml_feed: "pet_atom.xml",
|
5
|
+
sample_atom_feed_line_breaks: "AtomFeedWithSpacesAroundEquals.xml",
|
6
|
+
sample_atom_entry_content: "AmazonWebServicesBlogFirstEntryContent.xml",
|
7
|
+
sample_itunes_feed: "itunes.xml",
|
8
|
+
sample_itunes_feed_with_spaces: "ITunesWithSpacesInAttributes.xml",
|
9
|
+
sample_rdf_feed: "HREFConsideredHarmful.xml",
|
10
|
+
sample_rdf_entry_content: "HREFConsideredHarmfulFirstEntry.xml",
|
11
|
+
sample_rss_feed_burner_feed: "TechCrunch.xml",
|
12
|
+
sample_rss_feed_burner_entry_content: "TechCrunchFirstEntry.xml",
|
13
|
+
sample_rss_feed_burner_entry_description: "TechCrunchFirstEntryDescription.xml",
|
14
|
+
sample_rss_feed: "TenderLovemaking.xml",
|
15
|
+
sample_rss_entry_content: "TenderLovemakingFirstEntry.xml",
|
16
|
+
sample_feedburner_atom_feed: "PaulDixExplainsNothing.xml",
|
17
|
+
sample_feedburner_atom_entry_content: "PaulDixExplainsNothingFirstEntryContent.xml",
|
18
|
+
sample_wfw_feed: "PaulDixExplainsNothingWFW.xml",
|
19
|
+
sample_google_docs_list_feed: "GoogleDocsList.xml"
|
20
|
+
}
|
21
|
+
|
22
|
+
FEEDS.each do |method, filename|
|
23
|
+
define_method(method) { load_sample filename }
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_sample(filename)
|
27
|
+
File.read("#{File.dirname(__FILE__)}/sample_feeds/#{filename}")
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,88 +1,6 @@
|
|
1
|
-
begin
|
2
|
-
require 'simplecov'
|
3
|
-
require 'json'
|
4
|
-
SimpleCov.start do
|
5
|
-
add_filter "/spec/"
|
6
|
-
end
|
7
|
-
rescue LoadError
|
8
|
-
end
|
9
|
-
|
10
1
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/feedjira')
|
2
|
+
require 'sample_feeds'
|
11
3
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def sample_atom_feed
|
17
|
-
load_sample("AmazonWebServicesBlog.xml")
|
18
|
-
end
|
19
|
-
|
20
|
-
def sample_atom_xhtml_feed
|
21
|
-
load_sample("pet_atom.xml")
|
22
|
-
end
|
23
|
-
|
24
|
-
def sample_atom_feed_line_breaks
|
25
|
-
load_sample("AtomFeedWithSpacesAroundEquals.xml")
|
26
|
-
end
|
27
|
-
|
28
|
-
def sample_atom_entry_content
|
29
|
-
load_sample("AmazonWebServicesBlogFirstEntryContent.xml")
|
30
|
-
end
|
31
|
-
|
32
|
-
def sample_itunes_feed
|
33
|
-
load_sample("itunes.xml")
|
34
|
-
end
|
35
|
-
|
36
|
-
def sample_itunes_feed_with_spaces
|
37
|
-
load_sample("ITunesWithSpacesInAttributes.xml")
|
38
|
-
end
|
39
|
-
|
40
|
-
def sample_rdf_feed
|
41
|
-
load_sample("HREFConsideredHarmful.xml")
|
42
|
-
end
|
43
|
-
|
44
|
-
def sample_rdf_entry_content
|
45
|
-
load_sample("HREFConsideredHarmfulFirstEntry.xml")
|
46
|
-
end
|
47
|
-
|
48
|
-
def sample_rss_feed_burner_feed
|
49
|
-
load_sample("TechCrunch.xml")
|
50
|
-
end
|
51
|
-
|
52
|
-
def sample_rss_feed_burner_entry_content
|
53
|
-
load_sample("TechCrunchFirstEntry.xml")
|
54
|
-
end
|
55
|
-
|
56
|
-
def sample_rss_feed_burner_entry_description
|
57
|
-
load_sample("TechCrunchFirstEntryDescription.xml")
|
58
|
-
end
|
59
|
-
|
60
|
-
def sample_rss_feed
|
61
|
-
load_sample("TenderLovemaking.xml")
|
62
|
-
end
|
63
|
-
|
64
|
-
def sample_rss_entry_content
|
65
|
-
load_sample("TenderLovemakingFirstEntry.xml")
|
66
|
-
end
|
67
|
-
|
68
|
-
def sample_feedburner_atom_feed
|
69
|
-
load_sample("PaulDixExplainsNothing.xml")
|
70
|
-
end
|
71
|
-
|
72
|
-
def sample_feedburner_atom_entry_content
|
73
|
-
load_sample("PaulDixExplainsNothingFirstEntryContent.xml")
|
74
|
-
end
|
75
|
-
|
76
|
-
def sample_wfw_feed
|
77
|
-
load_sample("PaulDixExplainsNothingWFW.xml")
|
78
|
-
end
|
79
|
-
|
80
|
-
def sample_google_docs_list_feed
|
81
|
-
load_sample("GoogleDocsList.xml")
|
82
|
-
end
|
83
|
-
|
84
|
-
RSpec.configure do |config|
|
85
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
86
|
-
config.run_all_when_everything_filtered = true
|
87
|
-
config.filter_run :focus
|
4
|
+
RSpec.configure do |c|
|
5
|
+
c.include SampleFeeds
|
88
6
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feedjira
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Dix
|
@@ -11,62 +11,62 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-03-
|
14
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: sax-machine
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- - ~>
|
20
|
+
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.2.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.2.1
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: curb
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- - ~>
|
34
|
+
- - "~>"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 0.8.1
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 0.8.1
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: loofah
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- - ~>
|
48
|
+
- - "~>"
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: 1.2.1
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- - ~>
|
55
|
+
- - "~>"
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: 1.2.1
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
|
-
- - ~>
|
62
|
+
- - "~>"
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: 2.14.0
|
65
65
|
type: :development
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- - ~>
|
69
|
+
- - "~>"
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: 2.14.0
|
72
72
|
description: A library designed to retrieve and parse feeds as quickly as possible
|
@@ -75,12 +75,12 @@ executables: []
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
- .gitignore
|
79
|
-
- .rspec
|
80
|
-
- .travis.yml
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
81
|
- CHANGELOG.md
|
82
82
|
- Gemfile
|
83
|
-
-
|
83
|
+
- LICENSE
|
84
84
|
- README.md
|
85
85
|
- Rakefile
|
86
86
|
- benchmarks/README.md
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- spec/feedjira/parser/rss_feed_burner_entry_spec.rb
|
139
139
|
- spec/feedjira/parser/rss_feed_burner_spec.rb
|
140
140
|
- spec/feedjira/parser/rss_spec.rb
|
141
|
+
- spec/sample_feeds.rb
|
141
142
|
- spec/sample_feeds/AmazonWebServicesBlog.xml
|
142
143
|
- spec/sample_feeds/AmazonWebServicesBlogFirstEntryContent.xml
|
143
144
|
- spec/sample_feeds/AtomFeedWithSpacesAroundEquals.xml
|
@@ -172,17 +173,17 @@ require_paths:
|
|
172
173
|
- lib
|
173
174
|
required_ruby_version: !ruby/object:Gem::Requirement
|
174
175
|
requirements:
|
175
|
-
- -
|
176
|
+
- - ">="
|
176
177
|
- !ruby/object:Gem::Version
|
177
178
|
version: '0'
|
178
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
180
|
requirements:
|
180
|
-
- -
|
181
|
+
- - ">="
|
181
182
|
- !ruby/object:Gem::Version
|
182
183
|
version: '0'
|
183
184
|
requirements: []
|
184
185
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.1
|
186
|
+
rubygems_version: 2.2.1
|
186
187
|
signing_key:
|
187
188
|
specification_version: 4
|
188
189
|
summary: A feed fetching and parsing library
|
@@ -203,6 +204,7 @@ test_files:
|
|
203
204
|
- spec/feedjira/parser/rss_feed_burner_entry_spec.rb
|
204
205
|
- spec/feedjira/parser/rss_feed_burner_spec.rb
|
205
206
|
- spec/feedjira/parser/rss_spec.rb
|
207
|
+
- spec/sample_feeds.rb
|
206
208
|
- spec/sample_feeds/AmazonWebServicesBlog.xml
|
207
209
|
- spec/sample_feeds/AmazonWebServicesBlogFirstEntryContent.xml
|
208
210
|
- spec/sample_feeds/AtomFeedWithSpacesAroundEquals.xml
|