-
Notifications
You must be signed in to change notification settings - Fork 13
/
app.go
95 lines (78 loc) · 2.71 KB
/
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
package mixin
import (
"context"
"fmt"
"time"
)
type (
App struct {
UpdatedAt time.Time `json:"updated_at,omitempty"`
AppID string `json:"app_id,omitempty"`
AppNumber string `json:"app_number,omitempty"`
RedirectURL string `json:"redirect_url,omitempty"`
HomeURL string `json:"home_url,omitempty"`
Name string `json:"name,omitempty"`
IconURL string `json:"icon_url,omitempty"`
Description string `json:"description,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
ResourcePatterns []string `json:"resource_patterns,omitempty"`
Category string `json:"category,omitempty"`
CreatorID string `json:"creator_id,omitempty"`
AppSecret string `json:"app_secret,omitempty"`
}
FavoriteApp struct {
UserID string `json:"user_id,omitempty"`
AppID string `json:"app_id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
}
)
func (c *Client) ReadApp(ctx context.Context, appID string) (*App, error) {
var app App
uri := fmt.Sprintf("/apps/%s", appID)
if err := c.Get(ctx, uri, nil, &app); err != nil {
return nil, err
}
return &app, nil
}
type UpdateAppRequest struct {
RedirectURI string `json:"redirect_uri,omitempty"`
HomeURI string `json:"home_uri,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
IconBase64 string `json:"icon_base64,omitempty"`
SessionSecret string `json:"session_secret,omitempty"`
Category string `json:"category,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
ResourcePatterns []string `json:"resource_patterns,omitempty"`
}
func (c *Client) UpdateApp(ctx context.Context, appID string, req UpdateAppRequest) (*App, error) {
var app App
uri := fmt.Sprintf("/apps/%s", appID)
if err := c.Post(ctx, uri, req, &app); err != nil {
return nil, err
}
return &app, nil
}
func (c *Client) ReadFavoriteApps(ctx context.Context, userID string) ([]*FavoriteApp, error) {
uri := fmt.Sprintf("/users/%s/apps/favorite", userID)
var apps []*FavoriteApp
if err := c.Get(ctx, uri, nil, &apps); err != nil {
return nil, err
}
return apps, nil
}
func (c *Client) FavoriteApp(ctx context.Context, appID string) (*FavoriteApp, error) {
uri := fmt.Sprintf("/apps/%s/favorite", appID)
var app FavoriteApp
if err := c.Post(ctx, uri, nil, &app); err != nil {
return nil, err
}
return &app, nil
}
func (c *Client) UnfavoriteApp(ctx context.Context, appID string) error {
uri := fmt.Sprintf("/apps/%s/unfavorite", appID)
if err := c.Post(ctx, uri, nil, nil); err != nil {
return err
}
return nil
}