Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

feat: add gotOptions constructor options #33

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ the [My Account][my-account] page in the Cloudflare dashboard.
```javascript
var cf = require('cloudflare')({
email: 'you@example.com',
key: 'your Cloudflare API key'
key: 'your Cloudflare API key',
gotOptions: {} // options passed to `got`, like a HTTP agent for proxying
});
```

Expand Down Expand Up @@ -71,4 +72,4 @@ async function getZoneStatus(id) {
* `purgeCache(zoneId, params)`
* user
* `read()`
* `edit(params)`
* `edit(params)`
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ var resources = {
};

var Cloudflare = auto(prototypal({
constructor: function (auth) {
constructor: function (options) {
var client = new Client({
email: auth && auth.email,
key: auth && auth.key
email: options && options.email,
key: options && options.key,
gotOptions: options && options.gotOptions
});

Object.defineProperty(this, '_client', {
Expand Down
2 changes: 1 addition & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = prototypal({
constructor: function (options) {
this.email = options.email;
this.key = options.key;
this.getter = new Getter(options);
this.getter = new Getter(options && options.gotOptions);
},
request: function (requestMethod, requestPath, data, opts) {
var uri = 'https://api.cloudflare.com/client/v4/' + requestPath;
Expand Down
5 changes: 4 additions & 1 deletion lib/Getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ var assign = require('object-assign');
var got = require('got');

module.exports = prototypal({
constructor: function (options) {
this.options = options || {};
},
got: function (uri, options) {
options = assign({}, options);
options = assign({}, this.options, options);

return got(uri, options);
}
Expand Down
Loading