This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
/
subscriptions.go
75 lines (60 loc) · 2.17 KB
/
subscriptions.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
package licensing
import (
"context"
"net/url"
"github.com/docker/licensing/lib/go-clientlib"
"github.com/docker/licensing/model"
)
// RequestParams holds request parameters
type RequestParams struct {
DockerID string
PartnerAccountID string
Origin string
}
func (c *client) createSubscription(ctx context.Context, request *model.SubscriptionCreationRequest) (*model.SubscriptionDetail, error) {
url := c.baseURI
url.Path += "/api/billing/v4/subscriptions"
response := new(model.SubscriptionDetail)
if _, _, err := c.doReq(ctx, "POST", &url, clientlib.SendJSON(request), clientlib.RecvJSON(response)); err != nil {
return nil, err
}
return response, nil
}
func (c *client) getSubscription(ctx context.Context, id string) (*model.SubscriptionDetail, error) {
url := c.baseURI
url.Path += "/api/billing/v4/subscriptions/" + id
response := new(model.SubscriptionDetail)
if _, _, err := c.doReq(ctx, "GET", &url, clientlib.RecvJSON(response)); err != nil {
return nil, err
}
return response, nil
}
func (c *client) listSubscriptions(ctx context.Context, params map[string]string) ([]*model.Subscription, error) {
values := url.Values{}
values.Set("docker_id", params["docker_id"])
values.Set("partner_account_id", params["partner_account_id"])
values.Set("origin", params["origin"])
values.Set("include_orgs", "true")
url := c.baseURI
url.Path += "/api/billing/v4/subscriptions"
url.RawQuery = values.Encode()
response := make([]*model.Subscription, 0)
if _, _, err := c.doReq(ctx, "GET", &url, clientlib.RecvJSON(&response)); err != nil {
return nil, err
}
return response, nil
}
func (c *client) listSubscriptionsDetails(ctx context.Context, params map[string]string) ([]*model.SubscriptionDetail, error) {
values := url.Values{}
values.Set("docker_id", params["docker_id"])
values.Set("partner_account_id", params["partner_account_id"])
values.Set("origin", params["origin"])
url := c.baseURI
url.Path += "/api/billing/v4/subscriptions"
url.RawQuery = values.Encode()
response := make([]*model.SubscriptionDetail, 0)
if _, _, err := c.doReq(ctx, "GET", &url, clientlib.RecvJSON(&response)); err != nil {
return nil, err
}
return response, nil
}