@htdangkhoa/google-ads
Version:
Google Ads API client for Node.js
43 lines (42 loc) • 2.05 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { ServiceProvider } from './ServiceProvider.js';
import { getCredentials } from './utils.js';
import { LoggingInterceptor } from './LoggingInterceptor.js';
import { HOST, VERSION } from './constants.js';
import { google } from './generated/index.js';
export class Service extends ServiceProvider {
constructor(options) {
super();
this.cachedClients = {};
this.options = options;
}
get callMetadata() {
throw new Error('Not implemented');
}
loadService(serviceName) {
if (this.cachedClients[serviceName])
return this.cachedClients[serviceName];
const ProtoService = google.ads.googleads[VERSION].services[serviceName];
if (!ProtoService) {
throw new Error(`Service ${serviceName} not found.`);
}
const _a = this.options, { auth, developer_token, logging, interceptors = [], callInvocationTransformer } = _a, opts = __rest(_a, ["auth", "developer_token", "logging", "interceptors", "callInvocationTransformer"]);
const credentials = getCredentials(auth);
const logger = new LoggingInterceptor(logging || false);
const client = new ProtoService(HOST, credentials, Object.assign(Object.assign({}, opts), { interceptors: [logger.interceptCall.bind(logger), ...interceptors], callInvocationTransformer: (properties) => {
return logger.callInvocationTransformer(properties, callInvocationTransformer);
} }));
this.cachedClients[serviceName] = client;
return client;
}
}