From e922490927cd6f0aeb29c0dc554754fa18500e1f Mon Sep 17 00:00:00 2001 From: AustinLeeGordon Date: Mon, 11 Feb 2019 08:41:44 -0600 Subject: [PATCH] Added more node versions to Travis, added option to override limiter config, closes #153 --- .travis.yml | 6 +++++- README.md | 18 ++++++++++++++++-- lib/client.js | 8 ++++---- package-lock.json | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 41b4a90..7cde492 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: node_js -node_js: ["8.9.*"] +node_js: +- "node" +- 10 +- 8 +- 6 before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter diff --git a/README.md b/README.md index d14eb4a..582aec6 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ const hubspot = new Hubspot({ You can also authenticate via token: ```javascript -const hubspot = new Hubspot({ accessToken: 'abc' }) +const hubspot = new Hubspot({ accessToken: YOUR_ACCESS_TOKEN }) ``` To change the base url: ```javascript -const hubspot = new Hubspot({ accessToken: 'abc', baseUrl: 'https://some-url' }) +const hubspot = new Hubspot({ accessToken: YOUR_ACCESS_TOKEN, baseUrl: 'https://some-url' }) ``` If you're an app developer, you can also instantiate a client with your app @@ -57,6 +57,20 @@ return hubspot.refreshAccessToken() }) ``` +### Changing rate limiter options + +[Bottleneck](https://github.com/SGrondin/bottleneck) is used for rate limiting. To override the default settings, pass a `limiter` object when instantiating the client. Bottleneck options can be found [here](https://github.com/SGrondin/bottleneck#constructor). + +```javascript +const hubspot = new Hubspot({ + apiKey: YOUR_API_KEY, + limiter: { + maxConcurrent: 2, + minTime: 1000 / 9, + } +}) +``` + ## Usage All methods return a [promise]. The success case includes the returned object diff --git a/lib/client.js b/lib/client.js index 0b5fb41..282b19b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -18,10 +18,6 @@ const _ = require('lodash') const request = require('request-promise') const EventEmitter = require('events').EventEmitter const Bottleneck = require('bottleneck') -const limiter = new Bottleneck({ - maxConcurrent: 9, - minTime: 1000 / 8, -}) const debug = require('debug')('hubspot:client') @@ -49,6 +45,10 @@ class Client extends EventEmitter { }) this.checkLimit = options.checkLimit !== undefined ? options.checkLimit : true + this.limiter = new Bottleneck(Object.assign({ + maxConcurrent: 2, + minTime: 1000 / 9, + }, options.limiter)) this.broadcasts = new Broadcast(this) this.campaigns = new Campaign(this) diff --git a/package-lock.json b/package-lock.json index ec57ec3..fe99553 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "hubspot", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": {