Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint 2 #73

Merged
merged 19 commits into from
Sep 3, 2019
Merged
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
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,23 @@ const instance = ''; // Name of Zendesk instance
const email = ''; // Email address of Zendesk user
const token = ''; // Generated Zendesk token

const encoded = base64.encode(`${email}/token:${token}`);

const headers = {
'Content-Type': 'application/json',
Authorization: `Basic ${base64.encode(`${email}/token:${token}`)}`
Authorization: `Basic ${encoded}`
};
```

### Choose framework version

```javascript
const zdApi = require('@androozka/zendesk-api-js');
const zaf_v2 = zdApi.v2({ instance, headers });
```

- _**Note**: Only v2, [v1 being deprecated](https://support.zendesk.com/hc/en-us/articles/360002106888-Removal-of-Zendesk-Apps-framework-v1)_

### Selecting API endpoints

```javascript
Expand All @@ -69,44 +74,34 @@ const { support, sunshine } = zaf_v2;
### Add tags to a ticket

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

## API Coverage Status

### Support API

- [x] **Search**
- [x] **Users**
- [x] **Tickets**
- [x] **Ticket Metrics**
- [x] **Tags**
Search, Users, End Users, Groups, Organizations, Tickets, Ticket Comments, Ticket Metrics, Ticket Activities, Tags, Views, Ticket Forms, Ticket Fields, User Fields, Organization Fields

#### Under Construction

- [ ] Views
- [ ] Organizations
- [ ] Groups
- [ ] Ticket Forms
- [ ] Ticket Fields
- [ ] User Fields
- [ ] Organization Fields
- [ ] Brands
- [ ] User Identities
- [ ] User Passwords
- [ ] End Users
- [ ] Group Memberships
- [ ] Custom Agent Roles
- [ ] Organization Subscriptions
- [ ] Organization Memberships
- [ ] Requests
- [ ] Ticket Audits
- [ ] Ticket Comments
- [ ] Ticket Skips
- [ ] Ticket Metric Events
- [ ] Ticket Activities
- [ ] Ticket Import
- [ ] Attachments
- [ ] Satisfaction Ratings
Expand Down
9 changes: 0 additions & 9 deletions src/api/v2/support.js

This file was deleted.

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

This file was deleted.

3 changes: 3 additions & 0 deletions src/v2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = ({ instance, headers }) => ({
support: require('./support')({ instance, headers })
});
32 changes: 32 additions & 0 deletions src/v2/support/end_users/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const validate = require('./validate');

module.exports = ({ instance, headers }) => {
const url = `https://${instance}.zendesk.com`;

return {
show: (options = {}) => {
const { error } = validate.show(options);
if (error) throw new Error(error.details[0].message);

const { id } = options;
return {
method: 'GET',
url: `${url}/api/v2/end_users/${id}.json`,
headers
};
},

update: (options = {}) => {
const { error } = validate.update(options);
if (error) throw new Error(error.details[0].message);

const { id, data } = options;
return {
method: 'PUT',
url: `${url}/api/v2/end_users/${id}.json`,
headers,
data
};
}
};
};
10 changes: 10 additions & 0 deletions src/v2/support/end_users/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const Joi = require('@hapi/joi');

const id = Joi.number().min(1);
const data = Joi.object();

module.exports = {
show: options => Joi.validate(options, { id: id.required() }),
update: options =>
Joi.validate(options, { id: id.required(), data: data.required() })
};
79 changes: 79 additions & 0 deletions src/v2/support/groups/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const validate = require('./validate');

module.exports = ({ instance, headers }) => {
const url = `https://${instance}.zendesk.com`;

return {
list: (options = {}) => {
const { error } = validate.list(options);
if (error) throw new Error(error.details[0].message);

const { user_id } = options;
return {
method: 'GET',
url: `${url}/api/v2${user_id ? `/users/${user_id}` : ''}/groups.json`,
headers
};
},

show_assignable: (options = null) => {
if (options) throw new Error('no options are allowed');

return {
method: 'GET',
url: `${url}/api/v2/groups/assignable.json`,
headers
};
},

show: (options = {}) => {
const { error } = validate.show(options);
if (error) throw new Error(error.details[0].message);

const { id } = options;
return {
method: 'GET',
url: `${url}/api/v2/groups/${id}.json`,
headers
};
},

create: (options = {}) => {
const { error } = validate.create(options);
if (error) throw new Error(error.details[0].message);

const { data } = options;
return {
method: 'POST',
url: `${url}/api/v2/groups.json`,
headers,
data
};
},

update: (options = {}) => {
const { error } = validate.update(options);
if (error) throw new Error(error.details[0].message);

const { id, data } = options;
return {
method: 'PUT',
url: `${url}/api/v2/groups/${id}.json`,
headers,
data
};
},

delete: (options = {}) => {
const { error } = validate.delete(options);
if (error) throw new Error(error.details[0].message);

const { id } = options;
return {
method: 'DELETE',
url: `${url}/api/v2/groups/${id}.json`,
headers
};
}
};
};
15 changes: 15 additions & 0 deletions src/v2/support/groups/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Joi = require('@hapi/joi');

