diff --git a/README.md b/README.md index c6a90531..f00bfe46 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,16 @@ A TypeScript SDK for Jellyfin. ```js // Create a new instance of the SDK -const jellyfin = new Jellyfin(); +const jellyfin = new Jellyfin({ + clientInfo: { + name: 'My Client Application', + version: '1.0.0' + }, + deviceInfo: { + name: 'Device Name', + id: 'unique-device-id' + } +}); const api = jellyfin.createApi('https://demo.jellyfin.org/stable'); // Each API endpoint is exposed via a getter on the SDK instance using diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 5b350ca4..996c3f5f 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -8,18 +8,34 @@ import { Jellyfin } from '..'; // FIXME: These tests should be mocked and not calling an actual server const SERVER_URL = 'https://demo.jellyfin.org/stable'; +const TEST_CLIENT = { + name: 'sdk-test-client', + version: '0.0.0' +}; + +const TEST_DEVICE = { + name: 'device-name', + id: 'device-id' +}; + describe('Test the Base SDK', () => { it('create an api instance', () => { - const jellyfin = new Jellyfin(); + const jellyfin = new Jellyfin({ + clientInfo: TEST_CLIENT, + deviceInfo: TEST_DEVICE + }); expect(jellyfin).not.toBeNull(); const api = jellyfin.createApi(SERVER_URL); expect(api.basePath).toEqual(SERVER_URL); - expect(api.authorizationHeader).toEqual('MediaBrowser Client="jellyfin-sdk-typescript", Device="device-name", DeviceId="device-id", Version="v0.1.0", Token=""'); + expect(api.authorizationHeader).toEqual('MediaBrowser Client="sdk-test-client", Device="device-name", DeviceId="device-id", Version="0.0.0", Token=""'); }); it('public users api', async () => { - const jellyfin = new Jellyfin(); + const jellyfin = new Jellyfin({ + clientInfo: TEST_CLIENT, + deviceInfo: TEST_DEVICE + }); const api = jellyfin.createApi(SERVER_URL); const users = await api.userApi.getPublicUsers(); @@ -28,7 +44,10 @@ describe('Test the Base SDK', () => { }); it('public system info api', async () => { - const jellyfin = new Jellyfin(); + const jellyfin = new Jellyfin({ + clientInfo: TEST_CLIENT, + deviceInfo: TEST_DEVICE + }); const api = jellyfin.createApi(SERVER_URL); const info = await api.systemApi.getPublicSystemInfo(); @@ -37,7 +56,10 @@ describe('Test the Base SDK', () => { }); it('user login api', async () => { - const jellyfin = new Jellyfin(); + const jellyfin = new Jellyfin({ + clientInfo: TEST_CLIENT, + deviceInfo: TEST_DEVICE + }); const api = jellyfin.createApi(SERVER_URL); const auth = await api.authenticateUserByName({ Username: 'demo', Pw: '' }); @@ -46,7 +68,10 @@ describe('Test the Base SDK', () => { }); it('library api', async () => { - const jellyfin = new Jellyfin(); + const jellyfin = new Jellyfin({ + clientInfo: TEST_CLIENT, + deviceInfo: TEST_DEVICE + }); const api = jellyfin.createApi(SERVER_URL); await api.authenticateUserByName({ Username: 'demo', Pw: '' }); diff --git a/src/jellyfin.ts b/src/jellyfin.ts index 2c097bc5..10194cde 100644 --- a/src/jellyfin.ts +++ b/src/jellyfin.ts @@ -8,6 +8,11 @@ import { AxiosInstance } from 'axios'; import { Api } from './api'; import { ClientInfo, DeviceInfo } from './models'; +interface JellyfinParameters { + clientInfo: ClientInfo, + deviceInfo: DeviceInfo +} + /** * The minimum supported server version. */ @@ -20,13 +25,9 @@ export class Jellyfin { clientInfo; deviceInfo; - constructor( - clientInfo: ClientInfo = { name: 'jellyfin-sdk-typescript', version: 'v0.1.0' }, - // FIXME: The device info should always be required. - deviceInfo: DeviceInfo = { name: 'device-name', id: 'device-id' } - ) { - this.clientInfo = clientInfo; - this.deviceInfo = deviceInfo; + constructor(parameters: JellyfinParameters) { + this.clientInfo = parameters.clientInfo; + this.deviceInfo = parameters.deviceInfo; } createApi(basePath: string, accessToken?: string, axiosInstance?: AxiosInstance): Api {