forked from lokalise/go-lokalise-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svc_contributor.go
106 lines (83 loc) · 3.63 KB
/
svc_contributor.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
package lokalise
import (
"fmt"
)
type ContributorService struct {
BaseService
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service entity objects
// _____________________________________________________________________________________________________________________
type Contributor struct {
WithCreationTime
WithUserID
Email string `json:"email"`
Fullname string `json:"fullname"`
Permission
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service request/response objects
// _____________________________________________________________________________________________________________________
type NewContributor struct {
Email string `json:"email"`
Fullname string `json:"fullname,omitempty"`
Permission
}
type ContributorsResponse struct {
Paged
WithProjectID
Contributors []Contributor `json:"contributors"`
}
type ContributorResponse struct {
WithProjectID
Contributor Contributor `json:"contributor"`
}
type DeleteContributorResponse struct {
WithProjectID
IsDeleted bool `json:"contributor_deleted"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service methods
// _____________________________________________________________________________________________________________________
func (c *ContributorService) List(projectID string) (r ContributorsResponse, err error) {
resp, err := c.getWithOptions(c.Ctx(), pathContributors(projectID), &r, c.PageOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
func (c *ContributorService) Create(projectID string, cs []NewContributor) (r ContributorsResponse, err error) {
resp, err := c.post(c.Ctx(), pathContributors(projectID), &r, map[string]interface{}{"contributors": cs})
if err != nil {
return
}
return r, apiError(resp)
}
func (c *ContributorService) Retrieve(projectID string, userID int64) (r ContributorResponse, err error) {
resp, err := c.get(c.Ctx(), pathContributorByID(projectID, userID), &r)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *ContributorService) Update(projectID string, userID int64, p Permission) (r ContributorResponse, err error) {
resp, err := c.put(c.Ctx(), pathContributorByID(projectID, userID), &r, p)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *ContributorService) Delete(projectID string, userID int64) (r DeleteContributorResponse, err error) {
resp, err := c.delete(c.Ctx(), pathContributorByID(projectID, userID), &r)
if err != nil {
return
}
return r, apiError(resp)
}
func pathContributors(projectID string) string {
return fmt.Sprintf("%s/%s/contributors", pathProjects, projectID)
}
func pathContributorByID(projectID string, userID int64) string {
return fmt.Sprintf("%s/%s/contributors/%d", pathProjects, projectID, userID)
}