Compare commits

...

4 Commits

Author SHA1 Message Date
speakeasybot
a1f6c6f515 ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.166.1 2024-02-05 14:25:14 +00:00
speakeasy-bot
022d345196 🐝 Add license. 2024-02-01 16:30:24 +00:00
speakeasy-bot
6cec42bef1 🐝 Update gen.yaml 2024-02-01 16:30:23 +00:00
speakeasy-bot
eaa84306f6 🐝 Update workflow file 2024-02-01 16:30:22 +00:00
15 changed files with 331 additions and 340 deletions

View File

@@ -1,12 +1,12 @@
lockVersion: 2.0.0
id: 16f22cbf-f23f-4419-8924-3a4b06381947
management:
docChecksum: 94439465ae5d544f0e52b00719af05ee
docChecksum: 099fc5bbb987ae7e391f7f07b4212860
docVersion: 0.0.3
speakeasyVersion: internal
generationVersion: 2.245.1
releaseVersion: 0.6.1
configChecksum: 17b196f8440d03f46824f0af095f9927
generationVersion: 2.249.1
releaseVersion: 0.7.0
configChecksum: b3d1de88036ff1f77a38604e4ce3ffa1
repoURL: https://github.com/LukeHagar/plexjs.git
repoSubDirectory: .
installationURL: https://github.com/LukeHagar/plexjs
@@ -30,7 +30,6 @@ generatedFiles:
- src/sdk/search.ts
- src/sdk/library.ts
- src/sdk/log.ts
- src/sdk/tv.ts
- src/sdk/plex.ts
- src/sdk/playlists.ts
- src/sdk/security.ts
@@ -583,7 +582,6 @@ generatedFiles:
- docs/sdks/library/README.md
- docs/sdks/log/README.md
- docs/sdks/plex/README.md
- docs/sdks/tv/README.md
- docs/sdks/playlists/README.md
- docs/sdks/security/README.md
- docs/sdks/sessions/README.md

View File

