mirror of
https://github.com/jellyfin/jellyfin-sdk-typescript.git
synced 2024-11-23 05:59:44 +00:00
Require client and device info
This commit is contained in:
parent
52f101d649
commit
e05b93d613
11
README.md
11
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
|
||||
|
@ -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: '' });
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user