forked from segmentio/gads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension_setting.go
121 lines (105 loc) · 5.66 KB
/
extension_setting.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package gads
import (
"encoding/xml"
"fmt"
)
// https://developers.google.com/adwords/api/docs/reference/v201809/AdGroupExtensionSettingService.ExtensionSetting
// A setting specifying when and which extensions should serve at a given level (customer, campaign, or ad group).
type ExtensionSetting struct {
PlatformRestrictions ExtensionSettingPlatform `xml:"platformRestrictions,omitempty"`
Extensions Extension `xml:"https://adwords.google.com/api/adwords/cm/v201809 extensions,omitempty"`
}
// https://developers.google.com/adwords/api/docs/reference/v201809/AdGroupExtensionSettingService.ExtensionSetting.Platform
// Different levels of platform restrictions
// DESKTOP, MOBILE, NONE
type ExtensionSettingPlatform string
type Extension interface{}
// https://developers.google.com/adwords/api/docs/reference/v201809/AdGroupExtensionSettingService.ExtensionFeedItem
// Contains base extension feed item data for an extension in an extension feed managed by AdWords.
type ExtensionFeedItem struct {
XMLName xml.Name `json:"-" xml:"extensions"`
FeedId int64 `xml:"https://adwords.google.com/api/adwords/cm/v201809 feedId,omitempty"`
FeedItemId int64 `xml:"https://adwords.google.com/api/adwords/cm/v201809 feedItemId,omitempty"`
Status *FeedItemStatus `xml:"https://adwords.google.com/api/adwords/cm/v201809 status,omitempty"`
FeedType *FeedType `xml:"https://adwords.google.com/api/adwords/cm/v201809 feedType,omitempty"`
StartTime string `xml:"https://adwords.google.com/api/adwords/cm/v201809 startTime,omitempty"` // special value "00000101 000000" may be used to clear an existing start time.
EndTime string `xml:"https://adwords.google.com/api/adwords/cm/v201809 endTime,omitempty"` // special value "00000101 000000" may be used to clear an existing end time.
DevicePreference *FeedItemDevicePreference `xml:"https://adwords.google.com/api/adwords/cm/v201809 devicePreference,omitempty"`
Scheduling *FeedItemScheduling `xml:"https://adwords.google.com/api/adwords/cm/v201809 scheduling,omitempty"`
CampaignTargeting *FeedItemCampaignTargeting `xml:"https://adwords.google.com/api/adwords/cm/v201809 campaignTargeting,omitempty"`
AdGroupTargeting *FeedItemAdGroupTargeting `xml:"https://adwords.google.com/api/adwords/cm/v201809 adGroupTargeting,omitempty"`
KeywordTargeting *Keyword `xml:"https://adwords.google.com/api/adwords/cm/v201809 keywordTargeting,omitempty"`
GeoTargeting *Location `xml:"https://adwords.google.com/api/adwords/cm/v201809 geoTargeting,omitempty"`
GeoTargetingRestriction *FeedItemGeoRestriction `xml:"https://adwords.google.com/api/adwords/cm/v201809 geoTargetingRestriction,omitempty"`
ExtensionFeedItemType string `xml:"https://adwords.google.com/api/adwords/cm/v201809 ExtensionFeedItem.Type,omitempty"`
}
// https://developers.google.com/adwords/api/docs/reference/v201809/AdGroupExtensionSettingService.CallFeedItem
// Represents a Call extension.
type CallFeedItem struct {
ExtensionFeedItem
CallPhoneNumber string `xml:"https://adwords.google.com/api/adwords/cm/v201809 callPhoneNumber,omitempty"`
CallCountryCode string `xml:"https://adwords.google.com/api/adwords/cm/v201809 callCountryCode,omitempty"`
CallTracking bool `xml:"https://adwords.google.com/api/adwords/cm/v201809 callTracking,omitempty"`
CallConversionType CallConversionType `xml:"https://adwords.google.com/api/adwords/cm/v201809 callConversionType,omitempty"`
DisableCallConversionTracking bool `xml:"https://adwords.google.com/api/adwords/cm/v201809 disableCallConversionTracking,omitempty"`
}
func extensionsUnmarshalXML(dec *xml.Decoder, start xml.StartElement) (ext interface{}, err error) {
extensionsType, err := findAttr(start.Attr, xml.Name{Space: "http://www.w3.org/2001/XMLSchema-instance", Local: "type"})
if err != nil {
return
}
switch extensionsType {
case "CallFeedItem":
c := CallFeedItem{}
err = dec.DecodeElement(&c, &start)
ext = c
default:
err = fmt.Errorf("unknown Extensions type %#v", extensionsType)
}
return
}
func (s ExtensionSetting) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
e.EncodeToken(start)
if s.PlatformRestrictions != "NONE" {
e.EncodeElement(&s.PlatformRestrictions, xml.StartElement{Name: xml.Name{
"https://adwords.google.com/api/adwords/cm/v201809",
"platformRestrictions"}})
}
switch extType := s.Extensions.(type) {
case []CallFeedItem:
e.EncodeElement(s.Extensions.([]CallFeedItem), xml.StartElement{
xml.Name{baseUrl, "extensions"},
[]xml.Attr{
xml.Attr{xml.Name{"http://www.w3.org/2001/XMLSchema-instance", "type"}, "CallFeedItem"},
},
})
default:
return fmt.Errorf("unknown extension type %#v\n", extType)
}
e.EncodeToken(start.End())
return nil
}
func (s *ExtensionSetting) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) (err error) {
s.Extensions = []interface{}{}
for token, err := dec.Token(); err == nil; token, err = dec.Token() {
if err != nil {
return err
}
switch start := token.(type) {
case xml.StartElement:
switch start.Name.Local {
case "platformRestrictions":
if err := dec.DecodeElement(&s.PlatformRestrictions, &start); err != nil {
return err
}
case "extensions":
extension, err := extensionsUnmarshalXML(dec, start)
if err != nil {
return err
}
s.Extensions = append(s.Extensions.([]interface{}), extension)
}
}
}
return nil
}