forked from rwestlund/quickbooks-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer_type.go
49 lines (40 loc) · 1.15 KB
/
customer_type.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
package quickbooks
import (
"errors"
)
type CustomerType struct {
SyncToken string `json:",omitempty"`
Domain string `json:"domain,omitempty"`
Name string `json:",omitempty"`
Active bool `json:",omitempty"`
Id string `json:",omitempty"`
MetaData MetaData `json:",omitempty"`
}
// FindCustomerTypeById returns a customerType with a given Id.
func (c *Client) FindCustomerTypeById(id string) (*CustomerType, error) {
var r struct {
CustomerType CustomerType
Time Date
}
if err := c.get("customertype/"+id, &r, nil); err != nil {
return nil, err
}
return &r.CustomerType, nil
}
// QueryCustomerTypes accepts an SQL query and returns all customerTypes found using it
func (c *Client) QueryCustomerTypes(query string) ([]CustomerType, error) {
var resp struct {
QueryResponse struct {
CustomerTypes []CustomerType `json:"CustomerType"`
StartPosition int
MaxResults int
}
}
if err := c.query(query, &resp); err != nil {
return nil, err
}
if resp.QueryResponse.CustomerTypes == nil {
return nil, errors.New("could not find any customerTypes")
}
return resp.QueryResponse.CustomerTypes, nil
}