feedjira 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +8 -0
  4. data/.travis.yml +31 -12
  5. data/CHANGELOG.md +15 -1
  6. data/Dangerfile +1 -0
  7. data/Gemfile +2 -1
  8. data/Rakefile +6 -1
  9. data/feedjira.gemspec +16 -14
  10. data/fixtures/vcr_cassettes/fetch_failure.yml +62 -0
  11. data/fixtures/vcr_cassettes/parse_error.yml +222 -0
  12. data/fixtures/vcr_cassettes/success.yml +281 -0
  13. data/lib/feedjira.rb +9 -0
  14. data/lib/feedjira/core_ext.rb +3 -3
  15. data/lib/feedjira/core_ext/date.rb +2 -1
  16. data/lib/feedjira/core_ext/string.rb +1 -1
  17. data/lib/feedjira/core_ext/time.rb +19 -16
  18. data/lib/feedjira/date_time_utilities.rb +24 -0
  19. data/lib/feedjira/date_time_utilities/date_time_language_parser.rb +22 -0
  20. data/lib/feedjira/date_time_utilities/date_time_pattern_parser.rb +29 -0
  21. data/lib/feedjira/feed.rb +27 -18
  22. data/lib/feedjira/feed_entry_utilities.rb +15 -17
  23. data/lib/feedjira/feed_utilities.rb +26 -21
  24. data/lib/feedjira/parser/atom.rb +9 -8
  25. data/lib/feedjira/parser/atom_entry.rb +10 -13
  26. data/lib/feedjira/parser/atom_feed_burner.rb +8 -10
  27. data/lib/feedjira/parser/atom_feed_burner_entry.rb +11 -14
  28. data/lib/feedjira/parser/atom_youtube.rb +20 -0
  29. data/lib/feedjira/parser/atom_youtube_entry.rb +29 -0
  30. data/lib/feedjira/parser/google_docs_atom.rb +6 -6
  31. data/lib/feedjira/parser/google_docs_atom_entry.rb +11 -11
  32. data/lib/feedjira/parser/itunes_rss.rb +39 -22
  33. data/lib/feedjira/parser/itunes_rss_category.rb +38 -0
  34. data/lib/feedjira/parser/itunes_rss_item.rb +28 -20
  35. data/lib/feedjira/parser/itunes_rss_owner.rb +3 -4
  36. data/lib/feedjira/parser/podlove_chapter.rb +20 -0
  37. data/lib/feedjira/parser/rss.rb +10 -8
  38. data/lib/feedjira/parser/rss_entry.rb +17 -21
  39. data/lib/feedjira/parser/rss_feed_burner.rb +4 -6
  40. data/lib/feedjira/parser/rss_feed_burner_entry.rb +23 -28
  41. data/lib/feedjira/parser/rss_image.rb +15 -0
  42. data/lib/feedjira/preprocessor.rb +2 -2
  43. data/lib/feedjira/version.rb +1 -1
  44. data/spec/feedjira/date_time_utilities_spec.rb +41 -0
  45. data/spec/feedjira/feed_entry_utilities_spec.rb +23 -19
  46. data/spec/feedjira/feed_spec.rb +109 -74
  47. data/spec/feedjira/feed_utilities_spec.rb +65 -63
  48. data/spec/feedjira/parser/atom_entry_spec.rb +54 -34
  49. data/spec/feedjira/parser/atom_feed_burner_entry_spec.rb +27 -20
  50. data/spec/feedjira/parser/atom_feed_burner_spec.rb +32 -30
  51. data/spec/feedjira/parser/atom_spec.rb +50 -48
  52. data/spec/feedjira/parser/atom_youtube_entry_spec.rb +86 -0
  53. data/spec/feedjira/parser/atom_youtube_spec.rb +43 -0
  54. data/spec/feedjira/parser/google_docs_atom_entry_spec.rb +5 -4
  55. data/spec/feedjira/parser/google_docs_atom_spec.rb +6 -6
  56. data/spec/feedjira/parser/itunes_rss_item_spec.rb +33 -29
  57. data/spec/feedjira/parser/itunes_rss_owner_spec.rb +10 -9
  58. data/spec/feedjira/parser/itunes_rss_spec.rb +83 -30
  59. data/spec/feedjira/parser/podlove_chapter_spec.rb +37 -0
  60. data/spec/feedjira/parser/rss_entry_spec.rb +50 -33
  61. data/spec/feedjira/parser/rss_feed_burner_entry_spec.rb +55 -33
  62. data/spec/feedjira/parser/rss_feed_burner_spec.rb +31 -26
  63. data/spec/feedjira/parser/rss_spec.rb +56 -24
  64. data/spec/feedjira/preprocessor_spec.rb +11 -3
  65. data/spec/sample_feeds.rb +29 -21
  66. data/spec/sample_feeds/AmazonWebServicesBlog.xml +797 -797
  67. data/spec/sample_feeds/AtomEscapedHTMLInPreTag.xml +13 -0
  68. data/spec/sample_feeds/CRE.xml +5849 -0
  69. data/spec/sample_feeds/FeedBurnerXHTML.xml +400 -400
  70. data/spec/sample_feeds/ITunesWithSingleQuotedAttributes.xml +67 -0
  71. data/spec/sample_feeds/PaulDixExplainsNothing.xml +175 -175
  72. data/spec/sample_feeds/PaulDixExplainsNothingAlternate.xml +175 -175
  73. data/spec/sample_feeds/PaulDixExplainsNothingFirstEntryContent.xml +16 -16
  74. data/spec/sample_feeds/PaulDixExplainsNothingWFW.xml +174 -174
  75. data/spec/sample_feeds/TenderLovemaking.xml +12 -2
  76. data/spec/sample_feeds/TrotterCashionHome.xml +611 -611
  77. data/spec/sample_feeds/TypePadNews.xml +368 -368
  78. data/spec/sample_feeds/itunes.xml +18 -2
  79. data/spec/sample_feeds/pet_atom.xml +229 -229
  80. data/spec/sample_feeds/youtube_atom.xml +395 -0
  81. data/spec/spec_helper.rb +6 -0
  82. 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">&lt;p&gt;About a year ago, I took Feedjira to &lt;a href="http://feedjira.com/blog/2014/03/17/feedjira-goes-one-point-oh.html"&gt;version 1.0&lt;/a&gt; and today I&amp;rsquo;m releasing
