UNPKG

1.75 kBJavaScriptView Raw
1const Joi = require('@hapi/joi');
2const { validate, prepare } = require('../../utils/options');
3
4// Validation
5const _id = Joi.number().positive();
6const _data = Joi.object();
7
8// Initialize Endpoint
9module.exports = (options = {}) => {
10 const { error } = validate(options);
11 if (error) throw new Error(error.details[0].message);
12
13 const { url, headers } = prepare(options);
14
15 return {
16 /**
17 * List Bookmarks
18 *
19 * GET /api/v2/bookmarks.json
20 * https://developer.zendesk.com/rest_api/docs/support/bookmarks#list-bookmarks
21 */
22 list: () => {
23 // Ignore any options
24 return {
25 method: 'GET',
26 url: `${url}/api/v2/bookmarks.json`,
27 headers
28 };
29 },
30
31 /**
32 * Create Bookmark
33 *
34 * POST /api/v2/bookmarks.json
35 * https://developer.zendesk.com/rest_api/docs/support/bookmarks#create-bookmark
36 */
37 create: (options = {}) => {
38 const { error } = Joi.object({
39 data: _data.required()
40 }).validate(options);
41 if (error) throw new Error(error.details[0].message);
42
43 const { data } = options;
44 return {
45 method: 'POST',
46 url: `${url}/api/v2/bookmarks.json`,
47 headers,
48 data
49 };
50 },
51
52 /**
53 * Delete Bookmark
54 *
55 * DELETE /api/v2/bookmarks/{id}.json
56 * https://developer.zendesk.com/rest_api/docs/support/bookmarks#delete-bookmark
57 */
58 delete: (options = {}) => {
59 const { error } = Joi.object({
60 id: _id.required()
61 }).validate(options);
62 if (error) throw new Error(error.details[0].message);
63
64 const { id } = options;
65 return {
66 method: 'DELETE',
67 url: `${url}/api/v2/bookmarks/${id}.json`,
68 headers
69 };
70 }
71 };
72};