forked from zambien/go-apigee-edge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
developer_app.go
107 lines (78 loc) · 2.82 KB
/
developer_app.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
package apigee
import (
"path"
)
// DeveloperAppService is an interface for interfacing with the Apigee Edge Admin API
// dealing with developerApps.
type DeveloperAppService interface {
Get(string, string) (*DeveloperApp, *Response, error)
Create(string, DeveloperApp) (*DeveloperApp, *Response, error)
Delete(string, string) (*Response, error)
Update(string, DeveloperApp) (*DeveloperApp, *Response, error)
}
type DeveloperAppServiceOp struct {
client *EdgeClient
}
var _ DeveloperAppService = &DeveloperAppServiceOp{}
type DeveloperApp struct {
Name string `json:"name,omitempty"`
ApiProducts []string `json:"apiProducts,omitempty"`
KeyExpiresIn int `json:"keyExpiresIn,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
Scopes []string `json:"scopes,omitempty"`
CallbackUrl string `json:"callbackUrl,omitempty"`
Credentials []Credential `json:"credentials,omitempty"`
AppId string `json:"appId,omitempty"`
DeveloperId string `json:"developerId,omitempty"`
AppFamily string `json:"appFamily,omitempty"`
Status string `json:"status,omitempty"`
}
func (s *DeveloperAppServiceOp) Get(email string, name string) (*DeveloperApp, *Response, error) {
path := path.Join("developers", email, "apps", name)
req, e := s.client.NewRequest("GET", path, nil, "")
if e != nil {
return nil, nil, e
}
returnedDeveloperApp := DeveloperApp{}
resp, e := s.client.Do(req, &returnedDeveloperApp)
if e != nil {
return nil, resp, e
}
return &returnedDeveloperApp, resp, e
}
func (s *DeveloperAppServiceOp) Create(email string, developerApp DeveloperApp) (*DeveloperApp, *Response, error) {
return postOrPutDeveloperApp(email, developerApp, "POST", s)
}
func (s *DeveloperAppServiceOp) Update(email string, developerApp DeveloperApp) (*DeveloperApp, *Response, error) {
return postOrPutDeveloperApp(email, developerApp, "PUT", s)
}
func (s *DeveloperAppServiceOp) Delete(email string, name string) (*Response, error) {
path := path.Join("developers", email, "apps", name)
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 postOrPutDeveloperApp(email string, developerApp DeveloperApp, opType string, s *DeveloperAppServiceOp) (*DeveloperApp, *Response, error) {
uripath := ""
if opType == "PUT" {
uripath = path.Join("developers", email, "apps", developerApp.Name)
} else {
uripath = path.Join("developers", email, "apps")
}
req, e := s.client.NewRequest(opType, uripath, developerApp, "")
if e != nil {
return nil, nil, e
}
returnedDeveloperApp := DeveloperApp{}
resp, e := s.client.Do(req, &returnedDeveloperApp)
if e != nil {
return nil, resp, e
}
return &returnedDeveloperApp, resp, e
}