Skip to content

Commit e5a9274

Browse files
author
RTLcoil
authored
Add rate_limits back to responses sent from Admin API (#361)
* Add `rate_limits` back to responses sent from Admin API
1 parent e346e7f commit e5a9274

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

lib-es5/api_client/execute_request.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ function execute_request(method, params, auth, api_url, callback) {
7777

7878
if (result.error) {
7979
result.error.http_code = res.statusCode;
80+
} else {
81+
result.rate_limit_allowed = parseInt(res.headers["x-featureratelimit-limit"]);
82+
result.rate_limit_reset_at = new Date(res.headers["x-featureratelimit-reset"]);
83+
result.rate_limit_remaining = parseInt(res.headers["x-featureratelimit-remaining"]);
8084
}
8185

8286
if (result.error) {

lib/api_client/execute_request.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ function execute_request(method, params, auth, api_url, callback, options = {})
7070

7171
if (result.error) {
7272
result.error.http_code = res.statusCode;
73+
} else {
74+
result.rate_limit_allowed = parseInt(res.headers["x-featureratelimit-limit"]);
75+
result.rate_limit_reset_at = new Date(res.headers["x-featureratelimit-reset"]);
76+
result.rate_limit_remaining = parseInt(res.headers["x-featureratelimit-remaining"]);
7377
}
7478

7579
if (result.error) {

test/api_spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,17 @@ describe("api", function () {
468468
}).then(result => expect(result.tags).to.be.empty());
469469
});
470470
});
471+
describe("headers", function () {
472+
it("should include rate limits", function () {
473+
this.timeout(helper.TIMEOUT_MEDIUM);
474+
return cloudinary.v2.api.resources().then(function (result) {
475+
expect(result.rate_limit_allowed).to.be.a("number");
476+
expect(result.rate_limit_reset_at).to.be.an("object");
477+
expect(result.rate_limit_reset_at).to.have.property("getDate");
478+
expect(result.rate_limit_remaining).to.be.a("number");
479+
});
480+
});
481+
});
471482
describe("transformations", function () {
472483
var transformationName;
473484
itBehavesLike("a list with a cursor", cloudinary.v2.api.transformation, EXPLICIT_TRANSFORMATION_NAME);

test/streaming_profiles_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('Cloudinary::Api', function () {
5151
expect(result).not.to.be(void 0);
5252
});
5353
});
54-
it('should create a streaming profile with an array of transformation', function () {
54+
it('should create a streaming profile with an array of transformations', function () {
5555
return api.create_streaming_profile(test_id_1 + 'a', {
5656
representations: [
5757
{

0 commit comments

Comments
 (0)