Skip to content

Commit

Permalink
Allow to replace the API base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
krasun committed Nov 26, 2023
1 parent 4446c6b commit 033d02e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 10 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -22,6 +23,7 @@ export class Client {

this.accessKey = accessKey;
this.secretKey = secretKey;
this.apiBaseUrl = apiBaseUrl ? apiBaseUrl : API_BASE_URL;
}

/**
Expand All @@ -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}`;
}

/**
Expand All @@ -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}`;
}

/**
Expand All @@ -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}`;
}

/**
Expand Down Expand Up @@ -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");

Expand All @@ -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 =
Expand Down

0 comments on commit 033d02e

Please sign in to comment.