-
Notifications
You must be signed in to change notification settings - Fork 1
/
support_branch.go
83 lines (72 loc) · 2.24 KB
/
support_branch.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
package topdesk
// Supporting files.
//
// https://developers.topdesk.com/explorer/?page=supporting-files
import (
"context"
"path"
)
type BranchIterator struct {
*ListIterator
}
func (i BranchIterator) Branch() (*Branch, error) {
response := &Ref{}
if err := i.decode(&response); err != nil {
return nil, err // Wrap this bad boy.
}
return i.client.GetBranch(i.ctx, response.ID)
}
// Branch structure.
//
// https://developers.topdesk.com/explorer/?page=supporting-files#/Branches/retrieveBranches
type Branch struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Specification string `json:"specification"`
ClientReferenceNumber string `json:"clientReferenceNumber"`
Phone string `json:"phone"`
Fax string `json:"fax"`
Email string `json:"email"`
Website string `json:"website"`
BranchType string `json:"branchType"`
HeadBranch *Ref `json:"headBranch"`
Address struct {
Country struct {
ID string `json:"id"`
} `json:"country"`
Street string `json:"street"`
Number string `json:"number"`
County string `json:"county"`
City string `json:"city"`
Postcode string `json:"postcode"`
AddressMemo string `json:"addressMemo"`
} `json:"address"`
PostalAddress struct {
Country struct {
ID string `json:"id"`
} `json:"country"`
Street string `json:"street"`
Number string `json:"number"`
County string `json:"county"`
City string `json:"city"`
Postcode string `json:"postcode"`
AddressMemo string `json:"addressMemo"`
} `json:"postalAddress"`
}
func (b Branch) Ref() *Ref {
return &Ref{ID: b.ID}
}
type ListBranchesRequest struct{}
func (rc RestClient) ListBranches(ctx context.Context, request *ListBranchesRequest) (*BranchIterator, error) {
uri := *rc.endpoint
uri.Path = path.Join(uri.Path, "branches")
it, err := rc.list(ctx, &uri)
return &BranchIterator{it}, err
}
func (rc RestClient) GetBranch(ctx context.Context, id string) (*Branch, error) {
uri := *rc.endpoint
uri.Path = path.Join(uri.Path, "branches", "id", id)
response := &Branch{}
err := rc.get(ctx, &uri, response)
return response, err
}