Skip to content

Commit

Permalink
add ability to patch fetch function
Browse files Browse the repository at this point in the history
  • Loading branch information
s1adem4n committed Jul 31, 2023
1 parent 73926f0 commit 98121ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class API {
public clientID: string,
public oauthToken: string,
public apiURL: string = "https://api-v2.soundcloud.com",
public fetchFn = fetch,
) {
API.headers.Authorization = `OAuth ${oauthToken}`;
}
Expand All @@ -29,8 +30,9 @@ export class API {
url.search = `?client_id=${this.clientID}`;
}

const response = await fetch(url.toString(), {
const response = await this.fetchFn(url.toString(), {
headers: API.headers,
method: "GET",
});
if (!response.ok) {
throw new Error(
Expand Down
3 changes: 2 additions & 1 deletion src/soundcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ export class Soundcloud {
clientID: string,
oauthToken: string,
apiURL = "https://api-v2.soundcloud.com",
fetchFn = fetch,
) {
Soundcloud.clientID = clientID;
Soundcloud.oauthToken = oauthToken;
this.api = new API(clientID, oauthToken, apiURL);
this.api = new API(clientID, oauthToken, apiURL, fetchFn);
}
}

Expand Down

0 comments on commit 98121ba

Please sign in to comment.