Skip to content

Commit

Permalink
Merge pull request #2 from androozka/support_api-tickets
Browse files Browse the repository at this point in the history
support api: tickets
  • Loading branch information
androozka committed Aug 27, 2019
2 parents 61b81f4 + d89bed1 commit eb491a7
Show file tree
Hide file tree
Showing 22 changed files with 718 additions and 212 deletions.
11 changes: 0 additions & 11 deletions .npmignore

This file was deleted.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![travis_ci](https://travis-ci.org/androozka/zendesk-api-js.svg?branch=master)
[![codecov](https://codecov.io/gh/androozka/zendesk-api-js/branch/master/graph/badge.svg)](https://codecov.io/gh/androozka/zendesk-api-js)
![david_dm](http://david-dm.org/androozka/zendesk-api.js/status.svg)
![David](https://img.shields.io/david/androozka/zendesk-api-js)
[![install size](https://packagephobia.now.sh/badge?p=@androozka/zendesk-api-js)](https://packagephobia.now.sh/result?p=@androozka/zendesk-api-js)
[![npm downloads](https://img.shields.io/npm/dt/@androozka/zendesk-api-js)](http://npm-stat.com/charts.html?package=@androozka/zendesk-api-js)
![twitter follow](https://img.shields.io/twitter/follow/androozka?label=Follow&style=social)
Expand Down Expand Up @@ -55,7 +55,7 @@ const headers = {
### Choose framework version

```javascript
const zaf_v2 = zdApi.v2(instance, headers);
const zaf_v2 = zdApi.v2({ instance, headers });
```

### Selecting API endpoints
Expand All @@ -69,8 +69,9 @@ const { support, sunshine } = zaf_v2;
### Add tags to a ticket

```javascript
const list = { tags: ['tag_1', 'tag_2', ... ] }
const { data } = await axios(support.tags.add('tickets', 123, list));
const data = { tags: ['tag_1', 'tag_2', ... ] }
const req = support.tags.add({ type: 'tickets', id: 123, data });
const res = await axios(req);
```

## API Coverage Status
Expand All @@ -89,7 +90,7 @@ const { data } = await axios(support.tags.add('tickets', 123, list));
- [ ] Organization Subscriptions
- [ ] Organization Memberships
- [ ] Requests
- [ ] Tickets
- [x] Tickets
- [ ] Ticket Import
- [ ] Attachments
- [ ] Satisfaction Ratings
Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const v2 = require('./src/v2');

module.exports = {
v2: (url, headers) => v2(url, headers)
v2: ({ instance, headers }) => require('./src/v2')({ instance, headers })
};
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@
"bugs": {
"url": "https://github.com/androozka/zendesk-api-js/issues"
},
"keywords": [
"zendesk",
"api",
"node"
],
"scripts": {
"test": "jest",
"test:watch": "jest --watchAll --runInBand",
"pack": "npm pack",
"publish": "npm publish --access public"
},
"files": [
"index.js",
"src/*"
],
"dependencies": {},
"devDependencies": {
"@types/jest": "^24.0.18",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (instance, headers) => search_string => ({
module.exports = ({ instance, headers }) => ({ search_string }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/search.json?query=${search_string}`,
headers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = (instance, headers) => ({
module.exports = ({ instance, headers }) => ({
list: () => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/tags.json`,
headers
}),

show: (type, id) => ({
show: ({ type, id }) => ({
method: 'GET',
url: {
tickets: `https://${instance}.zendesk.com/api/v2/tickets/${id}/tags.json`,
Expand All @@ -15,7 +15,7 @@ module.exports = (instance, headers) => ({
headers
}),

set: (type, id, data) => ({
set: ({ type, id, data }) => ({
method: 'POST',
url: {
tickets: `https://${instance}.zendesk.com/api/v2/tickets/${id}/tags.json`,
Expand All @@ -26,7 +26,7 @@ module.exports = (instance, headers) => ({
data
}),

add: (type, id, data) => ({
add: ({ type, id, data }) => ({
method: 'PUT',
url: {
tickets: `https://${instance}.zendesk.com/api/v2/tickets/${id}/tags.json`,
Expand All @@ -37,7 +37,7 @@ module.exports = (instance, headers) => ({
data
}),

remove: (type, id, data) => ({
remove: ({ type, id, data }) => ({
method: 'DELETE',
url: {
tickets: `https://${instance}.zendesk.com/api/v2/tickets/${id}/tags.json`,
Expand All @@ -48,7 +48,7 @@ module.exports = (instance, headers) => ({
data
}),

autocomplete: name => ({
autocomplete: ({ name }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/autocomplete/tags.json?name=${name}`,
headers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module.exports = (instance, headers) => ({
module.exports = ({ instance, headers }) => ({
list: () => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/ticket_metrics.json`,
headers
}),

show: (type, id) => ({
show: ({ type = 'default', ticket_metric_id, ticket_id }) => ({
method: 'GET',
url: {
tickets: `https://${instance}.zendesk.com/api/v2/tickets/${id}/metrics.json`,
ticket_metrics: `https://${instance}.zendesk.com/api/v2/ticket_metrics/${id}.json`
default: `https://${instance}.zendesk.com/api/v2/ticket_metrics/${ticket_metric_id}.json`,
tickets: `https://${instance}.zendesk.com/api/v2/tickets/${ticket_id}/metrics.json`
}[type],
headers
})
Expand Down
165 changes: 165 additions & 0 deletions src/api/v2/routes/support/tickets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
module.exports = ({ instance, headers }) => ({
list: ({ type, id = 0 } = { type: 'tickets', id: 0 }) => ({
method: 'GET',
url: {
tickets: `https://${instance}.zendesk.com/api/v2/tickets.json`,
organizations: `https://${instance}.zendesk.com/api/v2/organizations/${id}/tickets.json`,
users_requested: `https://${instance}.zendesk.com/api/v2/users/${id}/tickets/requested.json`,
users_ccd: `https://${instance}.zendesk.com/api/v2/users/${id}/tickets/ccd.json`,
users_assigned: `https://${instance}.zendesk.com/api/v2/users/${id}/tickets/assigned.json`,
recent: `https://${instance}.zendesk.com/api/v2/tickets/recent.json`
}[type],
headers
}),

list_by_external_id: ({ external_id }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/tickets.json?external_id=${external_id}`,
headers
}),

show: ({ id }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}.json`,
headers
}),

show_many: ({ ids }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/tickets/show_many.json?ids=${ids}`,
headers
}),

create: ({ data }) => ({
method: 'POST',
url: `https://${instance}.zendesk.com/api/v2/tickets.json`,
headers,
data
}),

create_many: ({ data }) => ({
method: 'POST',
url: `https://${instance}.zendesk.com/api/v2/tickets/create_many.json`,
headers,
data
}),

update: ({ id, data }) => ({
method: 'PUT',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}.json`,
headers,
data
}),

update_many: ({ ids = '', data }) => ({
method: 'PUT',
url: `https://${instance}.zendesk.com/api/v2/tickets/update_many.json${
ids ? `?ids=${ids}` : ''
}`,
headers,
data
}),

mark_as_spam: ({ id }) => ({
method: 'PUT',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}/mark_as_spam.json`,
headers
}),

mark_as_spam_bulk: ({ ids }) => ({
method: 'PUT',
url: `https://${instance}.zendesk.com/api/v2/tickets/mark_many_as_spam.json?ids=${ids}`,
headers
}),

merge: ({ id, data }) => ({
method: 'POST',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}/merge.json`,
headers,
data
}),

related: ({ id }) => ({
method: 'POST',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}/related.json`,
headers
}),

delete: ({ id }) => ({
method: 'DELETE',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}.json`,
headers
}),

delete_bulk: ({ ids }) => ({
method: 'DELETE',
url: `https://${instance}.zendesk.com/api/v2/tickets/destroy_many.json?ids=${ids}`,
headers
}),

deleted: () => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/deleted_tickets.json`,
headers
}),

restore: ({ id }) => ({
method: 'PUT',
url: `https://${instance}.zendesk.com/api/v2/deleted_tickets/${id}/restore.json`,
headers
}),

restore_bulk: ({ ids }) => ({
method: 'PUT',
url: `https://${instance}.zendesk.com/api/v2/deleted_tickets/restore_many?ids=${ids}`,
headers
}),

delete_permanently: ({ id }) => ({
method: 'DELETE',
url: `https://${instance}.zendesk.com/api/v2/deleted_tickets/${id}.json`,
headers
}),

delete_permanently_bulk: ({ ids }) => ({
method: 'DELETE',
url: `https://${instance}.zendesk.com/api/v2/deleted_tickets/destroy_many?ids=${ids}`,
headers
}),

collaborators: ({ id }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}/collaborators.json`,
headers
}),

followers: ({ id }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}/followers.json`,
headers
}),

email_ccs: ({ id }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}/email_ccs.json`,
headers
}),

incidents: ({ id }) => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/tickets/${id}/incidents.json`,
headers
}),

problems: () => ({
method: 'GET',
url: `https://${instance}.zendesk.com/api/v2/problems.json`,
headers
}),

autocomplete_problems: ({ name }) => ({
method: 'POST',
url: `https://${instance}.zendesk.com/api/v2/problems/autocomplete.json?text=${name}`,
headers
})
});
9 changes: 9 additions & 0 deletions src/api/v2/support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = ({ instance, headers }) => ({
search: require('./routes/support/search')({ instance, headers }),
tickets: require('./routes/support/tickets')({ instance, headers }),
ticket_metrics: require('./routes/support/ticketMetrics')({
instance,
headers
}),
tags: require('./routes/support/tags')({ instance, headers })
});
3 changes: 3 additions & 0 deletions src/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = ({ instance, headers }) => ({
support: require('./api/v2/support')({ instance, headers })
});
5 changes: 0 additions & 5 deletions src/v2/api/support/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/v2/index.js

This file was deleted.

21 changes: 14 additions & 7 deletions tests/package.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
const pkg = require('..');

describe('Zendesk App Frameworks', () => {
const headers = {};
let api;
describe('package', () => {
let instance, headers;

describe('v2', () => {
beforeAll(() => (api = pkg.v2('', headers)));
afterAll(() => (api = null));
beforeEach(() => {
instance = 'test';
headers = {};
});

afterEach(() => {
instance = '';
headers = null;
});

test('Support API', () => expect(api.support).toBeDefined());
test('zaf v2', () => {
expect(typeof pkg.v2).toBe('function');
expect(typeof pkg.v2({ instance, headers })).toBe('object');
});
});
18 changes: 18 additions & 0 deletions tests/src/api/v2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const v2 = require('../../../src/v2');

const instance = '';
const headers = {};

describe('zaf v2', () => {
let zaf;

beforeEach(() => {
zaf = v2({ instance, headers });
});

afterEach(() => {
zaf = null;
});

test('support api', () => expect(zaf.support).toBeDefined());
});
Loading

0 comments on commit eb491a7

Please sign in to comment.