Skip to content

Commit b86d6a7

Browse files
authored
Merge pull request #867 from thornbill/add-get-url
2 parents 732873c + 85b6138 commit b86d6a7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/__tests__/api.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,10 @@ describe('Api', () => {
8080
const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE);
8181
expect(api.basePath).toBe(SERVER_URL);
8282
});
83+
84+
it('should return the correct uri', () => {
85+
const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE);
86+
const uri = api.getUri('/api/url', { param1: 'bar', param2: 'baz 123;xyz' });
87+
expect(uri).toBe(`${SERVER_URL}/api/url?param1=bar&param2=baz+123%3Bxyz`);
88+
});
8389
});

src/api.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ export class Api {
6464
});
6565
}
6666

67+
/**
68+
* Gets a full URI for a relative URL to the Jellyfin server for a given SDK Api instance.
69+
* @param url The relative URL.
70+
* @param params Any URL parameters.
71+
* @returns The complete URI with protocol, host, and base URL (if any).
72+
*/
73+
getUri(url: string, params?: object) {
74+
return this.axiosInstance.getUri({
75+
baseURL: this.basePath,
76+
url,
77+
params
78+
});
79+
}
80+
6781
/**
6882
* Convenience method for logging out and updating the internal state.
6983
*/

0 commit comments

Comments
 (0)