forked from Invoiced/invoiced-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
56 lines (41 loc) · 1.55 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
package creditbalanceadjustment
import (
"strconv"
"github.com/strongdm/invoiced-go/v2"
)
type Client struct {
*invoiced.Api
}
func (c *Client) Create(request *invoiced.CreditBalanceAdjustmentRequest) (*invoiced.CreditBalanceAdjustment, error) {
resp := new(invoiced.CreditBalanceAdjustment)
err := c.Api.Create("/credit_balance_adjustments", request, resp)
return resp, err
}
func (c *Client) Retrieve(id int64) (*invoiced.CreditBalanceAdjustment, error) {
resp := new(invoiced.CreditBalanceAdjustment)
_, err := c.Api.Get("/credit_balance_adjustments/"+strconv.FormatInt(id, 10), resp)
return resp, err
}
func (c *Client) Update(id int64, request *invoiced.CreditBalanceAdjustmentRequest) (*invoiced.CreditBalanceAdjustment, error) {
resp := new(invoiced.CreditBalanceAdjustment)
err := c.Api.Update("/credit_balance_adjustments/"+strconv.FormatInt(id, 10), request, resp)
return resp, err
}
func (c *Client) Delete(id int64) error {
return c.Api.Delete("/credit_balance_adjustments/" + strconv.FormatInt(id, 10))
}
func (c *Client) ListAll(filter *invoiced.Filter, sort *invoiced.Sort) (invoiced.CreditBalanceAdjustments, error) {
endpoint := invoiced.AddFilterAndSort("/credit_balance_adjustments", filter, sort)
adjustments := make(invoiced.CreditBalanceAdjustments, 0)
NEXT:
tmpAdjustments := make(invoiced.CreditBalanceAdjustments, 0)
endpointTmp, err := c.Api.Get(endpoint, &tmpAdjustments)
if err != nil {
return nil, err
}
adjustments = append(adjustments, tmpAdjustments...)
if endpointTmp != "" {
goto NEXT
}
return adjustments, nil
}