feedzirra 0.6.0 → 0.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +3 -2
- data/lib/feedzirra/core_ext/time.rb +2 -0
- data/lib/feedzirra/feed.rb +23 -7
- data/lib/feedzirra/version.rb +1 -1
- data/spec/feedzirra/feed_entry_utilities_spec.rb +6 -0
- data/spec/feedzirra/feed_spec.rb +17 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6547ea21e91fd542899dbb76260595526c269d70
|
4
|
+
data.tar.gz: 4b34a18d37afb06519846075bedaac411770e084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d45bc2899f40f6e3bbe1ac2173deca01e403522b08e8fd2c468df8ea96624f72c948b2d10f266de08f9dee61a27bec9af8294dac83a4aeac6a142cf42c1533f
|
7
|
+
data.tar.gz: 1813e66fa65f47b612befc1be51aefca816e9cf6a2553790abdd31a515ce5e98d2fc8acdba37e71a656fee8bd090ae3a4afa853b228c42882667176bfd1857fd
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Feedzirra Changelog
|
2
2
|
|
3
|
+
## 0.7.0
|
4
|
+
|
5
|
+
* General
|
6
|
+
* README update for callback arity [[#202][]]
|
7
|
+
|
8
|
+
* Enhancements
|
9
|
+
* Add error info to `on_failure` callback [[#194][]]
|
10
|
+
* On failure callbacks get curl and error as args
|
11
|
+
* Bugfix for parsing dates that are ISO 8601 with milliseconds [[#203][]]
|
12
|
+
|
13
|
+
[#194]: https://github.com/pauldix/feedzirra/pull/194
|
14
|
+
[#202]: https://github.com/pauldix/feedzirra/pull/202
|
15
|
+
[#203]: https://github.com/pauldix/feedzirra/pull/203
|
16
|
+
|
3
17
|
## 0.6.0
|
4
18
|
|
5
19
|
* General
|
data/README.md
CHANGED
@@ -101,8 +101,9 @@ updated_feeds = Feedzirra::Feed.update(feeds.values)
|
|
101
101
|
|
102
102
|
# defining custom behavior on failure or success. note that a return status of 304 (not updated) will call the on_success handler
|
103
103
|
feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing",
|
104
|
-
|
105
|
-
|
104
|
+
:on_success => lambda {|url, feed| puts feed.title },
|
105
|
+
:on_failure => lambda {|curl, error| puts error })
|
106
|
+
|
106
107
|
# if a collection was passed into fetch_and_parse, the handlers will be called for each one
|
107
108
|
|
108
109
|
# the behavior for the handlers when using Feedzirra::Feed.update is slightly different. The feed passed into on_success will be
|
data/lib/feedzirra/feed.rb
CHANGED
@@ -320,10 +320,10 @@ module Feedzirra
|
|
320
320
|
responses[url] = feed
|
321
321
|
options[:on_success].call(url, feed) if options.has_key?(:on_success)
|
322
322
|
rescue Exception => e
|
323
|
-
|
323
|
+
call_on_failure(c, e, options[:on_failure])
|
324
324
|
end
|
325
325
|
else
|
326
|
-
|
326
|
+
call_on_failure(c, "Can't determine a parser", options[:on_failure])
|
327
327
|
end
|
328
328
|
end
|
329
329
|
|
@@ -343,13 +343,13 @@ module Feedzirra
|
|
343
343
|
|
344
344
|
curl.on_missing do |c|
|
345
345
|
if c.response_code == 404 && options.has_key?(:on_failure)
|
346
|
-
|
346
|
+
call_on_failure(c, 'Server returned a 404', options[:on_failure])
|
347
347
|
end
|
348
348
|
end
|
349
349
|
|
350
350
|
curl.on_failure do |c, err|
|
351
351
|
responses[url] = c.response_code
|
352
|
-
|
352
|
+
call_on_failure(c, err, options[:on_failure])
|
353
353
|
end
|
354
354
|
end
|
355
355
|
multi.add(easy)
|
@@ -387,18 +387,21 @@ module Feedzirra
|
|
387
387
|
responses[feed.feed_url] = feed
|
388
388
|
options[:on_success].call(feed) if options.has_key?(:on_success)
|
389
389
|
rescue Exception => e
|
390
|
-
|
390
|
+
call_on_failure(c, e, options[:on_failure])
|
391
391
|
end
|
392
392
|
end
|
393
393
|
|
394
394
|
curl.on_failure do |c, err| # response code 50X
|
395
|
-
responses[feed.
|
396
|
-
|
395
|
+
responses[feed.feed_url] = c.response_code
|
396
|
+
call_on_failure(c, 'Server returned a 404', options[:on_failure])
|
397
397
|
end
|
398
398
|
|
399
399
|
curl.on_redirect do |c, err| # response code 30X
|
400
400
|
if c.response_code == 304
|
401
401
|
options[:on_success].call(feed) if options.has_key?(:on_success)
|
402
|
+
else
|
403
|
+
responses[feed.feed_url] = c.response_code
|
404
|
+
call_on_failure(c, err, options[:on_failure])
|
402
405
|
end
|
403
406
|
end
|
404
407
|
|
@@ -438,6 +441,19 @@ module Feedzirra
|
|
438
441
|
def on_parser_failure(url)
|
439
442
|
Proc.new { |message| raise "Error while parsing [#{url}] #{message}" }
|
440
443
|
end
|
444
|
+
|
445
|
+
def call_on_failure(c, error, on_failure)
|
446
|
+
if on_failure
|
447
|
+
if on_failure.arity == 4
|
448
|
+
warn 'on_failure proc with deprecated arity 4 should include a fifth parameter containing the error'
|
449
|
+
on_failure.call(c.url, c.response_code, c.header_str, c.body_str)
|
450
|
+
elsif on_failure.arity == 2
|
451
|
+
on_failure.call(c, error)
|
452
|
+
else
|
453
|
+
warn "on_failure proc with invalid parameters number #{on_failure.arity} instead of 2, ignoring it"
|
454
|
+
end
|
455
|
+
end
|
456
|
+
end
|
441
457
|
end
|
442
458
|
end
|
443
459
|
end
|
data/lib/feedzirra/version.rb
CHANGED
@@ -13,6 +13,12 @@ describe Feedzirra::FeedUtilities do
|
|
13
13
|
time.class.should == Time
|
14
14
|
time.should == Time.parse_safely("Wed Feb 20 18:05:00 UTC 2008")
|
15
15
|
end
|
16
|
+
|
17
|
+
it "should parse a ISO 8601 with milliseconds into Time" do
|
18
|
+
time = @klass.new.parse_datetime("2013-09-17T08:20:13.931-04:00")
|
19
|
+
time.class.should == Time
|
20
|
+
time.should == Time.parse_safely("Tue Sep 17 12:20:13 UTC 2013")
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
describe "sanitizing" do
|
data/spec/feedzirra/feed_spec.rb
CHANGED
@@ -4,7 +4,7 @@ class Hell < StandardError; end
|
|
4
4
|
|
5
5
|
class FailParser
|
6
6
|
def self.parse(_, &on_failure)
|
7
|
-
on_failure.call
|
7
|
+
on_failure.call 'this parser always fails.'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -57,7 +57,7 @@ describe Feedzirra::Feed do
|
|
57
57
|
|
58
58
|
context 'with a callback block' do
|
59
59
|
it 'passes the callback to the parser' do
|
60
|
-
callback = -> { raise Hell }
|
60
|
+
callback = ->(*) { raise Hell }
|
61
61
|
|
62
62
|
expect do
|
63
63
|
Feedzirra::Feed.parse_with FailParser, xml, &callback
|
@@ -268,6 +268,7 @@ describe Feedzirra::Feed do
|
|
268
268
|
before(:each) do
|
269
269
|
@paul_feed = { :xml => load_sample("PaulDixExplainsNothing.xml"), :url => "http://feeds.feedburner.com/PaulDixExplainsNothing" }
|
270
270
|
@trotter_feed = { :xml => load_sample("TrotterCashionHome.xml"), :url => "http://feeds2.feedburner.com/trottercashion" }
|
271
|
+
@invalid_feed = { :xml => 'This feed is invalid', :url => "http://feeds.feedburner.com/InvalidFeed" }
|
271
272
|
end
|
272
273
|
|
273
274
|
describe "#fetch_raw" do
|
@@ -456,11 +457,11 @@ describe Feedzirra::Feed do
|
|
456
457
|
end
|
457
458
|
|
458
459
|
describe 'when the parser raises an exception' do
|
459
|
-
it 'invokes the on_failure callback' do
|
460
|
-
failure =
|
461
|
-
failure.should_receive(:call).with(@
|
460
|
+
it 'invokes the on_failure callback with that exception' do
|
461
|
+
failure = double 'Failure callback', arity: 2
|
462
|
+
failure.should_receive(:call).with(@easy_curl, an_instance_of(Hell))
|
462
463
|
|
463
|
-
Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).and_raise
|
464
|
+
Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).and_raise Hell
|
464
465
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { on_failure: failure })
|
465
466
|
|
466
467
|
@easy_curl.on_success.call(@easy_curl)
|
@@ -473,8 +474,8 @@ describe Feedzirra::Feed do
|
|
473
474
|
end
|
474
475
|
|
475
476
|
it 'invokes the on_failure callback' do
|
476
|
-
failure =
|
477
|
-
failure.should_receive(:call).with(@
|
477
|
+
failure = double 'Failure callback', arity: 2
|
478
|
+
failure.should_receive(:call).with(@easy_curl, an_instance_of(RuntimeError))
|
478
479
|
|
479
480
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { on_failure: failure })
|
480
481
|
@easy_curl.on_success.call(@easy_curl)
|
@@ -484,8 +485,8 @@ describe Feedzirra::Feed do
|
|
484
485
|
|
485
486
|
describe 'when no compatible xml parser class is found' do
|
486
487
|
it 'invokes the on_failure callback' do
|
487
|
-
failure =
|
488
|
-
failure.should_receive(:call).with(@
|
488
|
+
failure = double 'Failure callback', arity: 2
|
489
|
+
failure.should_receive(:call).with(@easy_curl, "Can't determine a parser")
|
489
490
|
|
490
491
|
Feedzirra::Feed.should_receive(:determine_feed_parser_for_xml).and_return nil
|
491
492
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { on_failure: failure })
|
@@ -506,8 +507,8 @@ describe Feedzirra::Feed do
|
|
506
507
|
end
|
507
508
|
|
508
509
|
it 'should call proc if :on_failure option is passed' do
|
509
|
-
failure =
|
510
|
-
failure.should_receive(:call).with(@
|
510
|
+
failure = double 'Failure callback', arity: 2
|
511
|
+
failure.should_receive(:call).with(@easy_curl, nil)
|
511
512
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { :on_failure => failure })
|
512
513
|
@easy_curl.on_failure.call(@easy_curl)
|
513
514
|
end
|
@@ -533,8 +534,8 @@ describe Feedzirra::Feed do
|
|
533
534
|
end
|
534
535
|
|
535
536
|
it 'should call proc if :on_failure option is passed' do
|
536
|
-
complete =
|
537
|
-
complete.should_receive(:call).with(@
|
537
|
+
complete = double 'Failure callback', arity: 2
|
538
|
+
complete.should_receive(:call).with(@easy_curl, 'Server returned a 404')
|
538
539
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { :on_failure => complete })
|
539
540
|
@easy_curl.on_missing.call(@easy_curl)
|
540
541
|
end
|
@@ -659,7 +660,7 @@ describe Feedzirra::Feed do
|
|
659
660
|
end
|
660
661
|
|
661
662
|
it 'invokes the on_failure callback' do
|
662
|
-
failure =
|
663
|
+
failure = double 'Failure callback', arity: 2
|
663
664
|
failure.should_receive(:call)
|
664
665
|
|
665
666
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, { on_failure: failure })
|
@@ -692,7 +693,7 @@ describe Feedzirra::Feed do
|
|
692
693
|
@easy_curl.on_failure.call(@easy_curl)
|
693
694
|
|
694
695
|
responses.length.should == 1
|
695
|
-
responses[
|
696
|
+
responses[@paul_feed[:url]].should == 404
|
696
697
|
end
|
697
698
|
end
|
698
699
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feedzirra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Dix
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: sax-machine
|