feedjira 2.0.0 → 2.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 +1 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +31 -12
- data/CHANGELOG.md +15 -1
- data/Dangerfile +1 -0
- data/Gemfile +2 -1
- data/Rakefile +6 -1
- data/feedjira.gemspec +16 -14
- data/fixtures/vcr_cassettes/fetch_failure.yml +62 -0
- data/fixtures/vcr_cassettes/parse_error.yml +222 -0
- data/fixtures/vcr_cassettes/success.yml +281 -0
- data/lib/feedjira.rb +9 -0
- data/lib/feedjira/core_ext.rb +3 -3
- data/lib/feedjira/core_ext/date.rb +2 -1
- data/lib/feedjira/core_ext/string.rb +1 -1
- data/lib/feedjira/core_ext/time.rb +19 -16
- data/lib/feedjira/date_time_utilities.rb +24 -0
- data/lib/feedjira/date_time_utilities/date_time_language_parser.rb +22 -0
- data/lib/feedjira/date_time_utilities/date_time_pattern_parser.rb +29 -0
- data/lib/feedjira/feed.rb +27 -18
- data/lib/feedjira/feed_entry_utilities.rb +15 -17
- data/lib/feedjira/feed_utilities.rb +26 -21
- data/lib/feedjira/parser/atom.rb +9 -8
- data/lib/feedjira/parser/atom_entry.rb +10 -13
- data/lib/feedjira/parser/atom_feed_burner.rb +8 -10
- data/lib/feedjira/parser/atom_feed_burner_entry.rb +11 -14
- data/lib/feedjira/parser/atom_youtube.rb +20 -0
- data/lib/feedjira/parser/atom_youtube_entry.rb +29 -0
- data/lib/feedjira/parser/google_docs_atom.rb +6 -6
- data/lib/feedjira/parser/google_docs_atom_entry.rb +11 -11
- data/lib/feedjira/parser/itunes_rss.rb +39 -22
- data/lib/feedjira/parser/itunes_rss_category.rb +38 -0
- data/lib/feedjira/parser/itunes_rss_item.rb +28 -20
- data/lib/feedjira/parser/itunes_rss_owner.rb +3 -4
- data/lib/feedjira/parser/podlove_chapter.rb +20 -0
- data/lib/feedjira/parser/rss.rb +10 -8
- data/lib/feedjira/parser/rss_entry.rb +17 -21
- data/lib/feedjira/parser/rss_feed_burner.rb +4 -6
- data/lib/feedjira/parser/rss_feed_burner_entry.rb +23 -28
- data/lib/feedjira/parser/rss_image.rb +15 -0
- data/lib/feedjira/preprocessor.rb +2 -2
- data/lib/feedjira/version.rb +1 -1
- data/spec/feedjira/date_time_utilities_spec.rb +41 -0
- data/spec/feedjira/feed_entry_utilities_spec.rb +23 -19
- data/spec/feedjira/feed_spec.rb +109 -74
- data/spec/feedjira/feed_utilities_spec.rb +65 -63
- data/spec/feedjira/parser/atom_entry_spec.rb +54 -34
- data/spec/feedjira/parser/atom_feed_burner_entry_spec.rb +27 -20
- data/spec/feedjira/parser/atom_feed_burner_spec.rb +32 -30
- data/spec/feedjira/parser/atom_spec.rb +50 -48
- data/spec/feedjira/parser/atom_youtube_entry_spec.rb +86 -0
- data/spec/feedjira/parser/atom_youtube_spec.rb +43 -0
- data/spec/feedjira/parser/google_docs_atom_entry_spec.rb +5 -4
- data/spec/feedjira/parser/google_docs_atom_spec.rb +6 -6
- data/spec/feedjira/parser/itunes_rss_item_spec.rb +33 -29
- data/spec/feedjira/parser/itunes_rss_owner_spec.rb +10 -9
- data/spec/feedjira/parser/itunes_rss_spec.rb +83 -30
- data/spec/feedjira/parser/podlove_chapter_spec.rb +37 -0
- data/spec/feedjira/parser/rss_entry_spec.rb +50 -33
- data/spec/feedjira/parser/rss_feed_burner_entry_spec.rb +55 -33
- data/spec/feedjira/parser/rss_feed_burner_spec.rb +31 -26
- data/spec/feedjira/parser/rss_spec.rb +56 -24
- data/spec/feedjira/preprocessor_spec.rb +11 -3
- data/spec/sample_feeds.rb +29 -21
- data/spec/sample_feeds/AmazonWebServicesBlog.xml +797 -797
- data/spec/sample_feeds/AtomEscapedHTMLInPreTag.xml +13 -0
- data/spec/sample_feeds/CRE.xml +5849 -0
- data/spec/sample_feeds/FeedBurnerXHTML.xml +400 -400
- data/spec/sample_feeds/ITunesWithSingleQuotedAttributes.xml +67 -0
- data/spec/sample_feeds/PaulDixExplainsNothing.xml +175 -175
- data/spec/sample_feeds/PaulDixExplainsNothingAlternate.xml +175 -175
- data/spec/sample_feeds/PaulDixExplainsNothingFirstEntryContent.xml +16 -16
- data/spec/sample_feeds/PaulDixExplainsNothingWFW.xml +174 -174
- data/spec/sample_feeds/TenderLovemaking.xml +12 -2
- data/spec/sample_feeds/TrotterCashionHome.xml +611 -611
- data/spec/sample_feeds/TypePadNews.xml +368 -368
- data/spec/sample_feeds/itunes.xml +18 -2
- data/spec/sample_feeds/pet_atom.xml +229 -229
- data/spec/sample_feeds/youtube_atom.xml +395 -0
- data/spec/spec_helper.rb +6 -0
- metadata +112 -27
@@ -0,0 +1,281 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://feedjira.com/blog/feed.xml
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.2
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message:
|
16
|
+
headers:
|
17
|
+
date:
|
18
|
+
- Mon, 31 Oct 2016 02:29:13 GMT
|
19
|
+
server:
|
20
|
+
- Apache/2.4.18 (Ubuntu)
|
21
|
+
last-modified:
|
22
|
+
- Fri, 07 Oct 2016 14:37:00 GMT
|
23
|
+
etag:
|
24
|
+
- '"393e-53e4757c9db00-gzip"'
|
25
|
+
accept-ranges:
|
26
|
+
- bytes
|
27
|
+
vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
content-length:
|
30
|
+
- '5051'
|
31
|
+
connection:
|
32
|
+
- close
|
33
|
+
content-type:
|
34
|
+
- application/xml
|
35
|
+
body:
|
36
|
+
encoding: ASCII-8BIT
|
37
|
+
string: |
|
38
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
39
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
40
|
+
<title>Feedjira Blog</title>
|
41
|
+
<subtitle>A Blog for Feedjira</subtitle>
|
42
|
+
<id>http://feedjira.com/blog</id>
|
43
|
+
<link href="http://feedjira.com/blog"/>
|
44
|
+
<link href="http://feedjira.com/blog/feed.xml" rel="self"/>
|
45
|
+
<updated>2015-06-05T00:00:00Z</updated>
|
46
|
+
<author>
|
47
|
+
<name>Jon Allured</name>
|
48
|
+
</author>
|
49
|
+
<entry>
|
50
|
+
<title>Feedjira Two-Point-Oh</title>
|
51
|
+
<link rel="alternate" href="http://feedjira.com/blog/2015/06/05/feedjira-two-point-oh.html"/>
|
52
|
+
<id>http://feedjira.com/blog/2015/06/05/feedjira-two-point-oh.html</id>
|
53
|
+
<published>2015-06-05T00:00:00Z</published>
|
54
|
+
<updated>2015-04-17T16:16:07-05:00</updated>
|
55
|
+
<author>
|
56
|
+
<name>Jon Allured</name>
|
57
|
+
</author>
|
58
|
+
<content type="html"><p>About a year ago, I took Feedjira to <a href="http://feedjira.com/blog/2014/03/17/feedjira-goes-one-point-oh.html">version 1.0</a> and today I&rsquo;m releasing
|
59
|
+
version 2.0. Not much has changed actually - the biggest difference is that
|
60
|
+
<code>curb</code> has been replaced with <code>faraday</code>. For many users, upgrading to version
|
61
|
+
2.0 won&rsquo;t require anything more than a <code>bundle update feedjira</code>.</p>
|
62
|
+
|
63
|
+
<p>The other big change is that the <code>Feedjira#update</code> method was removed. It was
|
64
|
+
unreliable and mostly just caused issues. To read more about why this was
|
65
|
+
removed, check out <a href="https://github.com/feedjira/feedjira/issues/218#issuecomment-40282091">this comment</a> on a GitHub issue that was opened
|
66
|
+
about it not working as expected.</p>
|
67
|
+
|
68
|
+
<p>I&rsquo;ve also updated the site to reflect the changes in this version. I took the
|
69
|
+
opportunity to greatly simply things and got just about all the documentation to
|
70
|
+
fit on one page.</p>
|
71
|
+
|
72
|
+
<p>I hope you like version 2.0 - feel free to hit me up <a href="https://twitter.com/feedjira">on Twitter</a> or if
|
73
|
+
you have any trouble, open a <a href="https://github.com/feedjira/feedjira/issues">GitHub issue</a> and I&rsquo;ll give you a hand.</p>
|
74
|
+
|
75
|
+
<p>Finally, thanks to those that gave me feedback on either my thoughts on version
|
76
|
+
2.0 or the release candidate - I really appreciate it!</p>
|
77
|
+
</content>
|
78
|
+
</entry>
|
79
|
+
<entry>
|
80
|
+
<title>Thoughts on Version Two-Point-Oh</title>
|
81
|
+
<link rel="alternate" href="http://feedjira.com/blog/2014/04/14/thoughts-on-version-two-point-oh.html"/>
|
82
|
+
<id>http://feedjira.com/blog/2014/04/14/thoughts-on-version-two-point-oh.html</id>
|
83
|
+
<published>2014-04-14T00:00:00Z</published>
|
84
|
+
<updated>2014-09-05T12:15:28-05:00</updated>
|
85
|
+
<author>
|
86
|
+
<name>Jon Allured</name>
|
87
|
+
</author>
|
88
|
+
<content type="html"><p>TLDR: development of version 2.0 is being done on the <a href="https://github.com/feedjira/feedjira/tree/two-point-oh">two-point-oh branch</a>
|
89
|
+
and a <a href="https://github.com/feedjira/feedjira/issues/221">GitHub issue</a> is open for you to give feedback on its direction.</p>
|
90
|
+
|
91
|
+
<p>I&rsquo;ve starting work on a rewrite for Feedjira and I wanted to try using a <a href="https://github.com/feedjira/feedjira/issues/221">GitHub
|
92
|
+
issue</a> to discuss what I&rsquo;d like to see in the new version. I&rsquo;m very
|
93
|
+
interested in what users think, so please chime in!!</p>
|
94
|
+
|
95
|
+
<p>In no particular order, here are some design goals for the new version:</p>
|
96
|
+
|
97
|
+
<h2>Change HTTP Library</h2>
|
98
|
+
|
99
|
+
<p>This gem depends on <a href="https://github.com/taf2/curb">curb</a>, but I&rsquo;d like to switch that to something that will
|
100
|
+
allow me to support JRuby. I did some experimenting and really liked working
|
101
|
+
with <a href="https://github.com/lostisland/faraday">Faraday</a>, so that&rsquo;s what I&rsquo;m using at the moment.</p>
|
102
|
+
|
103
|
+
<h2>Forget Concurrency</h2>
|
104
|
+
|
105
|
+
<p>Throwing an array of feed urls at Feedjira and watching it concurrently fetch
|
106
|
+
and parse them extremely quickly is cool in READMEs and demos, but I don&rsquo;t think
|
107
|
+
it&rsquo;s reality. I think what&rsquo;s much more likely is a single url being passed and
|
108
|
+
concurrency being dealt with in the application, workers being the likely
|
109
|
+
approach.</p>
|
110
|
+
|
111
|
+
<h2>More Objects</h2>
|
112
|
+
|
113
|
+
<p>Feedjira has a dirty little secret and it&rsquo;s the <code>Feedjira::Feed</code> class. If you
|
114
|
+
open that sucker up, you&rsquo;ll see 19 class methods and 0 instance methods. These
|
115
|
+
class methods do everything from fetching and parsing to setting up curb and
|
116
|
+
unzipping raw xml. Not only is <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">SRP</a> off in the corner crying, its a mess to
|
117
|
+
test. I&rsquo;d like to break this down into smaller objects that get instantiated and
|
118
|
+
passed around in normal OO fashion.</p>
|
119
|
+
|
120
|
+
<h2>Fewer Parsers</h2>
|
121
|
+
|
122
|
+
<p>One of the things I like best about Feedjira is the ability for a user to define
|
123
|
+
their own custom parsers and I think its under-used. What I&rsquo;d like to see is
|
124
|
+
Feedjira ship with a parser for Atom and a parser for RSS - the others are
|
125
|
+
really just custom parsers.</p>
|
126
|
+
|
127
|
+
<h2>Custom Parser Project</h2>
|
128
|
+
|
129
|
+
<p>With version 1.2, I was able to spin off the benchmarks into <a href="https://github.com/feedjira/feedjira-benchmarks">their own
|
130
|
+
project</a> and I was very happy with how it turned out - I&rsquo;d like to see a
|
131
|
+
similar thing happen with the custom parsers mentioned above. You should be able
|
132
|
+
to easily grab these parsers and throw them in your application. If you write a
|
133
|
+
particularly cool custom parser, then you could contribute it back and others
|
134
|
+
could benefit from it.</p>
|
135
|
+
|
136
|
+
<h2>Raise Exceptions Instead of Callbacks</h2>
|
137
|
+
|
138
|
+
<p>Feedjira almost never raises an exception and instead provides the ability to
|
139
|
+
register callbacks for success and failure situations, but this has proven
|
140
|
+
brittle and painful. With the new version, I want to see sensible exceptions
|
141
|
+
raised when something goes wrong and that pretty much removes the need for
|
142
|
+
callbacks, so those will be cut.</p>
|
143
|
+
|
144
|
+
<h2>Feed Updating is Business Logic</h2>
|
145
|
+
|
146
|
+
<p>The updating functionality of Feedjira leaves a lot to be desired - its
|
147
|
+
inconsistent and there are lots of edges. I tend to steer users away and
|
148
|
+
encourage them to write this kind of code in their application instead. See
|
149
|
+
<a href="https://github.com/feedjira/feedjira/issues/218">this discussion</a> for more, but needless to say, I&rsquo;d like to see this entire
|
150
|
+
feature set removed.</p>
|
151
|
+
|
152
|
+
<h2>Configuration</h2>
|
153
|
+
|
154
|
+
<p>I want configuration for Feedjira done in a proper config block like most gems.
|
155
|
+
If you want to change the default parsers, that should be a config option. If
|
156
|
+
you want to set the user agent, that should be a configuration option.</p>
|
157
|
+
|
158
|
+
<h2>Feedback Appreciated</h2>
|
159
|
+
|
160
|
+
<p>Do you have any other ideas to make Feedjira better? Please check out the
|
161
|
+
<a href="https://github.com/feedjira/feedjira/issues/221">GitHub issue</a> and share what you&rsquo;re thinking. I&rsquo;m open to any feedback, so
|
162
|
+
if I just threw your favorite feature on the chopping block, please tell me!</p>
|
163
|
+
</content>
|
164
|
+
</entry>
|
165
|
+
<entry>
|
166
|
+
<title>A Separate Project For Benchmarks</title>
|
167
|
+
<link rel="alternate" href="http://feedjira.com/blog/2014/04/11/a-separate-project-for-benchmarks.html"/>
|
168
|
+
<id>http://feedjira.com/blog/2014/04/11/a-separate-project-for-benchmarks.html</id>
|
169
|
+
<published>2014-04-11T00:00:00Z</published>
|
170
|
+
<updated>2014-09-05T12:15:28-05:00</updated>
|
171
|
+
<author>
|
172
|
+
<name>Jon Allured</name>
|
173
|
+
</author>
|
174
|
+
<content type="html"><p>With the release of version 1.2.0, the benchmarks for Feedjira have been moved
|
175
|
+
to a separate project: <a href="https://github.com/feedjira/feedjira-benchmarks">https://github.com/feedjira/feedjira-benchmarks</a>.</p>
|
176
|
+
|
177
|
+
<p>What&rsquo;s nice about this is that it keeps things much more organized and allowed
|
178
|
+
me to add a pretty neat new benchmark - more on that in a moment. I also rewrote
|
179
|
+
the <a href="/benchmarks.html">Benchmarks page</a> on this site so please check that out.</p>
|
180
|
+
|
181
|
+
<p>One benchmark that I didn&rsquo;t pull over to the new project is the fetching one. I
|
182
|
+
left it out because it relied on the consistency of your network connection and
|
183
|
+
that didn&rsquo;t feel like it was scientific enough.</p>
|
184
|
+
|
185
|
+
<p>In its place I&rsquo;ve added a benchmark for parsing speed that&rsquo;s run against each
|
186
|
+
version of the gem. Its pretty cool - when you clone down the
|
187
|
+
feedjira-benchmarks project, you also clone down feedjira itself and then the
|
188
|
+
script moves to each version tag in the git repo, runs the benchmark and records
|
189
|
+
the results. It was pretty fun to write and works like a charm.</p>
|
190
|
+
|
191
|
+
<p>For the charts, I ended up learning some <a href="http://www.r-project.org/">R</a> so that I could have a little
|
192
|
+
more control.</p>
|
193
|
+
|
194
|
+
<p>Benchmarks are really only valuable if they can be reproduced by others, so I&rsquo;ve
|
195
|
+
written up instructions in the README for setting things up and running them. If
|
196
|
+
you&rsquo;re interested, take a look and try running them yourself!</p>
|
197
|
+
|
198
|
+
<p>I&rsquo;ll continue to use the benchmarks to ensure Feedjira stays fast, so you wont
|
199
|
+
have to worry about your favorite Ruby feed library slowing down. If you have
|
200
|
+
any feedback for me on the benchmarks, feel free to hit me up on Twitter
|
201
|
+
(<a href="https://twitter.com/feedjira">@feedjira</a>) or <a href="https://github.com/feedjira/feedjira-benchmarks/issues">open an issue</a> on the project&rsquo;s repo.</p>
|
202
|
+
</content>
|
203
|
+
</entry>
|
204
|
+
<entry>
|
205
|
+
<title>Feedjira Goes One-Point-Oh</title>
|
206
|
+
<link rel="alternate" href="http://feedjira.com/blog/2014/03/17/feedjira-goes-one-point-oh.html"/>
|
207
|
+
<id>http://feedjira.com/blog/2014/03/17/feedjira-goes-one-point-oh.html</id>
|
208
|
+
<published>2014-03-17T00:00:00Z</published>
|
209
|
+
<updated>2014-09-05T12:15:28-05:00</updated>
|
210
|
+
<author>
|
211
|
+
<name>Jon Allured</name>
|
212
|
+
</author>
|
213
|
+
<content type="html"><p>Last fall, I asked <a href="http://www.pauldix.net">Paul Dix</a> if I could take over maintenance of his gem
|
214
|
+
Feedzirra. My request was totally out of the blue, so I was pretty pumped when
|
215
|
+
he got right back to me and said yes. He said that he didn&rsquo;t have time to work
|
216
|
+
on it anymore and so I should feel free to do whatever I thought was best.</p>
|
217
|
+
|
218
|
+
<p>Score!</p>
|
219
|
+
|
220
|
+
<p>My first order of business was to go through the many open issues and pull
|
221
|
+
requests on GitHub. When I started there were over 60, a number that I&rsquo;ve gotten
|
222
|
+
down to just a few. I thought it was important to ensure that users saw me treat
|
223
|
+
their issue as important and even if it was very old (which many were), I asked
|
224
|
+
if there was anything I could do to help.</p>
|
225
|
+
|
226
|
+
<p>I was pleasantly surprised by the nice way many people responded and we got to
|
227
|
+
work addressing their questions and issues.</p>
|
228
|
+
|
229
|
+
<p>As I was working through issues and pull requests, I kept <a href="http://semver.org">SemVer</a> in mind -
|
230
|
+
bug fixes in patch releases and backward-compatible changes in minor releases.
|
231
|
+
But I also realized that it was past time for this project to be at version 1.0.
|
232
|
+
In the SemVer FAQ, they talk about when to release version 1.0 and Feedzirra fit
|
233
|
+
the bill: it was being used in production, there was a stable API and I was
|
234
|
+
taking backwards compatibilty seriously.</p>
|
235
|
+
|
236
|
+
<p>So I treated it as a project at 1.0 and I did my best to release versions that
|
237
|
+
were backward compatible and added deprecations for what I wanted to do in 1.0.
|
238
|
+
I saw things that I wanted to completely rewrite, but I resisted the urge to
|
239
|
+
burn it all down and start again.</p>
|
240
|
+
|
241
|
+
<p>When I was close to being caught up on the backlog of issues and pull requests,
|
242
|
+
I started thinking about releasing version 1.0, and I knew I wanted to create a
|
243
|
+
website for the project. I worked with <a href="http://danielariza.com">Daniel Ariza</a> to make it happen. I
|
244
|
+
ripped apart the README and rewrote just about all the sections.</p>
|
245
|
+
|
246
|
+
<p>There was an open issue on the project about renaming the Gem and I knew that
|
247
|
+
launching the website and releasing 1.0 would be the perfect opportunity, so I
|
248
|
+
went for it. There was a suggestion to change the name to Feedzilla, but since
|
249
|
+
that is already a thing, I went with Feedjira. I bought the domain and setup an
|
250
|
+
organization by that name on GitHub.</p>
|
251
|
+
|
252
|
+
<p>With those things in place, I needed to actually update the code for these
|
253
|
+
changes. I wanted to make this transition as easy as possible and devised a
|
254
|
+
simple way to use <a href="/versions.html">three versions</a> to make the jump to 1.0.</p>
|
255
|
+
|
256
|
+
<p>For most users, upgrading to 1.0 should be a breeze, but I have an <a href="/upgrading.html">upgrade
|
257
|
+
page</a> to help with a couple details. If you have any trouble upgrading,
|
258
|
+
please let me know by <a href="https://github.com/feedjira/feedjira/issues">opening an issue</a>.</p>
|
259
|
+
|
260
|
+
<p>There are still lots of things I&rsquo;d like to do with this Gem. I mentioned seeing
|
261
|
+
things that I wanted to completely rewrite, so that&rsquo;ll be something that I work
|
262
|
+
on for a 2.0 release, but that&rsquo;s a ways off. I&rsquo;d like to officially support
|
263
|
+
JRuby. Many people use Feedjira with Rails, so a separate project that helps
|
264
|
+
those users get up and running quickly seems to have value.</p>
|
265
|
+
|
266
|
+
<p>The list goes on.</p>
|
267
|
+
|
268
|
+
<p>I do have a request before I finish this thing: I&rsquo;d like to hear from users that
|
269
|
+
have apps in production using Feedjira. If you&rsquo;re using Feedjira for a
|
270
|
+
commercial app, please <a href="feedjira@gmail.com">email me</a>!</p>
|
271
|
+
|
272
|
+
<p>Thanks to everyone who has helped me accomplish this, but especially <a href="http://www.pauldix.net">Paul
|
273
|
+
Dix</a> for creating such a fun project to work on, <a href="http://danielariza.com">Daniel Ariza</a> for a
|
274
|
+
badass website design and the many people who opened issues or sent pull
|
275
|
+
requests. Open source is fun to work on because of people like you!! &lt;3 &lt;3 &lt;3</p>
|
276
|
+
</content>
|
277
|
+
</entry>
|
278
|
+
</feed>
|
279
|
+
http_version:
|
280
|
+
recorded_at: Mon, 31 Oct 2016 02:29:13 GMT
|
281
|
+
recorded_with: VCR 3.0.3
|
data/lib/feedjira.rb
CHANGED
@@ -5,11 +5,16 @@ require 'sax-machine'
|
|
5
5
|
require 'loofah'
|
6
6
|
|
7
7
|
require 'feedjira/core_ext'
|
8
|
+
require 'feedjira/date_time_utilities/date_time_pattern_parser'
|
9
|
+
require 'feedjira/date_time_utilities/date_time_language_parser'
|
10
|
+
require 'feedjira/date_time_utilities'
|
11
|
+
require 'feedjira/date_time_utilities'
|
8
12
|
require 'feedjira/feed_entry_utilities'
|
9
13
|
require 'feedjira/feed_utilities'
|
10
14
|
require 'feedjira/feed'
|
11
15
|
require 'feedjira/parser'
|
12
16
|
require 'feedjira/parser/rss_entry'
|
17
|
+
require 'feedjira/parser/rss_image'
|
13
18
|
require 'feedjira/parser/rss'
|
14
19
|
require 'feedjira/parser/atom_entry'
|
15
20
|
require 'feedjira/parser/atom'
|
@@ -18,13 +23,17 @@ require 'feedjira/version'
|
|
18
23
|
|
19
24
|
require 'feedjira/parser/rss_feed_burner_entry'
|
20
25
|
require 'feedjira/parser/rss_feed_burner'
|
26
|
+
require 'feedjira/parser/podlove_chapter'
|
21
27
|
require 'feedjira/parser/itunes_rss_owner'
|
28
|
+
require 'feedjira/parser/itunes_rss_category'
|
22
29
|
require 'feedjira/parser/itunes_rss_item'
|
23
30
|
require 'feedjira/parser/itunes_rss'
|
24
31
|
require 'feedjira/parser/atom_feed_burner_entry'
|
25
32
|
require 'feedjira/parser/atom_feed_burner'
|
26
33
|
require 'feedjira/parser/google_docs_atom_entry'
|
27
34
|
require 'feedjira/parser/google_docs_atom'
|
35
|
+
require 'feedjira/parser/atom_youtube_entry'
|
36
|
+
require 'feedjira/parser/atom_youtube'
|
28
37
|
|
29
38
|
module Feedjira
|
30
39
|
class NoParserAvailable < StandardError; end
|
data/lib/feedjira/core_ext.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'feedjira/core_ext/time'
|
2
|
+
require 'feedjira/core_ext/date'
|
3
|
+
require 'feedjira/core_ext/string'
|
@@ -8,10 +8,11 @@ class Date
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def feed_utils_to_local_time
|
11
|
-
feed_utils_to_time(new_offset(DateTime.now.offset-offset), :local)
|
11
|
+
feed_utils_to_time(new_offset(DateTime.now.offset - offset), :local)
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
|
+
|
15
16
|
def feed_utils_to_time(dest, method)
|
16
17
|
Time.send(method, dest.year, dest.month, dest.day, dest.hour, dest.min,
|
17
18
|
dest.sec, dest.zone)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'time'
|
2
|
+
require 'date'
|
3
3
|
|
4
4
|
class Time
|
5
5
|
# Parse a time string and convert it to UTC without raising errors.
|
@@ -11,21 +11,24 @@ class Time
|
|
11
11
|
# === Returns
|
12
12
|
# A Time instance in UTC or nil if there were errors while parsing.
|
13
13
|
def self.parse_safely(dt)
|
14
|
-
if dt
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
when dt.respond_to?(:to_datetime)
|
21
|
-
dt.to_datetime.utc
|
22
|
-
when dt.to_s =~ /\A\d{14}\z/
|
23
|
-
parse("#{dt.to_s}Z", true)
|
24
|
-
else
|
25
|
-
parse(dt.to_s, true).utc
|
26
|
-
end
|
14
|
+
if dt.is_a?(Time)
|
15
|
+
dt.utc
|
16
|
+
elsif dt.respond_to?(:to_datetime)
|
17
|
+
dt.to_datetime.utc
|
18
|
+
elsif dt.respond_to? :to_s
|
19
|
+
parse_string_safely dt.to_s
|
27
20
|
end
|
28
21
|
rescue StandardError
|
29
22
|
nil
|
30
|
-
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_string_safely(string)
|
26
|
+
return nil if string.empty?
|
27
|
+
|
28
|
+
if string =~ /\A\d{14}\z/
|
29
|
+
parse("#{string}Z", true)
|
30
|
+
else
|
31
|
+
parse(string).utc
|
32
|
+
end
|
33
|
+
end
|
31
34
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Feedjira
|
2
|
+
module DateTimeUtilities
|
3
|
+
# This is our date parsing heuristic.
|
4
|
+
# Date Parsers are attempted in order.
|
5
|
+
DATE_PARSERS = [
|
6
|
+
DateTimePatternParser,
|
7
|
+
DateTimeLanguageParser,
|
8
|
+
DateTime
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
# Parse the given string starting with the most common parser (default ruby)
|
12
|
+
# and going over all other available parsers
|
13
|
+
def parse_datetime(string)
|
14
|
+
DATE_PARSERS.find do |parser|
|
15
|
+
begin
|
16
|
+
return parser.parse(string).feed_utils_to_gm_time
|
17
|
+
rescue
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
warn "Failed to parse date #{string.inspect}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Feedjira
|
2
|
+
module DateTimeUtilities
|
3
|
+
class DateTimeLanguageParser
|
4
|
+
MONTHS_ENGLISH =
|
5
|
+
%w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec).freeze
|
6
|
+
MONTHS_SPANISH =
|
7
|
+
%w(Ene Feb Mar Abr May Jun Jul Ago Sep Oct Nov Dic).freeze
|
8
|
+
|
9
|
+
def self.parse(string)
|
10
|
+
DateTime.parse(translate(string))
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.translate(string)
|
14
|
+
MONTHS_SPANISH.each_with_index do |m, i|
|
15
|
+
rgx = Regexp.new("\s#{m}\s", Regexp::IGNORECASE)
|
16
|
+
return string.gsub(rgx, MONTHS_ENGLISH[i]) if string =~ rgx
|
17
|
+
end
|
18
|
+
raise "No translation found for #{string}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Feedjira
|
2
|
+
module DateTimeUtilities
|
3
|
+
class DateTimePatternParser
|
4
|
+
# rubocop:disable Style/AsciiComments
|
5
|
+
# Japanese Symbols are required for strange Date Strings like
|
6
|
+
# '水, 31 8 2016 07:37:00 PDT'
|
7
|
+
JAPANESE_SYMBOLS = %w(日 月 火 水 木 金 土).freeze
|
8
|
+
PATTERNS = ['%m/%d/%Y %T %p', '%d %m %Y %T %Z'].freeze
|
9
|
+
|
10
|
+
def self.parse(string)
|
11
|
+
PATTERNS.each do |p|
|
12
|
+
begin
|
13
|
+
datetime = DateTime.strptime(prepare(string), p)
|
14
|
+
return datetime
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
raise "No pattern matched #{string}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.prepare(string)
|
23
|
+
rgx = Regexp.new("^(#{JAPANESE_SYMBOLS.join('|')}),\s")
|
24
|
+
string.gsub(rgx, '')
|
25
|
+
end
|
26
|
+
private_class_method :prepare
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|