From 033d02e32fa73730ef61a3a1b2d49bd7293a3253 Mon Sep 17 00:00:00 2001 From: Dmytro Krasun Date: Sun, 26 Nov 2023 21:51:14 +0200 Subject: [PATCH] Allow to replace the API base URL --- package.json | 2 +- src/main.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 15e0c04..7b9892c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "screenshotone-api-sdk", "homepage": "https://screenshotone.com", - "version": "1.1.6", + "version": "1.1.7", "description": "Use ScreenshotOne.com API to generate screenshots of any website.", "repository": { "type": "git", diff --git a/src/main.ts b/src/main.ts index b182ac3..ac0eb1d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,8 +12,9 @@ const API_ANIMATE_PATH = "/animate"; export class Client { private readonly accessKey: string; private readonly secretKey: string; + private readonly apiBaseUrl: string; - constructor(accessKey: string, secretKey: string) { + constructor(accessKey: string, secretKey: string, apiBaseUrl?: string) { if (!accessKey || !secretKey) { throw new Error( "Both non-empty access and secret keys are required" @@ -22,6 +23,7 @@ export class Client { this.accessKey = accessKey; this.secretKey = secretKey; + this.apiBaseUrl = apiBaseUrl ? apiBaseUrl : API_BASE_URL; } /** @@ -37,7 +39,7 @@ export class Client { query.append("access_key", this.accessKey); let queryString = query.toString(); - return `${API_BASE_URL}${API_TAKE_PATH}?${queryString}`; + return `${this.apiBaseUrl}${API_TAKE_PATH}?${queryString}`; } /** @@ -55,7 +57,7 @@ export class Client { const signature = await signQueryString(queryString, this.secretKey); queryString += "&signature=" + signature; - return `${API_BASE_URL}${API_TAKE_PATH}?${queryString}`; + return `${this.apiBaseUrl}${API_TAKE_PATH}?${queryString}`; } /** @@ -73,7 +75,7 @@ export class Client { const signature = await signQueryString(queryString, this.secretKey); queryString += "&signature=" + signature; - return `${API_BASE_URL}${API_ANIMATE_PATH}?${queryString}`; + return `${this.apiBaseUrl}${API_ANIMATE_PATH}?${queryString}`; } /** @@ -139,9 +141,9 @@ export class Client { path: string, bucket?: string, acl?: "public-read" | "", - storageClass?: string, + storageClass?: string, accessKeyId?: string, - secretAccessKey?: string, + secretAccessKey?: string ): Promise<{ bucket: string | null; key: string | null }> { options.store(true).storagePath(path).responseType("empty"); @@ -155,10 +157,10 @@ export class Client { options.storageClass(storageClass); } if (accessKeyId) { - options.storageAccessKeyId(accessKeyId) + options.storageAccessKeyId(accessKeyId); } if (secretAccessKey) { - options.storageSecretAccessKey(secretAccessKey) + options.storageSecretAccessKey(secretAccessKey); } const url =