forked from emiddleton/gads
-
Notifications
You must be signed in to change notification settings - Fork 1
/
offline_conversion_feed.go
67 lines (59 loc) · 1.86 KB
/
offline_conversion_feed.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
package gads
import "encoding/xml"
type OfflineConversionService struct {
Auth
}
const (
uploadConversionAction = "ADD"
)
type OfflineConversionFeed struct {
GoogleClickId string `xml:"googleClickId"`
ConversionName string `xml:"conversionName"`
ConversionTime string `xml:"conversionTime,omitempty"`
ConversionCurrencyCode string `xml:"conversionCurrencyCode,omitempty"`
ExternalAttributionModel string `xml:"externalAttributionModel,omitempty"`
ConversionValue float64 `xml:"conversionValue,omitempty"`
ExternalAttributionCredit float64 `xml:"externalAttributionCredit,omitempty"`
}
type OfflineConversionOperations map[string][]OfflineConversionFeed
func NewOfflineConversionService(auth *Auth) *OfflineConversionService {
return &OfflineConversionService{Auth: *auth}
}
func (o *OfflineConversionService) Mutate(conversionOperations OfflineConversionOperations) (conversion []OfflineConversionFeed, error error) {
type conversionOperation struct {
Action string `xml:"operator"`
Conversion OfflineConversionFeed `xml:"operand"`
}
var ops []conversionOperation
for _, conversion := range conversionOperations {
for _, con := range conversion {
ops = append(ops,
conversionOperation{
Action: uploadConversionAction,
Conversion: con,
},
)
}
}
mutation := struct {
XMLName xml.Name
Ops []conversionOperation `xml:"operations"`
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "mutate",
},
Ops: ops}
respBody, err := o.Auth.request(offlineConversionFeedServiceUrl, "mutate", mutation)
if err != nil {
return conversion, err
}
mutateResp := struct {
Conversions []OfflineConversionFeed `xml:"rval>value"`
}{}
err = xml.Unmarshal([]byte(respBody), &mutateResp)
if err != nil {
return conversion, err
}
return mutateResp.Conversions, nil
}