@eclipse-ditto/ditto-javascript-client-node
Version:
Node.js(r) implementation of Eclipse Ditto JavaScript API.
79 lines • 2.96 kB
JavaScript
"use strict";
/*!
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpClientBuilder = void 0;
const http_request_sender_1 = require("./request-factory/http-request-sender");
const ditto_client_http_1 = require("./ditto-client-http");
const auth_provider_1 = require("../auth/auth-provider");
const builder_steps_1 = require("./builder-steps");
/**
* Implementation of all the methods to build a Context.
*/
class HttpClientBuilder extends builder_steps_1.AbstractBuilder {
constructor(requester) {
super();
this.requester = requester;
this.customHandles = {};
}
/**
* Build a new HttpClientBuilder.
*
* @param requester - The requester to use.
*/
static newBuilder(requester) {
return new HttpClientBuilder(requester);
}
finalize() {
return this;
}
// TODO: rebuild so that DittoHttpClient interface can be used
build() {
const url = this.buildUrl();
return ditto_client_http_1.DefaultDittoHttpClient.getInstance(new http_request_sender_1.HttpRequestSenderBuilder(this.requester, url, this.authProviders), this.customHandles);
}
buildClient(tls, domain, apiVersion, authProviders) {
this.tls = tls;
this.domain = domain;
this.apiVersion = apiVersion;
this.authProviders = authProviders;
return this.build();
}
buildUrl() {
const protocol = this.tls ? 'https' : 'http';
const path = (this.customPath === undefined) ? '/api' : this.customPath;
return auth_provider_1.ImmutableURL.newInstance(protocol, this.domain, `${path}/${this.apiVersion}`);
}
withCustomThingsHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { thingsHandle: factory });
return this;
}
withCustomFeaturesHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { featuresHandle: factory });
return this;
}
withCustomMessagesHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { messagesHandle: factory });
return this;
}
withCustomPoliciesHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { policiesHandle: factory });
return this;
}
withCustomSearchHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { searchHandle: factory });
return this;
}
}
exports.HttpClientBuilder = HttpClientBuilder;
//# sourceMappingURL=http-client-builder.js.map