forked from DinoChiesa/go-apigee-edge
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcompany_app.go
106 lines (77 loc) · 2.73 KB
/
company_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
package apigee
import (
"path"
)
// CompanyAppService is an interface for interfacing with the Apigee Edge Admin API
// dealing with companyApps.
type CompanyAppService interface {
Get(string, string) (*CompanyApp, *Response, error)
Create(string, CompanyApp) (*CompanyApp, *Response, error)
Delete(string, string) (*Response, error)
Update(string, CompanyApp) (*CompanyApp, *Response, error)
}
type CompanyAppServiceOp struct {
client *EdgeClient
}
var _ CompanyAppService = &CompanyAppServiceOp{}
type CompanyApp struct {
Name string `json:"name,omitempty"`
ApiProducts []string `json:"apiProducts,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"`
CompanyName string `json:"companyName,omitempty"`
AppFamily string `json:"appFamily,omitempty"`
Status string `json:"status,omitempty"`
}
func (s *CompanyAppServiceOp) Get(companyName string, name string) (*CompanyApp, *Response, error) {
path := path.Join("companies", companyName, "apps", name)
req, e := s.client.NewRequest("GET", path, nil, "")
if e != nil {
return nil, nil, e
}
returnedCompanyApp := CompanyApp{}
resp, e := s.client.Do(req, &returnedCompanyApp)
if e != nil {
return nil, resp, e
}
return &returnedCompanyApp, resp, e
}
func (s *CompanyAppServiceOp) Create(companyName string, companyApp CompanyApp) (*CompanyApp, *Response, error) {
return postOrPutCompanyApp(companyName, companyApp, "POST", s)
}
func (s *CompanyAppServiceOp) Update(companyName string, companyApp CompanyApp) (*CompanyApp, *Response, error) {
return postOrPutCompanyApp(companyName, companyApp, "PUT", s)
}
func (s *CompanyAppServiceOp) Delete(companyName string, name string) (*Response, error) {
path := path.Join("companies", companyName, "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 postOrPutCompanyApp(companyName string, companyApp CompanyApp, opType string, s *CompanyAppServiceOp) (*CompanyApp, *Response, error) {
uripath := ""
if opType == "PUT" {
uripath = path.Join("companies", companyName, "apps", companyApp.Name)
} else {
uripath = path.Join("companies", companyName, "apps")
}
req, e := s.client.NewRequest(opType, uripath, companyApp, "")
if e != nil {
return nil, nil, e
}
returnedCompanyApp := CompanyApp{}
resp, e := s.client.Do(req, &returnedCompanyApp)
if e != nil {
return nil, resp, e
}
return &returnedCompanyApp, resp, e
}