-
Notifications
You must be signed in to change notification settings - Fork 243
/
license.go
84 lines (67 loc) · 1.93 KB
/
license.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
package pagerduty
import (
"context"
"github.com/google/go-querystring/query"
)
type License struct {
APIObject
Name string `json:"name"`
Description string `json:"description"`
ValidRoles []string `json:"valid_roles"`
RoleGroup string `json:"role_group"`
Summary string `json:"summary"`
CurrentValue int `json:"current_value"`
AllocationsAvailable int `json:"allocations_available"`
}
type LicenseAllocated struct {
APIObject
Name string `json:"name"`
Description string `json:"description"`
ValidRoles []string `json:"valid_roles"`
RoleGroup string `json:"role_group"`
Summary string `json:"summary"`
}
type LicenseAllocation struct {
AllocatedAt string `json:"allocated_at"`
User APIObject
License LicenseAllocated `json:"license"`
}
type ListLicensesResponse struct {
Licenses []License `json:"licenses"`
}
type ListLicenseAllocationsResponse struct {
APIListObject
LicenseAllocations []LicenseAllocation `json:"license_allocations"`
}
type ListLicenseAllocationsOptions struct {
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
func (c *Client) ListLicensesWithContext(ctx context.Context) (*ListLicensesResponse, error) {
resp, err := c.get(ctx, "/licenses", nil)
if err != nil {
return nil, err
}
var result ListLicensesResponse
err = c.decodeJSON(resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}
func (c *Client) ListLicenseAllocationsWithContext(ctx context.Context, o ListLicenseAllocationsOptions) (*ListLicenseAllocationsResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get(ctx, "/license_allocations?"+v.Encode(), nil)
if err != nil {
return nil, err
}
var result ListLicenseAllocationsResponse
err = c.decodeJSON(resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}