This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension_schema.go
70 lines (56 loc) · 1.65 KB
/
extension_schema.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
package pagerduty
import (
"fmt"
"net/http"
"github.com/google/go-querystring/query"
)
type ExtensionSchema struct {
APIObject
IconURL string `json:"icon_url"`
LogoURL string `json:"logo_url"`
Label string `json:"label"`
Key string `json:"key"`
Description string `json:"description"`
GuideURL string `json:"guide_url"`
SendTypes []string `json:"send_types"`
URL string `json:"url"`
}
type ListExtensionSchemaResponse struct {
APIListObject
ExtensionSchemas []ExtensionSchema `json:"extension_schemas"`
}
type ListExtensionSchemaOptions struct {
APIListObject
Query string `url:"query,omitempty"`
}
func (c *Client) ListExtensionSchemas(o ListExtensionSchemaOptions) (*ListExtensionSchemaResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get("/extension_schemas?" + v.Encode())
if err != nil {
return nil, err
}
var result ListExtensionSchemaResponse
return &result, c.decodeJSON(resp, &result)
}
func (c *Client) GetExtensionSchema(id string) (*ExtensionSchema, error) {
resp, err := c.get("/extension_schemas/" + id)
return getExtensionSchemaFromResponse(c, resp, err)
}
func getExtensionSchemaFromResponse(c *Client, resp *http.Response, err error) (*ExtensionSchema, error) {
if err != nil {
return nil, err
}
var target map[string]ExtensionSchema
if dErr := c.decodeJSON(resp, &target); dErr != nil {
return nil, fmt.Errorf("Could not decode JSON response: %v", dErr)
}
rootNode := "extension_schema"
t, nodeOK := target[rootNode]
if !nodeOK {
return nil, fmt.Errorf("JSON response does not have %s field", rootNode)
}
return &t, nil
}