simplespotify 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simplespotify.rb +9 -0
- data/lib/simplespotify/constants.rb +4 -0
- data/lib/simplespotify/errors.rb +4 -0
- data/lib/simplespotify/version.rb +1 -1
- 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: 2d54cfd2eb0ed1efd9a94615be4ee1c6282e1b1c
|
4
|
+
data.tar.gz: 12810830ef26485fadca29dff3b547fb530cb464
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e14762ebf2f52ed45a2e0a40fdcf26685d3e2fb9689de787dbda3c7453305283549bfeb7426e9b9d3b5d6f36aa148efabe659c19b2770502b96694ad7242ec74
|
7
|
+
data.tar.gz: 72cf1640ea27b9f09e77e0673b4f7a1382a9c8ed1286a134251885b44f133b8431d3270ccae4c2d305d370b17178a396718b38cfc65ba5713e4a82b21df4a482
|
data/lib/simplespotify.rb
CHANGED
@@ -66,6 +66,15 @@ module SimpleSpotify
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
if http.code == 429 and SimpleSpotify::RETRY_IF_RATELIMITED == 'please'
|
70
|
+
raise SimpleSpotify::Error::RateLimited(429, http.body, request) if request.tries > SimpleSpotify::MAX_RETRIES
|
71
|
+
seconds = http.headers['Retry-After'].to_i + 1 # because computers (purely theoretic)
|
72
|
+
$stderr.puts "[simplespotify] Rate limited. Waiting #{seconds} seconds."
|
73
|
+
$stderr.puts "[simplespotify] waking up at #{Time.now + seconds}"
|
74
|
+
sleep seconds
|
75
|
+
return self.dispatch(request, session: session)
|
76
|
+
end
|
77
|
+
|
69
78
|
return Response.new(http.code, http.body, request)
|
70
79
|
end
|
71
80
|
|
@@ -11,4 +11,8 @@ module SimpleSpotify
|
|
11
11
|
# Upper bound when trying to refresh the authentication token
|
12
12
|
MAX_RETRIES = 2
|
13
13
|
|
14
|
+
# Should we block the whole program until we can retry a rate-limited request? set to
|
15
|
+
# "please" if you'd like to enable this potentially web-request blocking option
|
16
|
+
RETRY_IF_RATELIMITED = false
|
17
|
+
|
14
18
|
end
|
data/lib/simplespotify/errors.rb
CHANGED
@@ -5,6 +5,7 @@ module SimpleSpotify
|
|
5
5
|
case status_code
|
6
6
|
when 401 then Unauthorized
|
7
7
|
when 404 then NotFound
|
8
|
+
when 429 then RateLimited
|
8
9
|
when (500..599) then API
|
9
10
|
else
|
10
11
|
DefaultError
|
@@ -52,5 +53,8 @@ module SimpleSpotify
|
|
52
53
|
class Unauthorized < DefaultError
|
53
54
|
end
|
54
55
|
|
56
|
+
class RateLimited < DefaultError
|
57
|
+
end
|
58
|
+
|
55
59
|
end
|
56
60
|
end
|