fix: added dependencies for development. feat: added axios as dependency. feat: added some initial modeals. feat: setup unit testing
This commit is contained in:
+22
-6
@@ -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",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class App {
|
||||
href: string;
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
@@ -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:';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export class PagingRequest {
|
||||
pageNumber: number;
|
||||
pageSize: number;
|
||||
|
||||
constructor(pageNumber: number, pageSize: number) {
|
||||
this.pageNumber = pageNumber;
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user