|
1 |
| -import { Typeform } from './typeform-types' |
| 1 | +import {Typeform} from './typeform-types' |
2 | 2 |
|
3 | 3 | export class Images {
|
4 |
| - constructor(private _http: Typeform.HTTPClient) {} |
5 |
| - |
6 |
| - public add(args: { |
7 |
| - image?: string |
8 |
| - url?: string |
9 |
| - fileName: string |
10 |
| - }): Promise<Typeform.Image> { |
11 |
| - const { image, url, fileName } = args |
| 4 | + constructor(private _http: Typeform.HTTPClient) { |
| 5 | + } |
12 | 6 |
|
13 |
| - return this._http.request({ |
14 |
| - method: 'post', |
15 |
| - url: `/images`, |
16 |
| - data: { |
17 |
| - image, |
18 |
| - file_name: fileName, |
19 |
| - url, |
20 |
| - }, |
21 |
| - }) |
22 |
| - } |
| 7 | + public add(args: { |
| 8 | + image?: string |
| 9 | + url?: string |
| 10 | + fileName: string |
| 11 | + }): Promise<Typeform.Image> { |
| 12 | + const {image, url, fileName} = args |
23 | 13 |
|
24 |
| - public delete(args: { id: string }): Promise<null> { |
25 |
| - const { id } = args |
| 14 | + return this._http.request({ |
| 15 | + method: 'post', |
| 16 | + url: `/images`, |
| 17 | + data: { |
| 18 | + image, |
| 19 | + file_name: fileName, |
| 20 | + url, |
| 21 | + }, |
| 22 | + }) |
| 23 | + } |
26 | 24 |
|
27 |
| - return this._http.request({ |
28 |
| - method: 'delete', |
29 |
| - url: `/images/${id}`, |
30 |
| - }) |
31 |
| - } |
| 25 | + public delete(args: { id: string }): Promise<null> { |
| 26 | + const {id} = args |
32 | 27 |
|
33 |
| - public get(args: { |
34 |
| - id: string |
35 |
| - size?: string |
36 |
| - backgroundSize?: string |
37 |
| - choiceSize?: string |
38 |
| - }): Promise<Typeform.Image> { |
39 |
| - const { id, size, backgroundSize, choiceSize } = args |
40 |
| - const requestQuery: Typeform.Request = { |
41 |
| - method: 'get', |
42 |
| - url: `/images/${id}`, |
43 |
| - headers: { |
44 |
| - Accept: 'application/json', |
45 |
| - }, |
| 28 | + return this._http.request({ |
| 29 | + method: 'delete', |
| 30 | + url: `/images/${id}`, |
| 31 | + }) |
46 | 32 | }
|
47 | 33 |
|
48 |
| - const choiceImageSizes = [ |
49 |
| - 'default', |
50 |
| - 'thumbnail', |
51 |
| - 'supersize', |
52 |
| - 'supermobile', |
53 |
| - 'supersizefit', |
54 |
| - 'supermobilefit', |
55 |
| - ] |
| 34 | + public get(args: { |
| 35 | + id: string |
| 36 | + size?: string |
| 37 | + backgroundSize?: string |
| 38 | + choiceSize?: string |
| 39 | + }): Promise<Typeform.Image> { |
| 40 | + const {id, size, backgroundSize, choiceSize} = args |
| 41 | + const requestQuery: Typeform.Request = { |
| 42 | + method: 'get', |
| 43 | + url: `/images/${id}`, |
| 44 | + headers: { |
| 45 | + Accept: 'application/json', |
| 46 | + }, |
| 47 | + } |
56 | 48 |
|
57 |
| - if (size) { |
58 |
| - if (['default', 'thumbnail', 'mobile'].includes(size)) { |
59 |
| - requestQuery.url += `/image/${size}` |
60 |
| - } else { |
61 |
| - throw new Error(`Image size doesn't exist`) |
62 |
| - } |
63 |
| - } else if (backgroundSize) { |
64 |
| - if ( |
65 |
| - ['default', 'thumbnail', 'mobile', 'tablet'].includes(backgroundSize) |
66 |
| - ) { |
67 |
| - requestQuery.url += `/background/${backgroundSize}` |
68 |
| - } else { |
69 |
| - throw new Error(`Image background size doesn't exist`) |
70 |
| - } |
71 |
| - } else if (choiceSize) { |
72 |
| - if (choiceImageSizes.includes(choiceSize)) { |
73 |
| - requestQuery.url += `/choice/${choiceSize}` |
74 |
| - } else { |
75 |
| - throw new Error(`Image choice size doesn't exist`) |
76 |
| - } |
77 |
| - } |
| 49 | + const choiceImageSizes = [ |
| 50 | + 'default', |
| 51 | + 'thumbnail', |
| 52 | + 'supersize', |
| 53 | + 'supermobile', |
| 54 | + 'supersizefit', |
| 55 | + 'supermobilefit', |
| 56 | + ] |
78 | 57 |
|
79 |
| - return this._http.request(requestQuery) |
80 |
| - } |
| 58 | + if (size) { |
| 59 | + if (['default', 'thumbnail', 'mobile'].includes(size)) { |
| 60 | + requestQuery.url += `/image/${size}` |
| 61 | + } else { |
| 62 | + throw new Error(`Image size doesn't exist`) |
| 63 | + } |
| 64 | + } else if (backgroundSize) { |
| 65 | + if ( |
| 66 | + ['default', 'thumbnail', 'mobile', 'tablet'].includes(backgroundSize) |
| 67 | + ) { |
| 68 | + requestQuery.url += `/background/${backgroundSize}` |
| 69 | + } else { |
| 70 | + throw new Error(`Image background size doesn't exist`) |
| 71 | + } |
| 72 | + } else if (choiceSize) { |
| 73 | + if (choiceImageSizes.includes(choiceSize)) { |
| 74 | + requestQuery.url += `/choice/${choiceSize}` |
| 75 | + } else { |
| 76 | + throw new Error(`Image choice size doesn't exist`) |
| 77 | + } |
| 78 | + } |
81 | 79 |
|
82 |
| - public list(): Promise<Typeform.Image[]> { |
83 |
| - return this._http.request({ |
84 |
| - method: 'get', |
85 |
| - url: '/images', |
86 |
| - }) |
87 |
| - } |
| 80 | + return this._http.request(requestQuery) |
| 81 | + } |
| 82 | + |
| 83 | + public list(): Promise<Typeform.Image[]> { |
| 84 | + return this._http.request({ |
| 85 | + method: 'get', |
| 86 | + url: '/images', |
| 87 | + }) |
| 88 | + } |
88 | 89 | }
|
0 commit comments