forked from zambien/go-apigee-edge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
developer.go
105 lines (75 loc) · 2.33 KB
/
developer.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
package apigee
import (
"path"
)
// DeveloperService is an interface for interfacing with the Apigee Edge Admin API
// dealing with developers.
type DeveloperService interface {
Get(string) (*Developer, *Response, error)
Create(Developer) (*Developer, *Response, error)
Delete(string) (*Response, error)
Update(Developer) (*Developer, *Response, error)
}
type DeveloperServiceOp struct {
client *EdgeClient
}
var _ DeveloperService = &DeveloperServiceOp{}
type Developer struct {
Email string `json:"email,omitempty"`
FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"`
UserName string `json:"userName,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
DeveloperId string `json:"developerId,omitempty"`
Apps []string `json:"apps,omitempty"`
Status string `json:"status,omitempty"`
}
func (s *DeveloperServiceOp) Get(email string) (*Developer, *Response, error) {
path := path.Join("developers", email)
req, e := s.client.NewRequest("GET", path, nil, "")
if e != nil {
return nil, nil, e
}
returnedDeveloper := Developer{}
resp, e := s.client.Do(req, &returnedDeveloper)
if e != nil {
return nil, resp, e
}
return &returnedDeveloper, resp, e
}
func (s *DeveloperServiceOp) Create(developer Developer) (*Developer, *Response, error) {
return postOrPutDeveloper(developer, "POST", s)
}
func (s *DeveloperServiceOp) Update(developer Developer) (*Developer, *Response, error) {
return postOrPutDeveloper(developer, "PUT", s)
}
func (s *DeveloperServiceOp) Delete(email string) (*Response, error) {
path := path.Join("developers", email)
req, e := s.client.NewRequest("DELETE", path, nil, "")
if e != nil {
return nil, e
}
resp, e := s.client.Do(req, nil)
if e != nil {
return resp, e
}
return resp, e
}
func postOrPutDeveloper(developer Developer, opType string, s *DeveloperServiceOp) (*Developer, *Response, error) {
uripath := ""
if opType == "PUT" {
uripath = path.Join("developers", developer.Email)
} else {
uripath = path.Join("developers")
}
req, e := s.client.NewRequest(opType, uripath, developer, "")
if e != nil {
return nil, nil, e
}
returnedDeveloper := Developer{}
resp, e := s.client.Do(req, &returnedDeveloper)
if e != nil {
return nil, resp, e
}
return &returnedDeveloper, resp, e
}