forked from segmentio/gads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshallow_campaign.go
47 lines (42 loc) · 1016 Bytes
/
shallow_campaign.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 ShallowCampaignService struct {
Auth
}
func NewShallowCampaignService(auth *Auth) *ShallowCampaignService {
return &ShallowCampaignService{Auth: *auth}
}
type ShallowCampaign struct {
Id int64 `xml:"id"`
Name string `xml:"name"`
}
func (s *ShallowCampaignService) Get(selector Selector) (campaigns []ShallowCampaign, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := s.Auth.request(
campaignServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "get",
},
Sel: selector,
},
nil,
)
if err != nil {
return campaigns, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Campaigns []ShallowCampaign `xml:"rval>entries"`
}{}
err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return campaigns, totalCount, err
}
return getResp.Campaigns, getResp.Size, err
}