forked from lokalise/go-lokalise-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svc_branch.go
98 lines (80 loc) · 3.55 KB
/
svc_branch.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
package lokalise
import (
"path"
"strconv"
)
const (
pathBranches = "branches"
)
// BranchService handles communication with the branch related
// methods of the Lokalise API.
//
// Lokalise API docs: https://lokalise.com/api2docs/curl/#resource-branches
type BranchService struct {
BaseService
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service entity objects
// _____________________________________________________________________________________________________________________
type Branch struct {
WithCreationTime
WithCreationUser
BranchID int64 `json:"branch_id"`
Name string `json:"name"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service request/response objects
// _____________________________________________________________________________________________________________________
type ListBranchesResponse struct {
Paged
WithProjectID
Branches []Branch `json:"branches"`
}
type CreateBranchRequest struct {
Name string `json:"name"`
}
type CreateBranchResponse struct {
WithProjectID
Branch Branch `json:"branch"`
}
type DeleteBranchResponse struct {
WithProjectID
BranchDeleted bool `json:"branch_deleted"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service methods
// _____________________________________________________________________________________________________________________
// List retrieves a list of branches
//
// Lokalise API docs: https://lokalise.com/api2docs/curl/#transition-list-all-branches-get
func (c *BranchService) List(projectID string) (r ListBranchesResponse, err error) {
endpoint := path.Join(pathProjects, projectID, pathBranches)
resp, err := c.getWithOptions(c.Ctx(), endpoint, &r, c.PageOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
// Create creates a branch in the project. Requires admin right.
//
// Lokalise API docs: https://lokalise.com/api2docs/curl/#transition-create-a-branch-post
func (c *BranchService) Create(projectID string, name string) (r CreateBranchResponse, err error) {
endpoint := path.Join(pathProjects, projectID, pathBranches)
resp, err := c.post(c.Ctx(), endpoint, &r, CreateBranchRequest{Name: name})
if err != nil {
return
}
return r, apiError(resp)
}
// Delete deletes a configured branch in the project. Requires admin right.
//
// Lokalise API docs: https://lokalise.com/api2docs/curl/#transition-delete-a-branch-delete
func (c *BranchService) Delete(projectID string, ID int64) (r DeleteBranchResponse, err error) {
endpoint := path.Join(pathProjects, projectID, pathBranches, strconv.FormatInt(ID, 10))
resp, err := c.delete(c.Ctx(), endpoint, &r)
if err != nil {
return
}
return r, apiError(resp)
}