forked from GetStream/stream-chat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
113 lines (95 loc) · 3.44 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package stream_chat //nolint: golint
import (
"net/http"
"time"
)
type AppSettings struct {
DisableAuth *bool `json:"disable_auth_checks,omitempty"`
DisablePermissions *bool `json:"disable_permissions_checks,omitempty"`
APNConfig *APNConfig `json:"apn_config,omitempty"`
FirebaseConfig *FirebaseConfig `json:"firebase_config,omitempty"`
WebhookURL *string `json:"webhook_url,omitempty"`
}
func (a *AppSettings) SetDisableAuth(b bool) *AppSettings {
a.DisableAuth = &b
return a
}
func (a *AppSettings) SetDisablePermissions(b bool) *AppSettings {
a.DisablePermissions = &b
return a
}
func (a *AppSettings) SetAPNConfig(c APNConfig) *AppSettings {
a.APNConfig = &c
return a
}
func (a *AppSettings) SetFirebaseConfig(c FirebaseConfig) *AppSettings {
a.FirebaseConfig = &c
return a
}
func (a *AppSettings) SetWebhookURL(s string) *AppSettings {
a.WebhookURL = &s
return a
}
func NewAppSettings() *AppSettings {
return &AppSettings{}
}
type APNConfig struct {
Enabled bool `json:"enabled"`
Development bool `json:"development"`
AuthType string `json:"auth_type,omitempty"`
AuthKey []byte `json:"auth_key,omitempty"`
NotificationTemplate string `json:"notification_template"`
Host string `json:"host,omitempty"`
BundleID string `json:"bundle_id,omitempty"`
TeamID string `json:"team_id,omitempty"`
KeyID string `json:"key_id,omitempty"`
}
type FirebaseConfig struct {
Enabled bool `json:"enabled"`
NotificationTemplate string `json:"notification_template"`
}
type PushNotificationFields struct {
APNConfig APNConfig `json:"apn"`
FirebaseConfig FirebaseConfig `json:"firebase"`
}
type Policy struct {
Name string `json:"name"`
Resources []string `json:"resources"`
Roles []string `json:"roles"`
Action int `json:"action"` // allow: 1, deny: 0
Owner bool `json:"owner"`
Priority int `json:"priority"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type AppConfig struct {
Name string `json:"name"`
OrganizationName string `json:"organization"`
WebhookURL string `json:"webhook_url"`
SuspendedExplanation string `json:"suspended_explanation"`
PushNotifications PushNotificationFields `json:"push_notifications"`
ConfigNameMap map[string]*ChannelConfig `json:"channel_configs"`
Policies map[string][]Policy `json:"policies"`
Suspended bool `json:"suspended"`
DisableAuth bool `json:"disable_auth_checks"`
DisablePermissions bool `json:"disable_permissions_checks"`
}
type appResponse struct {
App *AppConfig `json:"app"`
}
// GetAppConfig returns app settings
func (c *Client) GetAppConfig() (*AppConfig, error) {
var resp appResponse
err := c.makeRequest(http.MethodGet, "app", nil, nil, &resp)
if err != nil {
return nil, err
}
return resp.App, nil
}
// UpdateAppSettings makes request to update app settings
// Example of usage:
// settings := NewAppSettings().SetDisableAuth(true)
// err := client.UpdateAppSettings(settings)
func (c *Client) UpdateAppSettings(settings *AppSettings) error {
return c.makeRequest(http.MethodPatch, "app", nil, settings, nil)
}