yt 0.5.11 → 0.5.12
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/Gemfile.lock +1 -1
- data/HISTORY.md +1 -0
- data/README.md +1 -1
- data/lib/yt/collections/earnings.rb +9 -0
- data/lib/yt/version.rb +1 -1
- data/spec/collections/earnings_spec.rb +26 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7a1e9d6fa998dd66d1929e0a2c39fbc0d18af93
|
4
|
+
data.tar.gz: 1be8fb1e1e1b38d3d2b5f8bfc074511f2dd44b4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd51e6439cd718fd612ac6433d003da818155f79b4d824c146161a7398f5c52ffa7c2c47807e66b29d08251c758fc10663ed742086b4793c5471f852e70bf109
|
7
|
+
data.tar.gz: c0ebf331e22a6b59fa2f56293a01e0a85e1c729636916e0eeccf1856c9cf4715ba91f0c8a98d2325a5f103bed7331adbbc671c970f88d2cccb904b175f73b0eb
|
data/Gemfile.lock
CHANGED
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.
|
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
|
data/lib/yt/version.rb
CHANGED
@@ -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
|
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
|
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
|
-
|
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
|
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
|
-
|
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
|