-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
65 lines (55 loc) · 1.79 KB
/
client.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
package ip_address
import (
"context"
files_sdk "github.com/Files-com/files-sdk-go/v2"
lib "github.com/Files-com/files-sdk-go/v2/lib"
listquery "github.com/Files-com/files-sdk-go/v2/listquery"
)
type Client struct {
files_sdk.Config
}
type Iter struct {
*lib.Iter
}
func (i *Iter) IpAddress() files_sdk.IpAddress {
return i.Current().(files_sdk.IpAddress)
}
func (c *Client) List(ctx context.Context, params files_sdk.IpAddressListParams) (*Iter, error) {
i := &Iter{Iter: &lib.Iter{}}
params.ListParams.Set(params.Page, params.PerPage, params.Cursor, params.MaxPages)
path := "/ip_addresses"
i.ListParams = ¶ms
list := files_sdk.IpAddressCollection{}
i.Query = listquery.Build(ctx, i, c.Config, path, &list)
return i, nil
}
func List(ctx context.Context, params files_sdk.IpAddressListParams) (*Iter, error) {
return (&Client{}).List(ctx, params)
}
func (c *Client) GetReserved(ctx context.Context, params files_sdk.IpAddressGetReservedParams) (files_sdk.PublicIpAddressCollection, error) {
publicIpAddressCollection := files_sdk.PublicIpAddressCollection{}
path := "/ip_addresses/reserved"
exportedParams, err := lib.ExportParams(params)
if err != nil {
return publicIpAddressCollection, err
}
data, res, err := files_sdk.Call(ctx, "GET", c.Config, path, exportedParams)
defer func() {
if res != nil {
res.Body.Close()
}
}()
if err != nil {
return publicIpAddressCollection, err
}
if res.StatusCode == 204 {
return publicIpAddressCollection, nil
}
if err := publicIpAddressCollection.UnmarshalJSON(*data); err != nil {
return publicIpAddressCollection, err
}
return publicIpAddressCollection, nil
}
func GetReserved(ctx context.Context, params files_sdk.IpAddressGetReservedParams) (files_sdk.PublicIpAddressCollection, error) {
return (&Client{}).GetReserved(ctx, params)
}