in lib/client/googleSoap.service.ts [23:68]
public async createClient(
logRequests = false,
logResponses = false,
): Promise<ImportClass<typeof SERVICE_MAP, T>> {
const serviceUrl = `https://ads.google.com/apis/ads/publisher/${this.apiVersion}/${this.service}?wsdl`;
const client = await createClientAsync(serviceUrl);
client.addSoapHeader(this.getSoapHeaders());
client.setToken = function setToken(token: string) {
client.setSecurity(new BearerSecurity(token));
};
if (this.token) client.setToken(this.token);
if (logRequests) {
client.addListener("request", (req: unknown) => {
console.info("SOAP Request:", req);
});
}
if (logResponses) {
client.addListener("response", (res: unknown) => {
console.info("SOAP Response:", res);
});
}
this._client = new Proxy(client, {
get: function get(target, propertyKey) {
const method = propertyKey.toString();
if (target.hasOwnProperty(method) && !["setToken"].includes(method)) {
return async function run(dto: any = {}) {
const res = await promiseFromCallback((cb) =>
client[method](dto, cb),
);
return res?.rval || null;
};
}
return target[method];
},
});
const services = SERVICE_MAP as any;
return new services[this.service](this._client);
}