yt 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72f7e8f2bdbc10f6d4ee9e400032c623f9dcaf9c
4
- data.tar.gz: 3f2eaf3a29cf656f4bf127ad92d4661603effa93
3
+ metadata.gz: a7a1e9d6fa998dd66d1929e0a2c39fbc0d18af93
4
+ data.tar.gz: 1be8fb1e1e1b38d3d2b5f8bfc074511f2dd44b4f
5
5
  SHA512:
6
- metadata.gz: 66571f1ace7215bc148992f19758a974f1ff46cb832c7c2312e76ed4d2bafa41241fd355e09803b0e520fc8c38e7b4d91d3baab53ba81b421d5130751d0b8aba
7
- data.tar.gz: 0d5d8ba68f7350f7d9d744d3202e616cb3bc64e322185c729b24de96bce99a6a44c9cc00b7fb843c00da41b400ccb7d505b8aa0511342bebbc63dcca73e44549
6
+ metadata.gz: cd51e6439cd718fd612ac6433d003da818155f79b4d824c146161a7398f5c52ffa7c2c47807e66b29d08251c758fc10663ed742086b4793c5471f852e70bf109
7
+ data.tar.gz: c0ebf331e22a6b59fa2f56293a01e0a85e1c729636916e0eeccf1856c9cf4715ba91f0c8a98d2325a5f103bed7331adbbc671c970f88d2cccb904b175f73b0eb
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yt (0.5.11)
4
+ yt (0.5.12)
5
5
  activesupport
6
6
 
7
7
  GEM
data/HISTORY.md CHANGED
@@ -18,6 +18,7 @@ v0.5 - 2014/05/16
18
18
  * Update RSpec to 3.0 (only required in development/testing)
19
19
  * New ContentOwner subclass of Account with access to partnered channels
20
20
  * Automatically refresh the access token when it expires or becomes invalid
21
+ * Retry once YouTube earning queries that return error 503
21
22
 
22
23
  v0.4 - 2014/05/09
23
24
  --------------------
data/README.md CHANGED
@@ -365,7 +365,7 @@ To install on your system, run
365
365
 
366
366
  To use inside a bundled Ruby project, add this line to the Gemfile:
367
367
 
368
- gem 'yt', '~> 0.5.11'
368
+ gem 'yt', '~> 0.5.12'
369
369
 
370
370
  Since the gem follows [Semantic Versioning](http://semver.org),
371
371
  indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
@@ -12,6 +12,7 @@ module Yt
12
12
  # case running the same query after one second fixes the issue. This is
13
13
  # not documented by YouTube and hardly testable, but trying again the
14
14
  # same query is a workaround that works and can hardly cause any damage.
15
+ # Similarly, once in while YouTube responds with a random 503 error.
15
16
  rescue Yt::Error => e
16
17
  try_again && rescue?(e) ? sleep(3) && within(days_range, false) : raise
17
18
  end
@@ -42,8 +43,16 @@ module Yt
42
43
  end
43
44
 
44
45
  def rescue?(error)
46
+ bad_request?(error) || backend_error?(error)
47
+ end
48
+
49
+ def bad_request?(error)
45
50
  'badRequest'.in?(error.reasons) && error.message =~ /did not conform/
46
51
  end
52
+
53
+ def backend_error?(error)
54
+ 'backendError'.in?(error.reasons)
55
+ end
47
56
  end
48
57
  end
49
58
  end
@@ -1,3 +1,3 @@
1
1
  module Yt
2
- VERSION = '0.5.11'
2
+ VERSION = '0.5.12'
3
3
  end
@@ -5,10 +5,9 @@ describe Yt::Collections::Earnings do
5
5
  subject(:collection) { Yt::Collections::Earnings.new parent: channel }
6
6
  let(:channel) { Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow' }
7
7
  let(:msg) { {response_body: {error: {errors: [error]}}}.to_json }
8
- let(:error) { {reason: 'badRequest', message: message} }
9
- let(:message) { 'Invalid query. Query did not conform to the expectations.' }
10
8
  let(:date) { 1.day.ago.to_date }
11
9
  let(:dollars) { 10 }
10
+ let(:message) { 'Invalid query. Query did not conform to the expectations.' }
12
11
  before { expect(collection).to behave }
13
12
 
14
13
  describe '#within' do
@@ -19,21 +18,41 @@ describe Yt::Collections::Earnings do
19
18
  end
20
19
 
21
20
  # NOTE: This test is just a reflection of YouTube irrational behavior
22
- # of raising a 400 error once in a while when retrieving earnings.
21
+ # of raising 400 or 504 error once in a while when retrieving earnings.
23
22
  # Hopefully this will get fixed and this code (and test) removed.
24
- context 'given YouTube responds with "Invalid query" the first time' do
23
+ context 'given YouTube responds to the first request with' do
25
24
  let(:behave) { receive(:flat_map) do
26
25
  expect(collection).to receive(:flat_map).and_return [date, dollars]
27
26
  raise Yt::Error, msg
28
27
  end}
29
28
 
30
- it { expect(collection.within(date..date)[date]).to eq dollars }
29
+ context 'an Invalid Query error' do
30
+ let(:error) { {reason: 'badRequest', message: message} }
31
+
32
+ it { expect(collection.within(date..date)[date]).to eq dollars }
33
+ end
34
+
35
+ context 'a Backend error' do
36
+ let(:error) { {reason: 'backendError', message: 'Backend Error'} }
37
+
38
+ it { expect(collection.within(date..date)[date]).to eq dollars }
39
+ end
31
40
  end
32
41
 
33
- context 'given YouTube responds with "Invalid query" the second time' do
42
+ context 'given YouTube responds to the second request with' do
34
43
  let(:behave) { receive(:flat_map).twice.and_raise Yt::Error, msg }
35
44
 
36
- it { expect{collection.within date..date}.to raise_error Yt::Error }
45
+ context 'an Invalid Query error' do
46
+ let(:error) { {reason: 'badRequest', message: message} }
47
+
48
+ it { expect{collection.within date..date}.to raise_error Yt::Error }
49
+ end
50
+
51
+ context 'a Backend error' do
52
+ let(:error) { {reason: 'backendError', message: 'Backend Error'} }
53
+
54
+ it { expect{collection.within date..date}.to raise_error Yt::Error }
55
+ end
37
56
  end
38
57
  end
39
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo