forked from segmentio/gads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshallow_ad_group_ad.go
47 lines (42 loc) · 1.01 KB
/
shallow_ad_group_ad.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
package gads
import "encoding/xml"
type ShallowAdGroupAdService struct {
Auth
}
func NewShallowAdGroupAdService(auth *Auth) *ShallowAdGroupAdService {
return &ShallowAdGroupAdService{Auth: *auth}
}
type ShallowAdGroupAd struct {
Id int64 `xml:"id"`
Name string `xml:"name"`
}
func (s *ShallowAdGroupAdService) Get(selector Selector) (adGroupAds []ShallowAdGroupAd, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := s.Auth.request(
adGroupAdServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "get",
},
Sel: selector,
},
nil,
)
if err != nil {
return adGroupAds, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
AdGroupAds []ShallowAdGroupAd `xml:"rval>entries"`
}{}
err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return adGroupAds, totalCount, err
}
return getResp.AdGroupAds, getResp.Size, err
}