-
Notifications
You must be signed in to change notification settings - Fork 1
/
organizations_products.go
61 lines (50 loc) · 1.77 KB
/
organizations_products.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
package gocancel
import (
"context"
"fmt"
)
type OrganizationProductsSortOptions struct {
CreatedAt string `url:"created_at,omitempty"`
UpdatedAt string `url:"updated_at,omitempty"`
}
type OrganizationProductsListOptions struct {
Cursor string `url:"cursor,omitempty"`
Limit int `url:"limit,omitempty"`
Locales []string `url:"locales[],omitempty"`
Metadata map[string]string `url:"metadata,omitempty"`
Slug string `url:"slug,omitempty"`
Sort OrganizationProductsSortOptions `url:"sort,omitempty"`
URL string `url:"url,omitempty"`
}
// List lists all products of an organization
func (s *OrganizationsService) ListProducts(ctx context.Context, organization string, opts *OrganizationProductsListOptions) ([]*Product, *Response, error) {
u, err := addOptions(fmt.Sprintf("api/v1/organizations/%s/products", organization), opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
root := new(productsRoot)
resp, err := s.client.Do(ctx, req, &root)
if err != nil {
return nil, resp, err
}
resp.Metadata = root.Metadata
return root.Products, resp, nil
}
// Get fetches a product of an organization.
func (s *OrganizationsService) GetProduct(ctx context.Context, organization string, product string) (*Product, *Response, error) {
u := fmt.Sprintf("api/v1/organizations/%s/products/%s", organization, product)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
root := new(productRoot)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Product, resp, nil
}