Skip to content

Commit

Permalink
Added more node versions to Travis, added option to override limiter …
Browse files Browse the repository at this point in the history
…config, closes MadKudu#153
  • Loading branch information
AustinLeeGordon committed Feb 11, 2019
1 parent 55b4d73 commit e922490
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e922490

Please sign in to comment.