Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement OfflineConversionUpload Mutate WSDL #13

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions ad_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package gads

import (
"encoding/xml"
)

type AdService struct {
Auth
}

func NewAdService(auth *Auth) *AdService {
return &AdService{Auth: *auth}
}

type AssetLink struct {
Asset Asset `xml:"asset"`
}

// Media represents an audio, image or video file.
type Ad struct {
Id int64 `xml:"id,omitempty"`
Url string `xml:"url,omitempty"`
DisplayUrl string `xml:"displayUrl,omitempty"`
FinalUrls []string `xml:"finalUrls,omitempty"`
FinalMobileUrls []string `xml:"finalMobileUrls,omitempty"`
FinalAppUrls []string `xml:"finalAppUrls,omitempty"`
TrackingUrlTemplate []string `xml:"trackingUrlTemplate,omitempty"`
FinalUrlSuffix []string `xml:"finalUrlSuffix,omitempty"`
Type string `xml:"http://www.w3.org/2001/XMLSchema-instance type,attr"`
AdType string `xml:"type"` // "DEPRECATED_AD", "IMAGE_AD", "PRODUCT_AD", "TEMPLATE_AD", "TEXT_AD", "THIRD_PARTY_REDIRECT_AD", "DYNAMIC_SEARCH_AD", "CALL_ONLY_AD",
// "EXPANDED_TEXT_AD", "RESPONSIVE_DISPLAY_AD", "SHOWCASE_AD", "GOAL_OPTIMIZED_SHOPPING_AD", "EXPANDED_DYNAMIC_SEARCH_AD", "GMAIL_AD",
// "RESPONSIVE_SEARCH_AD", "MULTI_ASSET_RESPONSIVE_DISPLAY_AD", "UNIVERSAL_APP_AD", "UNKNOWN"

// MultiAssetResponsiveDisplayAd
LogoImage []AssetLink `xml:"logoImages,omitempty"` // list asset link
}

func (s *AdService) Get(selector Selector) (ads []Ad, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := s.Auth.request(
adServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "get",
},
Sel: selector,
},
)
if err != nil {
return ads, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Ads []Ad `xml:"rval>entries"`
}{}
err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return ads, totalCount, err
}
return getResp.Ads, getResp.Size, err
}
99 changes: 99 additions & 0 deletions asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package gads

import (
"encoding/base64"
"encoding/xml"
)

type AssetService struct {
Auth
}

func NewAssetService(auth *Auth) *AssetService {
return &AssetService{Auth: *auth}
}

type ImageDimensionInfo struct {
Url string `xml:"imageUrl"` // "FULL", "SHRUNKEN", "PREVIEW", "VIDEO_THUMBNAIL"
Width float64 `xml:"imageHeight"`
Height float64 `xml:"imageWidth"`
}

// Media represents an audio, image or video file.
type Asset struct {
Id int64 `xml:"assetId,omitempty"`
Name string `xml:"assetName,omitempty"`
Type string `xml:"http://www.w3.org/2001/XMLSchema-instance type,attr"`
AssetType string `xml:"assetSubtype"` // "TEXT", "IMAGE", "YOUTUBE_VIDEO", "MEDIA_BUNDLE"
Status string `xml:"assetStatus,omitempty"`

// Media Bundle
MediaData string `xml:"mediaBundleData,omitempty"` // base64Binary encoded raw media bundle data

// Image
ImgData string `xml:"imageData,omitempty"` // base64Binary encoded raw image data
ImgSize float64 `xml:"imageFileSize,omitempty"`
MimeType string `xml:"imageMimeType,omitempty"` // "IMAGE_JPEG", "IMAGE_GIF", "IMAGE_PNG"
FullSizeInfo ImageDimensionInfo `xml:"fullSizeInfo,omitempty"`

// Youtube Video
YoutubeVideoId string `xml:"youTubeVideoId,omitempty"` // This is the 11 char string value used in the Youtube video URL
}

func NewMediaBundle(name, assetType string, data []byte) (image Asset) {
mediaData := base64.StdEncoding.EncodeToString(data)
return Asset{
Name: name,
Type: "media_bundle",
AssetType: assetType,
MediaData: mediaData,
}
}

func NewImageAsset(name, assetType, mimeType string, data []byte) (image Asset) {
imageData := base64.StdEncoding.EncodeToString(data)
return Asset{
Name: name,
Type: "Image",
AssetType: assetType,
ImgData: imageData,
MimeType: mimeType,
}
}

func NewVideoAsset(assetType string) (image Asset) {
return Asset{
Type: "Youtube_Video",
AssetType: assetType,
}
}

func (s *AssetService) Get(selector Selector) (assets []Asset, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "selector"}
respBody, err := s.Auth.request(
assetServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "get",
},
Sel: selector,
},
)
if err != nil {
return assets, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Assets []Asset `xml:"rval>entries"`
}{}
err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return assets, totalCount, err
}
return getResp.Assets, getResp.Size, err
}
33 changes: 14 additions & 19 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
)

const (
baseUrl = "https://adwords.google.com/api/adwords/cm/v201409"
baseUrl = "https://adwords.google.com/api/adwords/cm/v201809"
mcmUrl = "https://adwords.google.com/api/adwords/mcm/v201809"
reportUrl = "https://adwords.google.com/api/adwords/reportdownload/v201809"
)

type ServiceUrl struct {
Expand Down Expand Up @@ -56,15 +58,18 @@ var (
geoLocationServiceUrl = ServiceUrl{baseUrl, "GeoLocationService"}
labelServiceUrl = ServiceUrl{baseUrl, "LabelService"}
locationCriterionServiceUrl = ServiceUrl{baseUrl, "LocationCriterionService"}
managedCustomerServiceUrl = ServiceUrl{baseUrl, "ManagedCustomerService"}
managedCustomerServiceUrl = ServiceUrl{mcmUrl, "ManagedCustomerService"}
mediaServiceUrl = ServiceUrl{baseUrl, "MediaService"}
mutateJobServiceUrl = ServiceUrl{baseUrl, "Mutate_JOB_Service"}
offlineConversionFeedServiceUrl = ServiceUrl{baseUrl, "OfflineConversionFeedService"}
reportDefinitionServiceUrl = ServiceUrl{baseUrl, "ReportDefinitionService"}
reportDownloadServiceUrl = ServiceUrl{reportUrl, ""}
sharedCriterionServiceUrl = ServiceUrl{baseUrl, "SharedCriterionService"}
sharedSetServiceUrl = ServiceUrl{baseUrl, "SharedSetService"}
targetingIdeaServiceUrl = ServiceUrl{baseUrl, "TargetingIdeaService"}
trafficEstimatorServiceUrl = ServiceUrl{baseUrl, "TrafficEstimatorService"}
assetServiceUrl = ServiceUrl{baseUrl, "AssetService"}
adServiceUrl = ServiceUrl{baseUrl, "AdService"}
)

func (s ServiceUrl) String() string {
Expand Down Expand Up @@ -112,20 +117,12 @@ type Selector struct {
Paging *Paging `xml:"paging,omitempty"`
}

// error parsers
func selectorError() (err error) {
return err
}

func (a *Auth) request(serviceUrl ServiceUrl, action string, body interface{}) (respBody []byte, err error) {
type devToken struct {
XMLName xml.Name
}
type soapReqHeader struct {
XMLName xml.Name
UserAgent string `xml:"userAgent"`
DeveloperToken string `xml:"developerToken"`
ClientCustomerId string `xml:"clientCustomerId"`
ClientCustomerId string `xml:"clientCustomerId,omitempty"`
}

type soapReqBody struct {
Expand Down Expand Up @@ -160,7 +157,9 @@ func (a *Auth) request(serviceUrl ServiceUrl, action string, body interface{}) (
req.Header.Add("Content-Type", "text/xml;charset=UTF-8")
contentLength := fmt.Sprintf("%d", len(reqBody))
req.Header.Add("Content-length", contentLength)
req.Header.Add("SOAPAction", action)
if action != "" {
req.Header.Add("SOAPAction", action)
}
if a.Testing != nil {
a.Testing.Logf("request ->\n%s\n%#v\n%s\n", req.URL.String(), req.Header, string(reqBody))
}
Expand Down Expand Up @@ -197,13 +196,9 @@ func (a *Auth) request(serviceUrl ServiceUrl, action string, body interface{}) (
return respBody, err
}
if resp.StatusCode == 400 || resp.StatusCode == 401 || resp.StatusCode == 403 || resp.StatusCode == 405 || resp.StatusCode == 500 {
fault := Fault{}
fmt.Printf("unknown error ->\n%s\n", string(soapResp.Body.Response))
err = xml.Unmarshal(soapResp.Body.Response, &fault)
if err != nil {
return respBody, err
}
return soapResp.Body.Response, &fault.Errors
fault := new(Fault)
_ = xml.Unmarshal(soapResp.Body.Response, fault)
return soapResp.Body.Response, fault
}
return soapResp.Body.Response, err
}
2 changes: 1 addition & 1 deletion base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func rand_word(str_size int) string {
return string(bytes)
}

func testAuthSetup(t *testing.T) Auth {
func testAuthSetup(t *testing.T) *Auth {
config, err := NewCredentials(context.TODO())
if err != nil {
t.Fatal(err)
Expand Down
45 changes: 45 additions & 0 deletions conversion_tracker.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
package gads

import (
"encoding/xml"
)

type ConversionTrackerService struct {
Auth
}

func NewConversionTrackerService(auth *Auth) *ConversionTrackerService {
return &ConversionTrackerService{Auth: *auth}
}

type ConversionTracker struct {
Id int64 `xml:"id"`
OriginalConversionTypeId int64 `xml:"originalConversionTypeId"`
Name string `xml:"name"`
Status string `xml:"status"`
Category string `xml:"category"`
GoogleEventSnippet string `xml:"googleEventSnippet"`
GoogleGlobalSiteTag string `xml:"googleGlobalSiteTag"`
}

func (c *ConversionTrackerService) Get(selector Selector) (conversions []ConversionTracker, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := c.Auth.request(
conversionTrackerServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: baseUrl,
Local: "get",
},
Sel: selector,
},
)
if err != nil {
return conversions, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Conversions []ConversionTracker `xml:"rval>entries"`
}{}

err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return conversions, totalCount, err
}
return getResp.Conversions, getResp.Size, err
}
50 changes: 50 additions & 0 deletions managed_customer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
package gads

import (
"encoding/xml"
)

type ManagedCustomerService struct {
Auth
}

func NewManagedCustomerService(auth *Auth) *ManagedCustomerService {
return &ManagedCustomerService{Auth: *auth}
}

type AccountLabel struct {
Id string `xml:"id"`
Name string `xml:"name"`
}

type Account struct {
Name string `xml:"name,omitempty"`
CanManageClients bool `xml:"canManageClients,omitempty"`
ExcludeHiddenAccounts bool `xml:"excludeHiddenAccounts,omitempty"`
CustomerId string `xml:"customerId,omitempty"`
DateTimeZone string `xml:"dateTimeZone,omitempty"`
CurrencyCode string `xml:"currencyCode,omitempty"`
AccountLabels []AccountLabel `xml:"accountLabels,omitempty"`
}

func (m *ManagedCustomerService) Get(selector Selector) (accounts []Account, totalCount int64, err error) {
selector.XMLName = xml.Name{"", "serviceSelector"}
respBody, err := m.Auth.request(
managedCustomerServiceUrl,
"get",
struct {
XMLName xml.Name
Sel Selector
}{
XMLName: xml.Name{
Space: mcmUrl,
Local: "get",
},
Sel: selector,
},
)
if err != nil {
return accounts, totalCount, err
}
getResp := struct {
Size int64 `xml:"rval>totalNumEntries"`
Accounts []Account `xml:"rval>entries"`
}{}

err = xml.Unmarshal([]byte(respBody), &getResp)
if err != nil {
return accounts, totalCount, err
}
return getResp.Accounts, getResp.Size, err
}
Loading