-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.go
More file actions
81 lines (68 loc) · 2.4 KB
/
modules.go
File metadata and controls
81 lines (68 loc) · 2.4 KB
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
package api
import (
"context"
"encoding/json"
"fmt"
"net/http"
"gopkg.in/nullstone-io/go-api-client.v0/response"
"gopkg.in/nullstone-io/go-api-client.v0/types"
)
type Modules struct {
Client *Client
}
func (m Modules) basePath(orgName string) string {
return fmt.Sprintf("orgs/%s/modules", orgName)
}
func (m Modules) path(orgName, moduleName string) string {
return fmt.Sprintf("orgs/%s/modules/%s", orgName, moduleName)
}
func (m Modules) List(ctx context.Context, orgName string) ([]types.Module, error) {
res, err := m.Client.Do(ctx, http.MethodGet, m.basePath(orgName), nil, nil, nil)
if err != nil {
return nil, err
}
return response.ReadJsonVal[[]types.Module](res)
}
func (m Modules) Get(ctx context.Context, orgName, moduleName string) (*types.Module, error) {
res, err := m.Client.Do(ctx, http.MethodGet, m.path(orgName, moduleName), nil, nil, nil)
if err != nil {
return nil, err
}
return response.ReadJsonPtr[types.Module](res)
}
type CreateModuleInput struct {
Name string `json:"name"`
FriendlyName string `json:"friendlyName"`
Description string `json:"description"`
IsPublic bool `json:"isPublic"`
Category string `json:"category"`
Subcategory string `json:"subcategory"`
ProviderTypes []string `json:"providerTypes"`
Platform string `json:"platform"`
Subplatform string `json:"subplatform"`
Type string `json:"type"`
AppCategories []string `json:"appCategories"`
SourceUrl string `json:"sourceUrl"`
Status string `json:"status"`
}
func (m Modules) Create(ctx context.Context, orgName string, input CreateModuleInput) (*types.Module, error) {
rawPayload, _ := json.Marshal(input)
res, err := m.Client.Do(ctx, http.MethodPost, m.basePath(orgName), nil, nil, json.RawMessage(rawPayload))
if err != nil {
return nil, err
}
return response.ReadJsonPtr[types.Module](res)
}
type UpdateModuleInput struct {
IsPublic *bool `json:"isPublic,omitempty"`
SourceUrl *string `json:"sourceUrl,omitempty"`
Status *string `json:"status,omitempty"`
}
func (m Modules) Update(ctx context.Context, orgName string, moduleName string, input UpdateModuleInput) (*types.Module, error) {
rawPayload, _ := json.Marshal(input)
res, err := m.Client.Do(ctx, http.MethodPut, m.path(orgName, moduleName), nil, nil, json.RawMessage(rawPayload))
if err != nil {
return nil, err
}
return response.ReadJsonPtr[types.Module](res)
}