forked from segmentio/gads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_definition.go
74 lines (66 loc) · 1.97 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gads
import (
"encoding/xml"
)
type ReportDefinition struct {
Selector Selector `xml:"selector"`
ReportName string `xml:"reportName"`
ReportType string `xml:"reportType"`
DateRangeType string `xml:"dateRangeType"`
DownloadFormat string `xml:"downloadFormat"`
}
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 bool `xml:"canSelect"`
CanFilter bool `xml:"canFilter"`
IsEnumType bool `xml:"isEnumType"`
IsBeta bool `xml:"isBeta"`
IsZeroRowCompatible bool `xml:"isZeroRowCompatible"`
EnumValuePairs []EnumValuePair `xml:"enumValuePairs"`
}
type EnumValuePair struct {
EnumValue string `xml:"enumValue"`
EnumDisplayValue string `xml:"enumDisplayvalue"`
}
type ReportDefinitionService struct {
Auth
}
type ReportDefinitionRequest struct {
ReportType string `xml:"reportType"`
}
func NewReportDefinitionService(auth *Auth) *ReportDefinitionService {
return &ReportDefinitionService{Auth: *auth}
}
func (s *ReportDefinitionService) GetReportFields(report string) (fields []ReportDefinitionField, err error) {
respBody, err := s.Auth.request(
reportDefinitionServiceUrl,
"get",
struct {
XMLName xml.Name
ReportType string `xml:"reportType"`
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "getReportFields",
},
ReportType: report,
},
nil,
)
if err != nil {
return fields, err
}
getResp := struct {
Fields []ReportDefinitionField `xml:"rval"`
}{}
err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return fields, err
}
return getResp.Fields, err
}