forked from lokalise/go-lokalise-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvc_snapshot.go
91 lines (72 loc) · 3.17 KB
/
svc_snapshot.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
package lokalise
import (
"path"
"strconv"
)
const (
pathSnapshots = "snapshots"
)
type SnapshotService struct {
BaseService
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service entity objects
// _____________________________________________________________________________________________________________________
type Snapshot struct {
WithCreationTime
WithCreationUser
SnapshotID int64 `json:"snapshot_id"`
Title string `json:"title"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service request/response objects
// _____________________________________________________________________________________________________________________
type ListSnapshotsResponse struct {
Paged
WithProjectID
Snapshots []Snapshot `json:"snapshots"`
}
type CreateSnapshotResponse struct {
WithProjectID
Snapshot Snapshot `json:"snapshot"`
}
type DeleteSnapshotResponse struct {
WithProjectID
SnapshotDeleted bool `json:"snapshot_deleted"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service methods
// _____________________________________________________________________________________________________________________
func (c *SnapshotService) List(projectID string) (r ListSnapshotsResponse, err error) {
path := path.Join(pathProjects, projectID, pathSnapshots)
resp, err := c.getWithOptions(c.Ctx(), path, &r, c.PageOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
func (c *SnapshotService) Create(projectID string, title string) (r CreateSnapshotResponse, err error) {
path := path.Join(pathProjects, projectID, pathSnapshots)
resp, err := c.post(c.Ctx(), path, &r, map[string]interface{}{"title": title})
if err != nil {
return
}
return r, apiError(resp)
}
func (c *SnapshotService) Delete(projectID string, ID int64) (r DeleteSnapshotResponse, err error) {
path := path.Join(pathProjects, projectID, pathSnapshots, strconv.FormatInt(ID, 10))
resp, err := c.delete(c.Ctx(), path, &r)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *SnapshotService) Restore(projectID string, ID int64) (r Project, err error) {
path := path.Join(pathProjects, projectID, pathSnapshots, strconv.FormatInt(ID, 10))
resp, err := c.post(c.Ctx(), path, &r, nil)
if err != nil {
return
}
return r, apiError(resp)
}