forked from emiddleton/gads
-
Notifications
You must be signed in to change notification settings - Fork 1
/
managed_customer.go
59 lines (52 loc) · 1.46 KB
/
managed_customer.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
package gads
import (
"encoding/xml"
)
type ManagedCustomerService struct {
Auth
}
func NewManagedCustomerService(auth *Auth) *ManagedCustomerService {
return &ManagedCustomerService{Auth: *auth}
}
type AccountLabel struct {
Id string `xml:"id"`
Name string `xml:"name"`
}
type Account struct {
Name string `xml:"name,omitempty"`
CanManageClients bool `xml:"canManageClients,omitempty"`
ExcludeHiddenAccounts bool `xml:"excludeHiddenAccounts,omitempty"`
CustomerId string `xml:"customerId,omitempty"`
DateTimeZone string `xml:"dateTimeZone,omitempty"`
CurrencyCode string `xml:"currencyCode,omitempty"`
AccountLabels []AccountLabel `xml:"accountLabels,omitempty"`
}
func (m *ManagedCustomerService) Get(selector Selector) (accounts []Account, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := m.Auth.request(
managedCustomerServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: mcmUrl,
Local: "get",
},
Sel: selector,
},
)
if err != nil {
return accounts, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Accounts []Account `xml:"rval>entries"`
}{}
err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return accounts, totalCount, err
}
return getResp.Accounts, getResp.Size, err
}