@@ -111,11 +111,10 @@ run();
* [logMultiLine](docs/sdks/log/README.md#logmultiline) - Logging a multi-line message
* [enablePaperTrail](docs/sdks/log/README.md#enablepapertrail) - Enabling Papertrail
### [plex](docs/sdks/plex/README.md)
### [plex.tv](docs/sdks/tv/README.md)
* [getPin](docs/sdks/tv/README.md#getpin) - Get a Pin
* [getToken](docs/sdks/tv/README.md#gettoken) - Get Access Token
* [getPin](docs/sdks/plex/README.md#getpin) - Get a Pin
* [getToken](docs/sdks/plex/README.md#gettoken) - Get Access Token
### [playlists](docs/sdks/playlists/README.md)
@@ -272,7 +271,7 @@ async function run() {
const xPlexClientIdentifier = "string";
const strong = false;
const result = await sdk.plex.tv.getPin(xPlexClientIdentifier, strong, {
const result = await sdk.plex.getPin(xPlexClientIdentifier, strong, {
serverURL: "https://plex.tv/api/v2",
});

View File

@@ -169,3 +169,13 @@ Based on:
- [typescript v0.6.1] .
### Releases
- [NPM v0.6.1] https://www.npmjs.com/package/@lukehagar/plexjs/v/0.6.1 - .
## 2024-02-05 14:23:50
### Changes
Based on:
- OpenAPI Doc 0.0.3
- Speakeasy CLI 1.166.1 (2.249.1) https://github.com/speakeasy-api/speakeasy
### Generated
- [typescript v0.7.0] .
### Releases
- [NPM v0.7.0] https://www.npmjs.com/package/@lukehagar/plexjs/v/0.7.0 - .

View File

@@ -4,6 +4,6 @@
## Fields
| Field | Type | Required | Description |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<br/> |
| `strong` | *boolean* | :heavy_minus_sign: | Determines the kind of code returned by the API call<br/>Strong codes are used for Pin authentication flows<br/>Non-Strong codes are used for `Plex.tv/link`<br/> |

View File

@@ -4,6 +4,6 @@
## Fields
| Field | Type | Required | Description |
| ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for |
| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token |
| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<br/> |

View File

@@ -1,5 +1,106 @@
# Plex
(*plex*)
## Overview
API Calls that perform operations directly against https://Plex.tv
### Available Operations
* [getPin](#getpin) - Get a Pin
* [getToken](#gettoken) - Get Access Token
## getPin
Retrieve a Pin from Plex.tv for authentication flows
### Example Usage
```typescript
import { PlexAPI } from "@lukehagar/plexjs";
async function run() {
const sdk = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
});
const xPlexClientIdentifier = "string";
const strong = false;
const result = await sdk.plex.getPin(xPlexClientIdentifier, strong);
// Handle the result
console.log(result)
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<br/> |
| `strong` | *boolean* | :heavy_minus_sign: | Determines the kind of code returned by the API call<br/>Strong codes are used for Pin authentication flows<br/>Non-Strong codes are used for `Plex.tv/link`<br/> |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.serverURL` | *string* | :heavy_minus_sign: | An optional server URL to use. |
### Response
**Promise<[operations.GetPinResponse](../../models/operations/getpinresponse.md)>**
### Errors
| Error Object | Status Code | Content Type |
| ------------------------- | ------------------------- | ------------------------- |
| errors.GetPinResponseBody | 400 | application/json |
| errors.SDKError | 4xx-5xx | */* |
## getToken
Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
### Example Usage
```typescript
import { PlexAPI } from "@lukehagar/plexjs";
async function run() {
const sdk = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
});
const pinID = "string";
const xPlexClientIdentifier = "string";
const result = await sdk.plex.getToken(pinID, xPlexClientIdentifier);
// Handle the result
console.log(result)
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `pinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for |
| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | The unique identifier for the client application<br/>This is used to track the client application and its usage<br/>(UUID, serial number, or other number unique per device)<br/> |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.serverURL` | *string* | :heavy_minus_sign: | An optional server URL to use. |
### Response
**Promise<[operations.GetTokenResponse](../../models/operations/gettokenresponse.md)>**
### Errors
| Error Object | Status Code | Content Type |
| --------------------------- | --------------------------- | --------------------------- |
| errors.GetTokenResponseBody | 400 | application/json |
| errors.SDKError | 4xx-5xx | */* |

View File

@@ -1,101 +0,0 @@
# Tv
(*plex.tv*)
### Available Operations
* [getPin](#getpin) - Get a Pin
* [getToken](#gettoken) - Get Access Token
## getPin
Retrieve a Pin from Plex.tv for authentication flows
### Example Usage
```typescript
import { PlexAPI } from "@lukehagar/plexjs";
async function run() {
const sdk = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
});
const xPlexClientIdentifier = "string";
const strong = false;
const result = await sdk.plex.tv.getPin(xPlexClientIdentifier, strong);
// Handle the result
console.log(result)
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token |
| `strong` | *boolean* | :heavy_minus_sign: | Determines the kind of code returned by the API call<br/>Strong codes are used for Pin authentication flows<br/>Non-Strong codes are used for `Plex.tv/link`<br/> |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.serverURL` | *string* | :heavy_minus_sign: | An optional server URL to use. |
### Response
**Promise<[operations.GetPinResponse](../../models/operations/getpinresponse.md)>**
### Errors
| Error Object | Status Code | Content Type |
| ------------------------- | ------------------------- | ------------------------- |
| errors.GetPinResponseBody | 400 | application/json |
| errors.SDKError | 4xx-5xx | */* |
## getToken
Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
### Example Usage
```typescript
import { PlexAPI } from "@lukehagar/plexjs";
async function run() {
const sdk = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
});
const pinID = "string";
const xPlexClientIdentifier = "string";
const result = await sdk.plex.tv.getToken(pinID, xPlexClientIdentifier);
// Handle the result
console.log(result)
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `pinID` | *string* | :heavy_check_mark: | The PinID to retrieve an access token for |
| `xPlexClientIdentifier` | *string* | :heavy_check_mark: | Plex Authentication Token |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.serverURL` | *string* | :heavy_minus_sign: | An optional server URL to use. |
### Response
**Promise<[operations.GetTokenResponse](../../models/operations/gettokenresponse.md)>**
### Errors
| Error Object | Status Code | Content Type |
| --------------------------- | --------------------------- | --------------------------- |
| errors.GetTokenResponseBody | 400 | application/json |
| errors.SDKError | 4xx-5xx | */* |

View File

@@ -7,8 +7,9 @@ generation:
useClassNamesForArrayFields: true
fixes:
nameResolutionDec2023: false
parameterOrderingFeb2024: false
typescript:
version: 0.6.1
version: 0.7.0
author: LukeHagar
clientServerStatusCodesAsErrors: true
flattenGlobalSecurity: true

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@lukehagar/plexjs",
"version": "0.6.1",
"version": "0.7.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@lukehagar/plexjs",
"version": "0.6.1",
"version": "0.7.0",
"dependencies": {
"decimal.js": "^10.4.3",
"jsonpath": "^1.1.1"

View File

@@ -1,7 +1,7 @@
{
"type": "commonjs",
"name": "@lukehagar/plexjs",
"version": "0.6.1",
"version": "0.7.0",
"author": "LukeHagar",
"main": "./index.js",
"sideEffects": false,

View File

@@ -79,7 +79,7 @@ export function serverURLFromOptions(options: SDKOptions): URL {
export const SDK_METADATA = Object.freeze({
language: "typescript",
openapiDocVersion: "0.0.3",
sdkVersion: "0.6.1",
genVersion: "2.245.1",
userAgent: "speakeasy-sdk/typescript 0.6.1 2.245.1 0.0.3 @lukehagar/plexjs",
sdkVersion: "0.7.0",
genVersion: "2.249.1",
userAgent: "speakeasy-sdk/typescript 0.7.0 2.249.1 0.0.3 @lukehagar/plexjs",
});

View File

@@ -8,7 +8,12 @@ export const GetPinServerList = ["https://plex.tv/api/v2"] as const;
export type GetPinRequest = {
/**
* Plex Authentication Token
* The unique identifier for the client application
*
* @remarks
* This is used to track the client application and its usage
* (UUID, serial number, or other number unique per device)
*
*/
xPlexClientIdentifier: string;
/**

View File

@@ -12,7 +12,12 @@ export type GetTokenRequest = {
*/
pinID: string;
/**
* Plex Authentication Token
* The unique identifier for the client application
*
* @remarks
* This is used to track the client application and its usage
* (UUID, serial number, or other number unique per device)
*
*/
xPlexClientIdentifier: string;
};

View File

@@ -2,10 +2,12 @@
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
*/
import { SDKOptions, serverURLFromOptions } from "../lib/config";
import { SDK_METADATA, SDKOptions, serverURLFromOptions } from "../lib/config";
import * as enc$ from "../lib/encodings";
import { HTTPClient } from "../lib/http";
import { ClientSDK } from "../lib/sdks";
import { Tv } from "./tv";
import { ClientSDK, RequestOptions } from "../lib/sdks";
import * as errors from "../models/errors";
import * as operations from "../models/operations";
export class Plex extends ClientSDK {
private readonly options$: SDKOptions;
@@ -19,9 +21,184 @@ export class Plex extends ClientSDK {
this.options$ = options;
void this.options$;
}
/**
* Get a Pin
*
* @remarks
* Retrieve a Pin from Plex.tv for authentication flows
*/
async getPin(
xPlexClientIdentifier: string,
strong?: boolean | undefined,
options?: RequestOptions & { serverURL?: string }
): Promise<operations.GetPinResponse> {
const input$: operations.GetPinRequest = {
xPlexClientIdentifier: xPlexClientIdentifier,
strong: strong,
};
const headers$ = new Headers();
headers$.set("user-agent", SDK_METADATA.userAgent);
headers$.set("Accept", "application/json");
private _tv?: Tv;
get tv() {
return (this._tv ??= new Tv(this.options$));
const payload$ = operations.GetPinRequest$.outboundSchema.parse(input$);
const body$ = null;
const path$ = this.templateURLComponent("/pins")();
const query$ = [
enc$.encodeForm("strong", payload$.strong, { explode: true, charEncoding: "percent" }),
]
.filter(Boolean)
.join("&");
headers$.set(
"X-Plex-Client-Identifier",
enc$.encodeSimple("X-Plex-Client-Identifier", payload$["X-Plex-Client-Identifier"], {
explode: false,
charEncoding: "none",
})
);
const baseURL$ =
options?.serverURL ||
this.templateURLComponent(operations.GetPinServerList[0], {
charEncoding: "percent",
})();
let security$;
if (typeof this.options$.accessToken === "function") {
security$ = { accessToken: await this.options$.accessToken() };
} else if (this.options$.accessToken) {
security$ = { accessToken: this.options$.accessToken };
} else {
security$ = {};
}
const securitySettings$ = this.resolveGlobalSecurity(security$);
const response = await this.fetch$(
{
security: securitySettings$,
method: "POST",
baseURL: baseURL$,
path: path$,
headers: headers$,
query: query$,
body: body$,
},
options
);
const responseFields$ = {
ContentType: response.headers.get("content-type") ?? "application/octet-stream",
StatusCode: response.status,
RawResponse: response,
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = operations.GetPinResponse$.inboundSchema.parse({
...responseFields$,
object: responseBody,
});
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = errors.GetPinResponseBody$.inboundSchema.parse({
...responseFields$,
...responseBody,
});
throw result;
} else {
const responseBody = await response.text();
throw new errors.SDKError("Unexpected API response", response, responseBody);
}
}
/**
* Get Access Token
*
* @remarks
* Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
*/
async getToken(
pinID: string,
xPlexClientIdentifier: string,
options?: RequestOptions & { serverURL?: string }
): Promise<operations.GetTokenResponse> {
const input$: operations.GetTokenRequest = {
pinID: pinID,
xPlexClientIdentifier: xPlexClientIdentifier,
};
const headers$ = new Headers();
headers$.set("user-agent", SDK_METADATA.userAgent);
headers$.set("Accept", "application/json");
const payload$ = operations.GetTokenRequest$.outboundSchema.parse(input$);
const body$ = null;
const pathParams$ = {
pinID: enc$.encodeSimple("pinID", payload$.pinID, {
explode: false,
charEncoding: "percent",
}),
};
const path$ = this.templateURLComponent("/pins/{pinID}")(pathParams$);
headers$.set(
"X-Plex-Client-Identifier",
enc$.encodeSimple("X-Plex-Client-Identifier", payload$["X-Plex-Client-Identifier"], {
explode: false,
charEncoding: "none",
})
);
const baseURL$ =
options?.serverURL ||
this.templateURLComponent(operations.GetTokenServerList[0], {
charEncoding: "percent",
})();
let security$;
if (typeof this.options$.accessToken === "function") {
security$ = { accessToken: await this.options$.accessToken() };
} else if (this.options$.accessToken) {
security$ = { accessToken: this.options$.accessToken };
} else {
security$ = {};
}
const securitySettings$ = this.resolveGlobalSecurity(security$);
const response = await this.fetch$(
{
security: securitySettings$,
method: "GET",
baseURL: baseURL$,
path: path$,
headers: headers$,
body: body$,
},
options
);
const responseFields$ = {
ContentType: response.headers.get("content-type") ?? "application/octet-stream",
StatusCode: response.status,
RawResponse: response,
};
if (this.matchStatusCode(response, 200)) {
// fallthrough
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = errors.GetTokenResponseBody$.inboundSchema.parse({
...responseFields$,
...responseBody,
});
throw result;
} else {
const responseBody = await response.text();
throw new errors.SDKError("Unexpected API response", response, responseBody);
}
return operations.GetTokenResponse$.inboundSchema.parse(responseFields$);
}
}

View File

@@ -1,204 +0,0 @@
/*
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
*/
import { SDK_METADATA, SDKOptions, serverURLFromOptions } from "../lib/config";
import * as enc$ from "../lib/encodings";
import { HTTPClient } from "../lib/http";
import { ClientSDK, RequestOptions } from "../lib/sdks";
import * as errors from "../models/errors";
import * as operations from "../models/operations";
export class Tv extends ClientSDK {
private readonly options$: SDKOptions;
constructor(options: SDKOptions = {}) {
super({
client: options.httpClient || new HTTPClient(),
baseURL: serverURLFromOptions(options),
});
this.options$ = options;
void this.options$;
}
/**
* Get a Pin
*
* @remarks
* Retrieve a Pin from Plex.tv for authentication flows
*/
async getPin(
xPlexClientIdentifier: string,
strong?: boolean | undefined,
options?: RequestOptions & { serverURL?: string }
): Promise<operations.GetPinResponse> {
const input$: operations.GetPinRequest = {
xPlexClientIdentifier: xPlexClientIdentifier,
strong: strong,
};
const headers$ = new Headers();
headers$.set("user-agent", SDK_METADATA.userAgent);
headers$.set("Accept", "application/json");
const payload$ = operations.GetPinRequest$.outboundSchema.parse(input$);
const body$ = null;
const path$ = this.templateURLComponent("/pins")();
const query$ = [
enc$.encodeForm("strong", payload$.strong, { explode: true, charEncoding: "percent" }),
]
.filter(Boolean)
.join("&");
headers$.set(
"X-Plex-Client-Identifier",
enc$.encodeSimple("X-Plex-Client-Identifier", payload$["X-Plex-Client-Identifier"], {
explode: false,
charEncoding: "none",
})
);
const baseURL$ =
options?.serverURL ||
this.templateURLComponent(operations.GetPinServerList[0], {
charEncoding: "percent",
})();
let security$;
if (typeof this.options$.accessToken === "function") {
security$ = { accessToken: await this.options$.accessToken() };
} else if (this.options$.accessToken) {
security$ = { accessToken: this.options$.accessToken };
} else {
security$ = {};
}
const securitySettings$ = this.resolveGlobalSecurity(security$);
const response = await this.fetch$(
{
security: securitySettings$,
method: "POST",
baseURL: baseURL$,
path: path$,
headers: headers$,
query: query$,
body: body$,
},
options
);
const responseFields$ = {
ContentType: response.headers.get("content-type") ?? "application/octet-stream",
StatusCode: response.status,
RawResponse: response,
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = operations.GetPinResponse$.inboundSchema.parse({
...responseFields$,
object: responseBody,
});
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = errors.GetPinResponseBody$.inboundSchema.parse({
...responseFields$,
...responseBody,
});
throw result;
} else {
const responseBody = await response.text();
throw new errors.SDKError("Unexpected API response", response, responseBody);
}
}
/**
* Get Access Token
*
* @remarks
* Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
*/
async getToken(
pinID: string,
xPlexClientIdentifier: string,
options?: RequestOptions & { serverURL?: string }
): Promise<operations.GetTokenResponse> {
const input$: operations.GetTokenRequest = {
pinID: pinID,
xPlexClientIdentifier: xPlexClientIdentifier,
};
const headers$ = new Headers();
headers$.set("user-agent", SDK_METADATA.userAgent);
headers$.set("Accept", "application/json");
const payload$ = operations.GetTokenRequest$.outboundSchema.parse(input$);
const body$ = null;
const pathParams$ = {
pinID: enc$.encodeSimple("pinID", payload$.pinID, {
explode: false,
charEncoding: "percent",
}),
};
const path$ = this.templateURLComponent("/pins/{pinID}")(pathParams$);
headers$.set(
"X-Plex-Client-Identifier",
enc$.encodeSimple("X-Plex-Client-Identifier", payload$["X-Plex-Client-Identifier"], {
explode: false,
charEncoding: "none",
})
);
const baseURL$ =
options?.serverURL ||
this.templateURLComponent(operations.GetTokenServerList[0], {
charEncoding: "percent",
})();
let security$;
if (typeof this.options$.accessToken === "function") {
security$ = { accessToken: await this.options$.accessToken() };
} else if (this.options$.accessToken) {
security$ = { accessToken: this.options$.accessToken };
} else {
security$ = {};
}
const securitySettings$ = this.resolveGlobalSecurity(security$);
const response = await this.fetch$(
{
security: securitySettings$,
method: "GET",
baseURL: baseURL$,
path: path$,
headers: headers$,
body: body$,
},
options
);
const responseFields$ = {
ContentType: response.headers.get("content-type") ?? "application/octet-stream",
StatusCode: response.status,
RawResponse: response,
};
if (this.matchStatusCode(response, 200)) {
// fallthrough
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = errors.GetTokenResponseBody$.inboundSchema.parse({
...responseFields$,
...responseBody,
});
throw result;
} else {
const responseBody = await response.text();
throw new errors.SDKError("Unexpected API response", response, responseBody);
}
return operations.GetTokenResponse$.inboundSchema.parse(responseFields$);
}
}