diff --git a/src/api.ts b/src/api.ts index 9ec1d4d..9b10ec4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -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}`; } @@ -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( diff --git a/src/soundcloud.ts b/src/soundcloud.ts index 58e5a6e..066beab 100644 --- a/src/soundcloud.ts +++ b/src/soundcloud.ts @@ -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); } }