-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstores.go
88 lines (79 loc) · 2.86 KB
/
stores.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
85
86
87
88
package btcpay
import (
"context"
"fmt"
)
// View information about the available stores
func (c *Client) GetStores(ctx context.Context) ([]*StoreResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/stores", c.URL)
var dataRes []*StoreResponse
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil)
if err != nil {
return nil, statusCode, err
}
return dataRes, statusCode, nil
}
// create a new store
func (c *Client) CreateStore(ctx context.Context, storeRequest *StoreRequest) (*StoreResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/stores", c.URL)
var dataRes StoreResponse
statusCode, err := c.doRequest(ctx, endpoint, "POST", &dataRes, storeRequest)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}
// View information about the specified store
func (c *Client) GetStore(ctx context.Context, storeID *StoreID) (*StoreResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/stores/%s", c.URL, *storeID)
var dataRes StoreResponse
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}
func (s *Store) GetStore(ctx context.Context) (*StoreResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/stores/%s", s.Client.URL, s.ID)
var dataRes StoreResponse
statusCode, err := s.Client.doRequest(ctx, endpoint, "GET", &dataRes, nil)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}
func (c *Client) UpdateStore(ctx context.Context, storeID *StoreID, storeUpdate *StoreUpdate) (*StoreResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/stores/%s", c.URL, *storeID)
var dataRes StoreResponse
statusCode, err := c.doRequest(ctx, endpoint, "PUT", &dataRes, storeUpdate)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}
func (s *Store) UpdateStore(ctx context.Context, storeUpdate *StoreUpdate) (*StoreResponse, int, error) {
endpoint := fmt.Sprintf("%s/api/v1/stores/%s", s.Client.URL, s.ID)
var dataRes StoreResponse
statusCode, err := s.Client.doRequest(ctx, endpoint, "PUT", &dataRes, storeUpdate)
if err != nil {
return nil, statusCode, err
}
return &dataRes, statusCode, nil
}
// Removes the specified store. If there is another user with access, only your access will be removed.
func (c *Client) RemoveStore(ctx context.Context, storeID *StoreID) (int, error) {
endpoint := fmt.Sprintf("%s/api/v1/stores/%s", c.URL, *storeID)
statusCode, err := c.doRequest(ctx, endpoint, "DELETE", nil, nil)
if err != nil {
return statusCode, err
}
return statusCode, nil
}
func (s *Store) RemoveStore(ctx context.Context) (int, error) {
endpoint := fmt.Sprintf("%s/api/v1/stores/%s", s.Client.URL, s.ID)
statusCode, err := s.Client.doRequest(ctx, endpoint, "DELETE", nil, nil)
if err != nil {
return statusCode, err
}
return statusCode, nil
}