fix: added dependencies for development. feat: added axios as dependency. feat: added some initial modeals. feat: setup unit testing

This commit is contained in:
StevanFreeborn
2023-01-25 22:28:45 -06:00
parent 5cec90600a
commit dc90ac9a9d
9 changed files with 2552 additions and 8 deletions
+22 -6
View File
@@ -1,9 +1,25 @@
class OnspringClient {
private readonly _baseUrl: string;
private readonly _apiKey: string;
import { AxiosInstance } from "axios";
import axios from "axios";
import { ArgumentValidator } from "./models/ArgumentValidator";
constructor(baseUrl: string, apiKey: string) {
this._baseUrl = baseUrl;
this._apiKey = apiKey;
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",
},
});
}
}
+13
View File
@@ -0,0 +1,13 @@
export class ApiResponse<T> {
readonly statusCode: number;
readonly isSuccessful: boolean;
readonly message: string;
readonly data: T;
constructor(statusCode: number, isSuccessful: boolean, message: string, data: T) {
this.statusCode = statusCode;
this.isSuccessful = statusCode < 400;
this.message = message;
this.data = data;
}
}
+5
View File
@@ -0,0 +1,5 @@
class App {
href: string;
id: number;
name: string;
}
+17
View File
@@ -0,0 +1,17 @@
export class ArgumentValidator {
public static isNullOrWhiteSpace(value: string | null | undefined): boolean {
return value === null || value === undefined || (/^\s*$/).test(value);
}
public static isValidUrl(value: string | null | undefined): boolean {
let url: URL;
try {
url = new URL(value);
} catch (error) {
return false;
}
return url.protocol === 'http:' || url.protocol === 'https:';
}
}
+9
View File
@@ -0,0 +1,9 @@
export class PagingRequest {
pageNumber: number;
pageSize: number;
constructor(pageNumber: number, pageSize: number) {
this.pageNumber = pageNumber;
this.pageSize = pageSize;
}
}