-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnotification_platforms.go
More file actions
77 lines (64 loc) · 2.28 KB
/
notification_platforms.go
File metadata and controls
77 lines (64 loc) · 2.28 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
package scalingo
import (
"context"
"encoding/json"
"github.com/Scalingo/go-scalingo/v10/debug"
"github.com/Scalingo/go-scalingo/v10/http"
"github.com/Scalingo/go-utils/errors/v3"
)
type NotificationPlatformsService interface {
NotificationPlatformsList(context.Context) ([]*NotificationPlatform, error)
NotificationPlatformByName(ctx context.Context, name string) ([]*NotificationPlatform, error)
}
var _ NotificationPlatformsService = (*Client)(nil)
type NotificationPlatform struct {
ID string `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
LogoURL string `json:"logo_url"`
Description string `json:"description"`
AvailableEventIDs []string `json:"available_event_ids"`
}
type PlatformRes struct {
NotificationPlatform *NotificationPlatform `json:"notification_platform"`
}
type PlatformsRes struct {
NotificationPlatforms []*NotificationPlatform `json:"notification_platforms"`
}
func (c *Client) NotificationPlatformsList(ctx context.Context) ([]*NotificationPlatform, error) {
req := &http.APIRequest{
NoAuth: true,
Endpoint: "/notification_platforms",
}
res, err := c.ScalingoAPI().Do(ctx, req)
if err != nil {
return nil, errors.Wrap(ctx, err, "list notification platforms")
}
defer res.Body.Close()
var response PlatformsRes
err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
return nil, errors.Wrap(ctx, err, "decode notification platforms response")
}
return response.NotificationPlatforms, nil
}
func (c *Client) NotificationPlatformByName(ctx context.Context, name string) ([]*NotificationPlatform, error) {
debug.Printf("[NotificationPlatformByName] name: %s", name)
req := &http.APIRequest{
NoAuth: true,
Endpoint: "/notification_platforms/search",
Params: map[string]string{"name": name},
}
res, err := c.ScalingoAPI().Do(ctx, req)
if err != nil {
return nil, errors.Wrap(ctx, err, "search notification platforms by name")
}
defer res.Body.Close()
debug.Printf("[NotificationPlatformByName] response: %+v", res.Body)
var response PlatformsRes
err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
return nil, errors.Wrap(ctx, err, "decode notification platform search response")
}
return response.NotificationPlatforms, nil
}