Skip to content

Commit

Permalink
add options to builder
Browse files Browse the repository at this point in the history
  • Loading branch information
jaddek committed Sep 19, 2024
1 parent c525e30 commit 20e9846
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/HeadersBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {HeadersDictInterface} from "./Contracts";

export class HeadersBuilder {
private readonly API_KEYWORD: string = "x-api-key";
private headers: HeadersDictInterface = {};

public newHeaders() {
Expand All @@ -15,7 +16,7 @@ export class HeadersBuilder {
return this;
}

public addToken(token: string, key: string = "x-api-key") {
public addToken(token: string, key: string = this.API_KEYWORD) {
this.headers[key] = token;

return this;
Expand Down
20 changes: 13 additions & 7 deletions src/MetlinkHttpClientBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@ import axios from "axios";
import {ResponseDataDecorator} from "./ResponseDataDecorator";

export class MetlinkHttpClientBuilder {
public static buildWithAxios(token: string): MetlinkHttpClient {

public static buildWithAxios(token: string, options: object = {}): MetlinkHttpClient {
const [host, headers]: [HostInterface, HeadersDictInterface] = HeadersDirector.build(token);
const axiosInstance = axios.create({
const config = {
baseURL: host.getUrl(),
headers: headers
});
};

const axiosInstance = axios.create({...options, ...config});

return new MetlinkHttpClient(new AxiosAdapter(axiosInstance));
}

public static buildWithAxiosAndDecorate(token: string): ResponseDataDecorator {
public static buildWithAxiosAndDecorate(token: string, options: object = {}): ResponseDataDecorator {

const [host, headers]: [HostInterface, HeadersDictInterface] = HeadersDirector.build(token);
const axiosInstance = axios.create({
const config = {
baseURL: host.getUrl(),
headers: headers
});
};

const axiosInstance = axios.create({...options, ...config});

return new ResponseDataDecorator(new MetlinkHttpClient(new AxiosAdapter(axiosInstance)));
}
}
}

0 comments on commit 20e9846

Please sign in to comment.