-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththemes.go
111 lines (103 loc) · 2.84 KB
/
themes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package gotypeform
import (
"bytes"
"encoding/json"
)
type Themes struct {
TotalItems int `json:"total_items"`
PageCount int `json:"page_count"`
Items []Theme `json:"items"`
}
type Theme struct {
Background *Background `json:"background,omitempty"`
Colors *Colors `json:"colors,omitempty"`
Fields *ThemeFields `json:"fields,omitempty"`
Font string `json:"font,omitempty"`
HasTransparentButton bool `json:"has_transparent_button"`
ID string `json:"id,omitempty"`
Name string `json:"name"`
Screens *Screens `json:"screens,omitempty"`
Visibility string `json:"visibility,omitempty"`
}
type Background struct {
Brightness float64 `json:"brightness"`
Href string `json:"href"`
Layout string `json:"layout"`
}
type Colors struct {
Answer string `json:"answer"`
Background string `json:"background"`
Button string `json:"button"`
Question string `json:"question"`
}
type ThemeFields struct {
Alignment string `json:"alignment"`
FontSize string `json:"font_size"`
}
type Screens struct {
Alignment string `json:"alignment"`
FontSize string `json:"font_size"`
}
type ThemeQueryParams struct {
Page int `url:"page,omitempty"`
PageSize int `url:"page_size,omitempty"`
}
func (t *Typeform) GetTheme(id string) (*Theme, error) {
contents, err := t.buildAndExecRequest("GET", themesUrl+"/"+id, nil)
if err != nil {
return nil, err
}
var theme *Theme
err = json.Unmarshal(contents, &theme)
if err != nil {
return nil, err
}
return theme, nil
}
func (t *Typeform) CreateTheme(themedata Theme) (*Theme, error) {
requestBody := &themedata
json_data, err := json.Marshal(requestBody)
if err != nil {
return nil, err
}
contents, err := t.buildAndExecRequest("POST", themesUrl, bytes.NewBuffer(json_data))
if err != nil {
return nil, err
}
var theme *Theme
err = json.Unmarshal(contents, &theme)
if err != nil {
return nil, err
}
return theme, nil
}
func (t *Typeform) DeleteTheme(id string) error {
_, err := t.buildAndExecRequest("DELETE", themesUrl+"/"+id, nil)
return err
}
func (t *Typeform) UpdateTheme(id string, theme Theme) error {
requestBody := &theme
json_data, err := json.Marshal(requestBody)
if err != nil {
return err
}
_, err = t.buildAndExecRequest("PUT", themesUrl+"/"+id, bytes.NewBuffer(json_data))
return err
}
func (t *Typeform) GetAllThemes(params ThemeQueryParams) (*Themes, error) {
requestBody := ¶ms
json_data, err := json.Marshal(requestBody)
if err != nil {
return nil, err
}
contents, err := t.buildAndExecRequest("GET", themesUrl, bytes.NewBuffer(json_data))
if err != nil {
return nil, err
}
var themes *Themes
err = json.Unmarshal(contents, &themes)
if err != nil {
return nil, err
}
return themes, nil
}