const id = Joi.number().min(1);
const user_id = Joi.number().min(1);
const data = Joi.object();

module.exports = {
list: options => Joi.validate(options, { user_id }),
show_assignable: null, // no options
show: options => Joi.validate(options, { id: id.required() }),
create: options => Joi.validate(options, { data: data.required() }),
update: options =>
Joi.validate(options, { id: id.required(), data: data.required() }),
delete: options => Joi.validate(options, { id: id.required() })
};
17 changes: 17 additions & 0 deletions src/v2/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = ({ instance, headers }) => ({
end_users: require('./end_users')({ instance, headers }),
groups: require('./groups')({ instance, headers }),
organizations: require('./organizations')({ instance, headers }),
organization_fields: require('./organization_fields')({ instance, headers }),
search: require('./search')({ instance, headers }),
tags: require('./tags')({ instance, headers }),
ticket_activities: require('./ticket_activities')({ instance, headers }),
ticket_comments: require('./ticket_comments')({ instance, headers }),
ticket_fields: require('./ticket_fields')({ instance, headers }),
ticket_forms: require('./ticket_forms')({ instance, headers }),
ticket_metrics: require('./ticket_metrics')({ instance, headers }),
tickets: require('./tickets')({ instance, headers }),
user_fields: require('./user_fields')({ instance, headers }),
users: require('./users')({ instance, headers }),
views: require('./views')({ instance, headers })
});
80 changes: 80 additions & 0 deletions src/v2/support/organization_fields/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const validate = require('./validate');

module.exports = ({ instance, headers }) => {
const url = `https://${instance}.zendesk.com`;

return {
list: (options = null) => {
if (options) throw new Error('no options are allowed');

return {
method: 'GET',
url: `${url}/api/v2/organization_fields.json`,
headers
};
},

show: (options = {}) => {
const { error } = validate.show(options);
if (error) throw new Error(error.details[0].message);

const { id } = options;
return {
method: 'GET',
url: `${url}/api/v2/organization_fields/${id}.json`,
headers
};
},

create: (options = {}) => {
const { error } = validate.create(options);
if (error) throw new Error(error.details[0].message);

const { data } = options;
return {
method: 'POST',
url: `${url}/api/v2/organization_fields.json`,
headers,
data
};
},

update: (options = {}) => {
const { error } = validate.update(options);
if (error) throw new Error(error.details[0].message);

const { id, data } = options;
return {
method: 'PUT',
url: `${url}/api/v2/organization_fields/${id}.json`,
headers,
data
};
},

delete: (options = {}) => {
const { error } = validate.delete(options);
if (error) throw new Error(error.details[0].message);

const { id } = options;
return {
method: 'DELETE',
url: `${url}/api/v2/organization_fields/${id}.json`,
headers
};
},

reorder: (options = {}) => {
const { error } = validate.reorder(options);
if (error) throw new Error(error.details[0].message);

const { data } = options;
return {
method: 'PUT',
url: `${url}/api/v2/organization_fields/reorder.json`,
headers,
data
};
}
};
};
14 changes: 14 additions & 0 deletions src/v2/support/organization_fields/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Joi = require('@hapi/joi');

const id = Joi.number().min(1);
const data = Joi.object();

module.exports = {
list: null, // no options
show: options => Joi.validate(options, { id: id.required() }),
create: options => Joi.validate(options, { data: data.required() }),
update: options =>
Joi.validate(options, { id: id.required(), data: data.required() }),
delete: options => Joi.validate(options, { id: id.required() }),
reorder: options => Joi.validate(options, { data: data.required() })
};
Loading