forked from emiddleton/gads
/
report_definition.go
58 lines (53 loc) · 1.54 KB
/
report_definition.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
package gads
import (
"encoding/xml"
)
type ReportDefinitionField struct {
FieldName string `xml:"fieldName"`
DisplayFieldName string `xml:"displayFieldName"`
XmlAttributeName string `xml:"xmlAttributeName"`
FieldType string `xml:"fieldType"`
FieldBehavior string `xml:"fieldBehavior"`
EnumValues string `xml:"enumValues"`
CanSelect string `xml:"canSelect"`
CanFilter string `xml:"canFilter"`
IsEnumType string `xml:"isEnumType"`
IsBeta string `xml:"isBeta"`
IsZeroRowCompatible string `xml:"isZeroRowCompatible"`
EnumValuePairs string `xml:"enumValuePairs"`
}
type ReportDefinitionService struct {
Auth
}
func NewReportDefinitionService(auth *Auth) *ReportDefinitionService {
return &ReportDefinitionService{Auth: *auth}
}
func (s *ReportDefinitionService) Get(selector Selector) (reports []ReportDefinitionField, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := s.Auth.request(
reportDefinitionServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "get",
},
Sel: selector,
},
)
if err != nil {
return reports, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Reports []ReportDefinitionField `xml:"rval>entries"`
}{}
err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return reports, totalCount, err
}
return getResp.Reports, getResp.Size, err
}