-
Notifications
You must be signed in to change notification settings - Fork 19
/
svc_screenshot.go
148 lines (119 loc) · 5.18 KB
/
svc_screenshot.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package lokalise
import (
"fmt"
"github.com/google/go-querystring/query"
"github.com/go-resty/resty/v2"
)
const (
pathScreenshots = "screenshots"
)
type ScreenshotService struct {
BaseService
listOpts ScreenshotListOptions
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service entity objects
// _____________________________________________________________________________________________________________________
type Screenshot struct {
WithCreationTime
ScreenshotID int64 `json:"screenshot_id"`
KeyIDs []int64 `json:"key_ids"`
URL string `json:"url"`
Title string `json:"title"`
Description string `json:"description"`
ScreenshotTags []string `json:"tags"`
Width int64 `json:"width"`
Height int64 `json:"height"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service request/response objects
// _____________________________________________________________________________________________________________________
type ScreenshotResponse struct {
WithProjectID
Screenshot Screenshot `json:"screenshot"`
}
type ScreenshotsResponse struct {
Paged
WithProjectID
Screenshots []Screenshot `json:"screenshots"`
}
type DeleteScreenshotResponse struct {
WithProjectID
Deleted bool `json:"screenshot_deleted"`
}
type NewScreenshot struct {
// The screenshot, base64 encoded (with leading image type `data:image/jpeg;base64,`).
// Supported file formats are JPG and PNG.
Body string `json:"data"` // maybe []byte?
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Ocr *bool `json:"ocr,omitempty"`
KeyIDs []int64 `json:"key_ids,omitempty"`
Tags []string `json:"tags,omitempty"`
}
type UpdateScreenshot struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
KeyIDs []int64 `json:"key_ids,omitempty"`
Tags []string `json:"tags,omitempty"`
}
func (c *ScreenshotService) List(projectID string) (r ScreenshotsResponse, err error) {
resp, err := c.getWithOptions(c.Ctx(), fmt.Sprintf("%s/%s/%s", pathProjects, projectID, pathScreenshots), &r, c.ListOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
func (c *ScreenshotService) Create(projectID string, screenshots []NewScreenshot) (r ScreenshotsResponse, err error) {
resp, err := c.post(c.Ctx(), fmt.Sprintf("%s/%s/%s", pathProjects, projectID, pathScreenshots), &r,
map[string]interface{}{
"screenshots": screenshots,
},
)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *ScreenshotService) Retrieve(projectID string, screenshotID int64) (r ScreenshotResponse, err error) {
resp, err := c.get(c.Ctx(), fmt.Sprintf("%s/%s/%s/%d", pathProjects, projectID, pathScreenshots, screenshotID), &r)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *ScreenshotService) Update(projectID string, screenshotID int64, opts UpdateScreenshot) (r ScreenshotResponse, err error) {
resp, err := c.put(c.Ctx(), fmt.Sprintf("%s/%s/%s/%d", pathProjects, projectID, pathScreenshots, screenshotID), &r, opts)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *ScreenshotService) Delete(projectID string, screenshotID int64) (r DeleteScreenshotResponse, err error) {
resp, err := c.delete(c.Ctx(), fmt.Sprintf("%s/%s/%s/%d", pathProjects, projectID, pathScreenshots, screenshotID), &r)
if err != nil {
return
}
return r, apiError(resp)
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Additional methods
// _____________________________________________________________________________________________________________________
type ScreenshotListOptions struct {
// page options
Page uint `url:"page,omitempty"`
Limit uint `url:"limit,omitempty"`
IncludeTags uint8 `json:"include_tags,omitempty"`
ListOnly uint8 `json:"list_only,omitempty"`
}
func (options ScreenshotListOptions) Apply(req *resty.Request) {
v, _ := query.Values(options)
req.SetQueryString(v.Encode())
}
func (c *ScreenshotService) ListOpts() ScreenshotListOptions { return c.listOpts }
func (c *ScreenshotService) SetListOptions(o ScreenshotListOptions) { c.listOpts = o }
func (c *ScreenshotService) WithListOptions(o ScreenshotListOptions) *ScreenshotService {
c.listOpts = o
return c
}