UNPKG

2.83 kBJavaScriptView Raw
1const Joi = require('@hapi/joi');
2const { validate, prepare } = require('../../utils/options');
3
4// Validation
5const _id = Joi.number().min(1);
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 Locales
18 *
19 * GET /api/v2/locales.json
20 * https://developer.zendesk.com/rest_api/docs/support/locales#list-locales
21 */
22 list: () => {
23 // Ignore any options
24 return {
25 method: 'GET',
26 url: `${url}/api/v2/locales.json`,
27 headers
28 };
29 },
30
31 /**
32 * List Available Public Locales
33 *
34 * GET /api/v2/locales/public.json
35 * https://developer.zendesk.com/rest_api/docs/support/locales#list-available-public-locales
36 */
37 public: () => {
38 // Ignore any options
39 return {
40 method: 'GET',
41 url: `${url}/api/v2/locales/public.json`,
42 headers
43 };
44 },
45
46 /**
47 * List Locales for Agent
48 *
49 * GET /api/v2/locales/agent.json
50 * https://developer.zendesk.com/rest_api/docs/support/locales#list-locales-for-agent
51 */
52 agent: () => {
53 // Ignore any options
54 return {
55 method: 'GET',
56 url: `${url}/api/v2/locales/agent.json`,
57 headers
58 };
59 },
60
61 /**
62 * Show Locale
63 *
64 * GET /api/v2/locales/{id}.json
65 * https://developer.zendesk.com/rest_api/docs/support/locales#show-locale
66 */
67 show: (options = {}) => {
68 const { error } = Joi.object({
69 id: _id.required()
70 }).validate(options);
71 if (error) throw new Error(error.details[0].message);
72
73 const { id } = options;
74 return {
75 method: 'GET',
76 url: `${url}/api/v2/locales/${id}.json`,
77 headers
78 };
79 },
80
81 /**
82 * Show Current Locale
83 *
84 * GET /api/v2/locales/current.json
85 * https://developer.zendesk.com/rest_api/docs/support/locales#show-current-locale
86 */
87 current: () => {
88 // Ignore any options
89 return {
90 method: 'GET',
91 url: `${url}/api/v2/locales/current.json`,
92 headers
93 };
94 },
95
96 /**
97 * Detect best language for user
98 *
99 * GET /api/v2/locales/detect_best_locale.json
100 * https://developer.zendesk.com/rest_api/docs/support/locales#detect-best-language-for-user
101 */
102 detect: (options = {}) => {
103 const { error } = Joi.object({
104 data: _data.required()
105 }).validate(options);
106 if (error) throw new Error(error.details[0].message);
107
108 const { data } = options;
109 return {
110 method: 'GET',
111 url: `${url}/api/v2/locales/detect_best_locale.json`,
112 headers,
113 data
114 };
115 }
116 };
117};