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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62554e8195245de7c6e70d71a66bdbe9172239c1
4
- data.tar.gz: f13d4a33c45fed82b33cfe8444469bbebc179831
3
+ metadata.gz: 2d54cfd2eb0ed1efd9a94615be4ee1c6282e1b1c
4
+ data.tar.gz: 12810830ef26485fadca29dff3b547fb530cb464
5
5
  SHA512:
6
- metadata.gz: e34be0b85d181612f75603e841ee4d7405f7e7717b17f8476d46148cbe1efbb9202139008e28854ed63a059a7204f1f197e40a084b55aea4fc149f7328c04eca
7
- data.tar.gz: 6e616282ce1121794cfd6a8c549093f0365ef8098d43816eb0621d97faedf5c72c65833f2026a840615c217bf45f355915f894a01714de69ba2303b222951b3b
6
+ metadata.gz: e14762ebf2f52ed45a2e0a40fdcf26685d3e2fb9689de787dbda3c7453305283549bfeb7426e9b9d3b5d6f36aa148efabe659c19b2770502b96694ad7242ec74
7
+ data.tar.gz: 72cf1640ea27b9f09e77e0673b4f7a1382a9c8ed1286a134251885b44f133b8431d3270ccae4c2d305d370b17178a396718b38cfc65ba5713e4a82b21df4a482
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SimpleSpotify
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplespotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Hidalgo