1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _id = Joi.number().positive();
|
6 | const _data = Joi.object();
|
7 |
|
8 |
|
9 | module.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 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | list: () => {
|
23 |
|
24 | return {
|
25 | method: 'GET',
|
26 | url: `${url}/api/v2/channels/twitter/monitored_twitter_handles.json`,
|
27 | headers
|
28 | };
|
29 | },
|
30 |
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | show: (options = {}) => {
|
38 | const { error } = Joi.object({
|
39 | id: _id.required()
|
40 | }).validate(options);
|
41 | if (error) throw new Error(error.details[0].message);
|
42 |
|
43 | const { id } = options;
|
44 | return {
|
45 | method: 'GET',
|
46 | url: `${url}/api/v2/channels/twitter/monitored_twitter_handles/${id}.json`,
|
47 | headers
|
48 | };
|
49 | },
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | create: (options = {}) => {
|
58 | const { error } = Joi.object({
|
59 | data: _data.required()
|
60 | }).validate(options);
|
61 | if (error) throw new Error(error.details[0].message);
|
62 |
|
63 | const { data } = options;
|
64 | return {
|
65 | method: 'POST',
|
66 | url: `${url}/api/v2/channels/twitter/tickets.json`,
|
67 | headers,
|
68 | data
|
69 | };
|
70 | },
|
71 |
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | status: (options = {}) => {
|
79 | const { error } = Joi.object({
|
80 | id: _id.required()
|
81 | }).validate(options);
|
82 | if (error) throw new Error(error.details[0].message);
|
83 |
|
84 | const { id } = options;
|
85 | return {
|
86 | method: 'GET',
|
87 | url: `${url}/api/v2/channels/twitter/tickets/${id}/statuses.json`,
|
88 | headers
|
89 | };
|
90 | }
|
91 | };
|
92 | };
|