forked from Invoiced/invoiced-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
53 lines (40 loc) · 1.18 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
package taxrate
import (
"github.com/strongdm/invoiced-go/v2"
)
type Client struct {
*invoiced.Api
}
func (c *Client) Create(request *invoiced.TaxRateRequest) (*invoiced.TaxRate, error) {
resp := new(invoiced.TaxRate)
err := c.Api.Create("/tax_rates", request, resp)
return resp, err
}
func (c *Client) Retrieve(id string) (*invoiced.TaxRate, error) {
resp := new(invoiced.TaxRate)
_, err := c.Api.Get("/tax_rates/"+id, resp)
return resp, err
}
func (c *Client) Update(id string, request *invoiced.TaxRateRequest) (*invoiced.TaxRate, error) {
resp := new(invoiced.TaxRate)
err := c.Api.Update("/tax_rates/"+id, request, resp)
return resp, err
}
func (c *Client) Delete(id string) error {
return c.Api.Delete("/tax_rates/" + id)
}
func (c *Client) ListAll(filter *invoiced.Filter, sort *invoiced.Sort) (invoiced.TaxRates, error) {
endpoint := invoiced.AddFilterAndSort("/tax_rates", filter, sort)
taxRates := make(invoiced.TaxRates, 0)
NEXT:
tmpTaxRates := make(invoiced.TaxRates, 0)
endpointTmp, err := c.Api.Get(endpoint, &tmpTaxRates)
if err != nil {
return nil, err
}
taxRates = append(taxRates, tmpTaxRates...)
if endpointTmp != "" {
goto NEXT
}
return taxRates, nil
}