node-zendesk
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -25,3 +25,3 @@ //Brand.js: Client for the zendesk API. | ||
Brand.prototype.show = function(brandId, cb) { | ||
this.request('GET', ['brands'], cb); | ||
this.request('GET', ['brands', brandId], cb); | ||
}; | ||
@@ -28,0 +28,0 @@ |
@@ -67,3 +67,4 @@ // client.js - main client file that does most of the processing | ||
useOAuth = this.options.get('oauth'), | ||
token = this.options.get('token'); | ||
token = this.options.get('token'), | ||
asUser = this.options.get('asUser'); | ||
@@ -83,2 +84,6 @@ url = assembleUrl(self, uri); | ||
if(asUser){ | ||
self.options.headers['X-On-Behalf-Of'] = asUser; | ||
} | ||
if (useOAuth) {// token is an oauth token obtained from OAuth2 | ||
@@ -93,3 +98,5 @@ self.options.headers.Authorization = 'Bearer ' + token; | ||
if (body) { | ||
if ('GET' === method) { | ||
self.options.body = undefined; | ||
} else if (body) { | ||
self.options.body = JSON.stringify(body); | ||
@@ -113,3 +120,3 @@ } else if ('GET' !== method && 'application/json' === self.options.headers['Content-Type']) { | ||
var args = Array.prototype.slice.call(arguments), | ||
callback = args.pop(), | ||
callbackOpt = args.pop(), | ||
nextPage = 'Not Null!', | ||
@@ -124,2 +131,15 @@ bodyList = [], | ||
var errorCb, nextCb, completeCb; | ||
if ( typeof callbackOpt === 'function' ) { | ||
errorCb = callbackOpt; | ||
nextCb = function () {}; | ||
completeCb = function (statusList, bodyList, responseList, resultList) { | ||
callbackOpt(null, statusList, bodyList, responseList, resultList) | ||
}; | ||
} else { | ||
errorCb = callbackOpt.error; | ||
nextCb = callbackOpt.next; | ||
completeCb = callbackOpt.complete; | ||
} | ||
if ( throttle ) { | ||
@@ -129,13 +149,18 @@ __request = throttler( this, Client.prototype.request, throttle ); | ||
function processPage(status, body, response, result) { | ||
if(completeCb) { // only accumulate pages if a completeCb is provided | ||
statusList.push(status); | ||
bodyList.push(body); | ||
responseList.push(response); | ||
resultList.push(result); | ||
} | ||
nextPage = result ? result.next_page : null; | ||
nextCb(status, body, response, result, nextPage); | ||
} | ||
return __request.apply(this, args.concat(function (error, status, body, response, result) { | ||
if (error) { | ||
return callback(error); | ||
return errorCb(error); | ||
} | ||
statusList.push(status); | ||
bodyList.push(body); | ||
responseList.push(response); | ||
resultList.push(result); | ||
nextPage = result ? result.next_page : null; | ||
processPage(status, body, response, result); | ||
async.whilst( | ||
@@ -155,8 +180,3 @@ function () { | ||
} | ||
statusList.push(status); | ||
bodyList.push(body); | ||
responseList.push(response); | ||
resultList.push(result); | ||
nextPage = result ? result.next_page : null; | ||
processPage(status, body, response, result); | ||
cb(null); | ||
@@ -167,5 +187,5 @@ }]); | ||
if (err) { | ||
callback(err); | ||
} else { | ||
return callback(null, statusList, flatten(bodyList), responseList, resultList); | ||
return errorCb(err); | ||
} else if(completeCb) { | ||
return completeCb(statusList, flatten(bodyList), responseList, resultList); | ||
} | ||
@@ -172,0 +192,0 @@ } |
@@ -19,3 +19,3 @@ // | ||
attempts = 0, | ||
client = require('../client').createClient(options); | ||
client = require('../client').createClient(options.stores.defaults.store); | ||
nIntervId = setInterval(function getJobStatusUntilComplete() { getJobStatus(jobID); },( interval||500)); | ||
@@ -32,3 +32,5 @@ | ||
if(result["job_status"].status === "completed"){ | ||
if(result["job_status"].status === "completed" || | ||
result["job_status"].status === "failed" || | ||
result["job_status"].status === "killed") { | ||
stopGetJobStatus(); | ||
@@ -35,0 +37,0 @@ console.log('Job '+id+' completed!'); |
@@ -30,2 +30,6 @@ //tickets.js: Client for the zendesk API. | ||
Tickets.prototype.listAssigned = function (userID, cb) { | ||
this.requestAll('GET', ['users', userID, 'tickets', 'assigned'], cb);//all? | ||
}; | ||
Tickets.prototype.listByOrganization = function (orgID, cb) { | ||
@@ -32,0 +36,0 @@ this.requestAll('GET', ['organizations', orgID, 'tickets'], cb);//all |
{ | ||
"name": "node-zendesk", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "zendesk API client wrapper", | ||
@@ -62,8 +62,8 @@ "keywords": [ | ||
"dependencies": { | ||
"request": "2.74.x", | ||
"querystring": "0.2.x", | ||
"async": "0.9.x", | ||
"flatten": "0.0.x", | ||
"nconf": "0.7.x" | ||
"nconf": "0.7.x", | ||
"querystring": "0.2.x", | ||
"request": "^2.81.0" | ||
} | ||
} |
@@ -82,3 +82,3 @@ # node-zendesk | ||
They are fairly self-explanatory no-cookies, timeout, proxy, encoding are all options to request. if using debug its reccomended you use `--encoding utf8` or something similar as all you will see is a buffer otherwise in the response. | ||
They are fairly self-explanatory no-cookies, timeout, proxy, encoding are all options to request. if using debug its recommended you use `--encoding utf8` or something similar as all you will see is a buffer otherwise in the response. | ||
@@ -106,3 +106,3 @@ Because of these command line options you can try a few already from the examples section: | ||
disableGlobalState: true, | ||
debug: true // if you wan't to debug in library only mode, you'll have to include this | ||
debug: true // if you want to debug in library only mode, you'll have to include this | ||
}); | ||
@@ -122,2 +122,18 @@ ``` | ||
## Impersonation | ||
See [Making API requests on behalf of end users ](https://help.zendesk.com/hc/en-us/articles/229488908) to grant impersonate scope. Pass end-user's email when creating client. | ||
```js | ||
var zendesk = require('node-zendesk'); | ||
var client = zendesk.createClient({ | ||
username: 'username', | ||
token: 'oauth_token', | ||
remoteUri: 'https://remote.zendesk.com/api/v2', | ||
oauth: true, | ||
asUser: 'end-user@example.com' | ||
}); | ||
``` | ||
## client | ||
@@ -131,2 +147,6 @@ | ||
## Pagination | ||
When using the `requestAll` method, the client automatically pages-through results, accumulating all responses before returning them to the `cb` method. To monitor pagination, the `cb` parameter can also be an [observer](http://reactivex.io/rxjs/manual/overview.html#observer) – see [this example](examples/ticket-list-observer.js). | ||
## Core API Methods | ||
@@ -422,2 +442,3 @@ (See: https://developer.zendesk.com/rest_api/docs/core/introduction) | ||
list(cb) | ||
listAssigned(userID, cb) | ||
listByOrganization(orgID, cb) | ||
@@ -424,0 +445,0 @@ listByUserRequested(userID, cb) |
146336
75
2820
804
+ Addedajv@6.12.6(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedassert-plus@0.2.0(transitive)
- Removedasync@2.6.4(transitive)
- Removedaws-sign2@0.6.0(transitive)
- Removedbl@1.1.2(transitive)
- Removedboom@2.10.1(transitive)
- Removedcaseless@0.11.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcryptiles@2.0.5(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedform-data@1.0.1(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgenerate-object-property@1.2.0(transitive)
- Removedhar-validator@2.0.6(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhawk@3.1.3(transitive)
- Removedhoek@2.16.3(transitive)
- Removedhttp-signature@1.1.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-my-ip-valid@1.0.1(transitive)
- Removedis-my-json-valid@2.20.6(transitive)
- Removedis-property@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedlodash@4.17.21(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedoauth-sign@0.8.2(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprocess-nextick-args@1.0.7(transitive)
- Removedpunycode@1.4.1(transitive)
- Removedqs@6.2.4(transitive)
- Removedreadable-stream@2.0.6(transitive)
- Removedrequest@2.74.0(transitive)
- Removedsntp@1.0.9(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstringstream@0.0.6(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtough-cookie@2.3.4(transitive)
- Removedtunnel-agent@0.4.3(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedxtend@4.0.2(transitive)
Updatedrequest@^2.81.0