-
Notifications
You must be signed in to change notification settings - Fork 8
/
notification_platforms.go
78 lines (64 loc) · 2.1 KB
/
notification_platforms.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
package scalingo
import (
"context"
"encoding/json"
"gopkg.in/errgo.v1"
"github.com/Scalingo/go-scalingo/v7/debug"
"github.com/Scalingo/go-scalingo/v7/http"
)
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, errgo.Mask(err)
}
defer res.Body.Close()
var response PlatformsRes
err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
return nil, errgo.Mask(err, errgo.Any)
}
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, errgo.Mask(err)
}
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, errgo.Mask(err, errgo.Any)
}
return response.NotificationPlatforms, nil
}