yt 0.25.6 → 0.25.7

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: 4906f2b9b0a43d68f1c2bc2e60bb629da1c976b8
4
- data.tar.gz: 35ebf6686a6821d9a71cc73d721b814c1e094261
3
+ metadata.gz: 9b810fefdbabe409e4af5f086ba9b6423812249c
4
+ data.tar.gz: 2cc04a37afd86e0bb7333b59a4c9196c2acbc049
5
5
  SHA512:
6
- metadata.gz: e59bb56d0fce3c1bf71b156af6a35d4373cf03c05ddc22c94ad1705cd39098d2f1379a0eb48859bf98af2d959a81ed4e20e77b01dd5d3faa29159653a1653bf3
7
- data.tar.gz: 9ef78181e2dc8ecfec9742288e119cddf3ad75e164df0dc6a90b0f2d1fc1c31ab59a8f49d36ccb7b406e744254be33e925eb6b478f5af6f482edb602f51f9cc7
6
+ metadata.gz: bcc361e5f7fc1763e85298d605125ce82f0e7a68dbe8a36ca5626fc69fea3fcc7be068288e71c294d0e1fc5fdd0afff9b95ae1731f21e27f109928e2ffaa4a9f
7
+ data.tar.gz: e294831648f38525a06b6795a6d779492a218d2ac939e6a2951ca564210983324c676b94e0c1c0d96de288592721f331dd3decbaa690a0ad2122a7e5d46824e7
@@ -6,6 +6,10 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 0.25.7 - 2015-09-10
10
+
11
+ * [FEATURE] Retry the same request once if YouTube responds with "quotaExceeded"
12
+
9
13
  ## 0.25.6 - 2015-09-03
10
14
 
11
15
  * [FEATURE] New channel/video reports: `videos_added_to_playlists`, `videos_removed_from_playlists`.
@@ -188,13 +188,15 @@ module Yt
188
188
  end
189
189
 
190
190
  # Returns whether it is worth to run a failed request again.
191
- # There are two cases in which retrying a request might be worth:
191
+ # There are three cases in which retrying a request might be worth:
192
192
  # - when the server specifies that the request token has expired and
193
- # the user has to refresh the token in order to tryi again
193
+ # the user has to refresh the token in order to try again
194
194
  # - when the server is unreachable, and waiting for a couple of seconds
195
195
  # might solve the connection issues.
196
+ # - when the user has reached the quota for requests/second, and waiting
197
+ # for a couple of seconds might solve the connection issues.
196
198
  def run_again?
197
- refresh_token_and_retry? || server_error? && sleep_and_retry?
199
+ refresh_token_and_retry? || (server_error? || exceeded_quota?) && sleep_and_retry?
198
200
  end
199
201
 
200
202
  # Returns the list of server errors worth retrying the request once.
@@ -261,6 +263,11 @@ module Yt
261
263
  response_error == Errors::ServerError
262
264
  end
263
265
 
266
+ # @return [Boolean] whether the request exceeds the YouTube quota
267
+ def exceeded_quota?
268
+ response_error == Errors::Forbidden && response.body =~ /quotaExceeded/
269
+ end
270
+
264
271
  # @return [Boolean] whether the request lacks proper authorization.
265
272
  def unauthorized?
266
273
  response_error == Errors::Unauthorized
@@ -1,3 +1,3 @@
1
1
  module Yt
2
- VERSION = '0.25.6'
2
+ VERSION = '0.25.7'
3
3
  end
@@ -37,6 +37,26 @@ describe Yt::Request do
37
37
  end
38
38
  end
39
39
 
40
+ context 'an error code 403 with a "quota exceeded message"' do
41
+ let(:response_class) { Net::HTTPForbidden }
42
+ let(:retry_response) { retry_response_class.new nil, nil, nil }
43
+ let(:response_body) { "{\n \"error\": {\n \"errors\": [\n {\n \"domain\": \"youtube.quota\",\n \"reason\": \"quotaExceeded\",\n \"message\": \"The request cannot be completed because you have exceeded your \\u003ca href=\\\"/youtube/v3/getting-started#quota\\\"\\u003equota\\u003c/a\\u003e.\"\n }\n ],\n \"code\": 403,\n \"message\": \"The request cannot be completed because you have exceeded your \\u003ca href=\\\"/youtube/v3/getting-started#quota\\\"\\u003equota\\u003c/a\\u003e.\"\n }\n}\n" }
44
+ before { allow(retry_response).to receive(:body) }
45
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
46
+
47
+ context 'every time' do
48
+ let(:retry_response_class) { Net::HTTPForbidden }
49
+
50
+ it { expect{request.run}.to fail }
51
+ end
52
+
53
+ context 'but returns a success code 2XX the second time' do
54
+ let(:retry_response_class) { Net::HTTPOK }
55
+
56
+ it { expect{request.run}.not_to fail }
57
+ end
58
+ end
59
+
40
60
  context 'an error code 401' do
41
61
  let(:response_class) { Net::HTTPUnauthorized }
42
62
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.6
4
+ version: 0.25.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport