UNPKG

adwords-api

Version:

Unofficial SDK for Google Adwords API

116 lines (100 loc) 2.8 kB
var _ = require('lodash'), async = require('async'), soap = require('soap'); var AdWordsService = require('./adWordsService'); var types = require('../types/managedCustomer'); var links = require('../types/managedCustomerLink'); function Service(options) { var self = this; var Selector = require('../types/selector').model; AdWordsService.call(self, options); self.Collection = types.collection; self.Model = types.model; self.ManagedCustomerLinkCollection = links.collection; self.ManagedCustomerLink = links.model; self.findByCustomerId = function(clientCustomerId, customerId, cb) { var selector = new Selector({ fields: ['CustomerId'], predicates: [ {field: 'CustomerId', operator: 'EQUALS', values: customerId} ] }); return self.get(clientCustomerId, selector, cb); }; self.mutateLinkSet = function(clientCustomerId, operand, done) { if (!operand.isValid()) return done(operand.validationError); var operation = {}; operation[self.operatorKey] = 'SET'; operation.operand = operand.toJSON(); var options = { clientCustomerId: clientCustomerId, mutateMethod: 'mutateLink', operations: [operation], parseMethod: self.parseMutateLinkResponse }; self.mutate(options, done); }; self.mutateRemove = null; self.parseGetResponse = function(response) { if (self.validateOnly) { return { entries: null, links: null, 'Page.Type': null, totalNumEntries: null }; } else if (response.rval) { return { entries: response.rval.entries || [], links: response.rval.links || [], 'Page.Type': response.rval['Page.Type'], totalNumEntries: response.rval.totalNumEntries }; } else { return {}; } }; self.parseMutateResponse = function(response) { if (self.validateOnly) { return { value: null }; } else if (response.rval) { return { value: response.rval.value || [] }; } else { return {}; } }; self.parseMutateLinkResponse = function(response) { if (self.validateOnly) { return { links: null }; } else if (response.rval) { return { links: response.rval.links || [] }; } else { return {}; } }; self.selectable = [ 'Name', 'CompanyName', 'CustomerId', 'CanManageClients', 'CurrencyCode', 'DateTimeZone', 'TestAccount', 'AccountLabels' ]; self.xmlns = 'https://adwords.google.com/api/adwords/mcm/' + self.version; self.wsdlUrl = self.xmlns + '/ManagedCustomerService?wsdl'; } Service.prototype = _.create(AdWordsService.prototype, { constructor: Service }); module.exports = Service;