2023-01-25 22:28:45 -06:00
|
|
|
import { AxiosInstance } from "axios";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import { ArgumentValidator } from "./models/ArgumentValidator";
|
2023-01-25 17:08:19 -06:00
|
|
|
|
2023-01-25 22:28:45 -06:00
|
|
|
export class OnspringClient {
|
|
|
|
|
protected readonly client: AxiosInstance;
|
|
|
|
|
|
|
|
|
|
constructor(baseUrl: string | undefined | null, apiKey: string | undefined | null) {
|
|
|
|
|
if (ArgumentValidator.isValidUrl(baseUrl) === false) {
|
|
|
|
|
throw new Error("baseUrl must be an absolute and well-formed URI.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ArgumentValidator.isNullOrWhiteSpace(apiKey)) {
|
|
|
|
|
throw new Error("apiKey cannot be null/empty/whitespace.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.client = axios.create({
|
|
|
|
|
baseURL: baseUrl,
|
|
|
|
|
headers: {
|
|
|
|
|
"x-apikey": apiKey,
|
|
|
|
|
"x-api-version": "2",
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-01-25 17:08:19 -06:00
|
|
|
}
|
|
|
|
|
}
|