59
+ version 2.0. Not much has changed actually - the biggest difference is that
60
+ &lt;code&gt;curb&lt;/code&gt; has been replaced with &lt;code&gt;faraday&lt;/code&gt;. For many users, upgrading to version
61
+ 2.0 won&amp;rsquo;t require anything more than a &lt;code&gt;bundle update feedjira&lt;/code&gt;.&lt;/p&gt;
62
+
63
+ &lt;p&gt;The other big change is that the &lt;code&gt;Feedjira#update&lt;/code&gt; method was removed. It was
64
+ unreliable and mostly just caused issues. To read more about why this was
65
+ removed, check out &lt;a href="https://github.com/feedjira/feedjira/issues/218#issuecomment-40282091"&gt;this comment&lt;/a&gt; on a GitHub issue that was opened
66
+ about it not working as expected.&lt;/p&gt;
67
+
68
+ &lt;p&gt;I&amp;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.&lt;/p&gt;
71
+
72
+ &lt;p&gt;I hope you like version 2.0 - feel free to hit me up &lt;a href="https://twitter.com/feedjira"&gt;on Twitter&lt;/a&gt; or if
73
+ you have any trouble, open a &lt;a href="https://github.com/feedjira/feedjira/issues"&gt;GitHub issue&lt;/a&gt; and I&amp;rsquo;ll give you a hand.&lt;/p&gt;
74
+
75
+ &lt;p&gt;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!&lt;/p&gt;
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">&lt;p&gt;TLDR: development of version 2.0 is being done on the &lt;a href="https://github.com/feedjira/feedjira/tree/two-point-oh"&gt;two-point-oh branch&lt;/a&gt;
89
+ and a &lt;a href="https://github.com/feedjira/feedjira/issues/221"&gt;GitHub issue&lt;/a&gt; is open for you to give feedback on its direction.&lt;/p&gt;
90
+
91
+ &lt;p&gt;I&amp;rsquo;ve starting work on a rewrite for Feedjira and I wanted to try using a &lt;a href="https://github.com/feedjira/feedjira/issues/221"&gt;GitHub
92
+ issue&lt;/a&gt; to discuss what I&amp;rsquo;d like to see in the new version. I&amp;rsquo;m very
93
+ interested in what users think, so please chime in!!&lt;/p&gt;
94
+
95
+ &lt;p&gt;In no particular order, here are some design goals for the new version:&lt;/p&gt;
96
+
97
+ &lt;h2&gt;Change HTTP Library&lt;/h2&gt;
98
+
99
+ &lt;p&gt;This gem depends on &lt;a href="https://github.com/taf2/curb"&gt;curb&lt;/a&gt;, but I&amp;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 &lt;a href="https://github.com/lostisland/faraday"&gt;Faraday&lt;/a&gt;, so that&amp;rsquo;s what I&amp;rsquo;m using at the moment.&lt;/p&gt;
102
+
103
+ &lt;h2&gt;Forget Concurrency&lt;/h2&gt;
104
+
105
+ &lt;p&gt;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&amp;rsquo;t think
107
+ it&amp;rsquo;s reality. I think what&amp;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.&lt;/p&gt;
110
+
111
+ &lt;h2&gt;More Objects&lt;/h2&gt;
112
+
113
+ &lt;p&gt;Feedjira has a dirty little secret and it&amp;rsquo;s the &lt;code&gt;Feedjira::Feed&lt;/code&gt; class. If you
114
+ open that sucker up, you&amp;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 &lt;a href="http://en.wikipedia.org/wiki/Single_responsibility_principle"&gt;SRP&lt;/a&gt; off in the corner crying, its a mess to
117
+ test. I&amp;rsquo;d like to break this down into smaller objects that get instantiated and
118
+ passed around in normal OO fashion.&lt;/p&gt;
119
+
120
+ &lt;h2&gt;Fewer Parsers&lt;/h2&gt;
121
+
122
+ &lt;p&gt;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&amp;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.&lt;/p&gt;
126
+
127
+ &lt;h2&gt;Custom Parser Project&lt;/h2&gt;
128
+
129
+ &lt;p&gt;With version 1.2, I was able to spin off the benchmarks into &lt;a href="https://github.com/feedjira/feedjira-benchmarks"&gt;their own
130
+ project&lt;/a&gt; and I was very happy with how it turned out - I&amp;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.&lt;/p&gt;
135
+
136
+ &lt;h2&gt;Raise Exceptions Instead of Callbacks&lt;/h2&gt;
137
+
138
+ &lt;p&gt;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.&lt;/p&gt;
143
+
144
+ &lt;h2&gt;Feed Updating is Business Logic&lt;/h2&gt;
145
+
146
+ &lt;p&gt;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
+ &lt;a href="https://github.com/feedjira/feedjira/issues/218"&gt;this discussion&lt;/a&gt; for more, but needless to say, I&amp;rsquo;d like to see this entire
150
+ feature set removed.&lt;/p&gt;
151
+
152
+ &lt;h2&gt;Configuration&lt;/h2&gt;
153
+
154
+ &lt;p&gt;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.&lt;/p&gt;
157
+
158
+ &lt;h2&gt;Feedback Appreciated&lt;/h2&gt;
159
+
160
+ &lt;p&gt;Do you have any other ideas to make Feedjira better? Please check out the
161
+ &lt;a href="https://github.com/feedjira/feedjira/issues/221"&gt;GitHub issue&lt;/a&gt; and share what you&amp;rsquo;re thinking. I&amp;rsquo;m open to any feedback, so
162
+ if I just threw your favorite feature on the chopping block, please tell me!&lt;/p&gt;
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">&lt;p&gt;With the release of version 1.2.0, the benchmarks for Feedjira have been moved
175
+ to a separate project: &lt;a href="https://github.com/feedjira/feedjira-benchmarks"&gt;https://github.com/feedjira/feedjira-benchmarks&lt;/a&gt;.&lt;/p&gt;
176
+
177
+ &lt;p&gt;What&amp;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 &lt;a href="/benchmarks.html"&gt;Benchmarks page&lt;/a&gt; on this site so please check that out.&lt;/p&gt;
180
+
181
+ &lt;p&gt;One benchmark that I didn&amp;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&amp;rsquo;t feel like it was scientific enough.&lt;/p&gt;
184
+
185
+ &lt;p&gt;In its place I&amp;rsquo;ve added a benchmark for parsing speed that&amp;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.&lt;/p&gt;
190
+
191
+ &lt;p&gt;For the charts, I ended up learning some &lt;a href="http://www.r-project.org/"&gt;R&lt;/a&gt; so that I could have a little
192
+ more control.&lt;/p&gt;
193
+
194
+ &lt;p&gt;Benchmarks are really only valuable if they can be reproduced by others, so I&amp;rsquo;ve
195
+ written up instructions in the README for setting things up and running them. If
196
+ you&amp;rsquo;re interested, take a look and try running them yourself!&lt;/p&gt;
197
+
198
+ &lt;p&gt;I&amp;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
+ (&lt;a href="https://twitter.com/feedjira"&gt;@feedjira&lt;/a&gt;) or &lt;a href="https://github.com/feedjira/feedjira-benchmarks/issues"&gt;open an issue&lt;/a&gt; on the project&amp;rsquo;s repo.&lt;/p&gt;
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">&lt;p&gt;Last fall, I asked &lt;a href="http://www.pauldix.net"&gt;Paul Dix&lt;/a&gt; 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&amp;rsquo;t have time to work
216
+ on it anymore and so I should feel free to do whatever I thought was best.&lt;/p&gt;
217
+
218
+ &lt;p&gt;Score!&lt;/p&gt;
219
+
220
+ &lt;p&gt;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&amp;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.&lt;/p&gt;
225
+
226
+ &lt;p&gt;I was pleasantly surprised by the nice way many people responded and we got to
227
+ work addressing their questions and issues.&lt;/p&gt;
228
+
229
+ &lt;p&gt;As I was working through issues and pull requests, I kept &lt;a href="http://semver.org"&gt;SemVer&lt;/a&gt; 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.&lt;/p&gt;
235
+
236
+ &lt;p&gt;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.&lt;/p&gt;
240
+
241
+ &lt;p&gt;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 &lt;a href="http://danielariza.com"&gt;Daniel Ariza&lt;/a&gt; to make it happen. I
244
+ ripped apart the README and rewrote just about all the sections.&lt;/p&gt;
245
+
246
+ &lt;p&gt;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.&lt;/p&gt;
251
+
252
+ &lt;p&gt;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 &lt;a href="/versions.html"&gt;three versions&lt;/a&gt; to make the jump to 1.0.&lt;/p&gt;
255
+
256
+ &lt;p&gt;For most users, upgrading to 1.0 should be a breeze, but I have an &lt;a href="/upgrading.html"&gt;upgrade
257
+ page&lt;/a&gt; to help with a couple details. If you have any trouble upgrading,
258
+ please let me know by &lt;a href="https://github.com/feedjira/feedjira/issues"&gt;opening an issue&lt;/a&gt;.&lt;/p&gt;
259
+
260
+ &lt;p&gt;There are still lots of things I&amp;rsquo;d like to do with this Gem. I mentioned seeing
261
+ things that I wanted to completely rewrite, so that&amp;rsquo;ll be something that I work
262
+ on for a 2.0 release, but that&amp;rsquo;s a ways off. I&amp;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.&lt;/p&gt;
265
+
266
+ &lt;p&gt;The list goes on.&lt;/p&gt;
267
+
268
+ &lt;p&gt;I do have a request before I finish this thing: I&amp;rsquo;d like to hear from users that
269
+ have apps in production using Feedjira. If you&amp;rsquo;re using Feedjira for a
270
+ commercial app, please &lt;a href="feedjira@gmail.com"&gt;email me&lt;/a&gt;!&lt;/p&gt;
271
+
272
+ &lt;p&gt;Thanks to everyone who has helped me accomplish this, but especially &lt;a href="http://www.pauldix.net"&gt;Paul
273
+ Dix&lt;/a&gt; for creating such a fun project to work on, &lt;a href="http://danielariza.com"&gt;Daniel Ariza&lt;/a&gt; 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!! &amp;lt;3 &amp;lt;3 &amp;lt;3&lt;/p&gt;
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
@@ -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
@@ -1,3 +1,3 @@
1
- require "feedjira/core_ext/time"
2
- require "feedjira/core_ext/date"
3
- require "feedjira/core_ext/string"
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,6 +1,6 @@
1
1
  class String
2
2
  def sanitize!
3
- self.replace(sanitize)
3
+ replace(sanitize)
4
4
  end
5
5
 
6
6
  def sanitize
@@ -1,5 +1,5 @@
1
- require "time"
2
- require "date"
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
- case
16
- when dt.is_a?(Time)
17
- dt.utc
18
- when dt.respond_to?(:empty?) && dt.empty?
19
- nil
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 unless method_defined?(:parse_safely)
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