mdottavio / ya-lifx

:bulb: - Yet Another LIFX JS client
MIT License
8 stars 1 forks source link

Rate Limits #5

Closed goliatone closed 7 years ago

goliatone commented 7 years ago

The API response returns rate limits information, which currently is discarded.

At least, it could be added to the result body, or whatever other way to make it available to the developer. Ideally, the library would handle this for the developer.

src/requestHandler.js:

  let doRequest = (endpoint, method, data) => {

   ...

      request(options, function(err, res, body) {
        body = JSON.parse(body);
        if (err) {
          reject(err);
        } else if (res.statusCode < 400) {
           //Pass rate limit info along...
            body.ratelimit = {
                limit: parseInt(res.headers['x-ratelimit-limit'] || 0),
                remaining: parseInt(res.headers['x-ratelimit-remaining'] || 0),
                reset: parseInt(res.headers['x-ratelimit-reset'] || 0)
            };

          resolve(body);
        } else {
         ...
        }
      });
    });
  };
mdottavio commented 7 years ago

@goliatone Can you review #6 ?

Thanks.

mdottavio commented 7 years ago

New version published. https://www.npmjs.com/package/ya-lifx