mirror of
https://github.com/LukeHagar/plexpy.git
synced 2025-12-06 04:20:52 +00:00
ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.166.1
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
lockVersion: 2.0.0
|
||||
id: 3eeea668-4ef4-464e-a888-bdfa023bedf5
|
||||
management:
|
||||
docChecksum: 94439465ae5d544f0e52b00719af05ee
|
||||
docChecksum: 099fc5bbb987ae7e391f7f07b4212860
|
||||
docVersion: 0.0.3
|
||||
speakeasyVersion: internal
|
||||
generationVersion: 2.248.1
|
||||
releaseVersion: 0.1.0
|
||||
configChecksum: 2877f8704c4fbbfe7f9d4f3b50a47769
|
||||
generationVersion: 2.249.1
|
||||
releaseVersion: 0.1.1
|
||||
configChecksum: b27977e99573e671f0e8dcca458909cc
|
||||
repoURL: https://github.com/LukeHagar/plexpy.git
|
||||
repoSubDirectory: .
|
||||
installationURL: https://github.com/LukeHagar/plexpy.git
|
||||
@@ -31,7 +31,6 @@ generatedFiles:
|
||||
- src/plex_api/search.py
|
||||
- src/plex_api/library.py
|
||||
- src/plex_api/log.py
|
||||
- src/plex_api/tv.py
|
||||
- src/plex_api/plex.py
|
||||
- src/plex_api/playlists.py
|
||||
- src/plex_api/security.py
|
||||
@@ -569,7 +568,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
|
||||
|
||||
@@ -100,11 +100,10 @@ if res.object is not None:
|
||||
* [log_multi_line](docs/sdks/log/README.md#log_multi_line) - Logging a multi-line message
|
||||
* [enable_paper_trail](docs/sdks/log/README.md#enable_paper_trail) - Enabling Papertrail
|
||||
|
||||
### [plex](docs/sdks/plex/README.md)
|
||||
|
||||
### [plex.tv](docs/sdks/tv/README.md)
|
||||
|
||||
* [get_pin](docs/sdks/tv/README.md#get_pin) - Get a Pin
|
||||
* [get_token](docs/sdks/tv/README.md#get_token) - Get Access Token
|
||||
* [get_pin](docs/sdks/plex/README.md#get_pin) - Get a Pin
|
||||
* [get_token](docs/sdks/plex/README.md#get_token) - Get Access Token
|
||||
|
||||
### [playlists](docs/sdks/playlists/README.md)
|
||||
|
||||
@@ -245,7 +244,7 @@ s = plex_api.PlexAPI(
|
||||
)
|
||||
|
||||
|
||||
res = s.plex.tv.get_pin(server_url="https://plex.tv/api/v2", x_plex_client_identifier='string', strong=False)
|
||||
res = s.plex.get_pin(server_url="https://plex.tv/api/v2", x_plex_client_identifier='string', strong=False)
|
||||
|
||||
if res.object is not None:
|
||||
# handle response
|
||||
|
||||
12
RELEASES.md
12
RELEASES.md
@@ -28,4 +28,14 @@ Based on:
|
||||
### Generated
|
||||
- [python v0.1.0] .
|
||||
### Releases
|
||||
- [PyPI v0.1.0] https://pypi.org/project/plex-api-client/0.1.0 - .
|
||||
- [PyPI v0.1.0] https://pypi.org/project/plex-api-client/0.1.0 - .
|
||||
|
||||
## 2024-02-05 14:23:46
|
||||
### Changes
|
||||
Based on:
|
||||
- OpenAPI Doc 0.0.3
|
||||
- Speakeasy CLI 1.166.1 (2.249.1) https://github.com/speakeasy-api/speakeasy
|
||||
### Generated
|
||||
- [python v0.1.1] .
|
||||
### Releases
|
||||
- [PyPI v0.1.1] https://pypi.org/project/plex-api-client/0.1.1 - .
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `x_plex_client_identifier` | *str* | :heavy_check_mark: | Plex Authentication Token |
|
||||
| `strong` | *Optional[bool]* | :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/> |
|
||||
| Field | Type | Required | Description |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `x_plex_client_identifier` | *str* | :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` | *Optional[bool]* | :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/> |
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- |
|
||||
| `pin_id` | *str* | :heavy_check_mark: | The PinID to retrieve an access token for |
|
||||
| `x_plex_client_identifier` | *str* | :heavy_check_mark: | Plex Authentication Token |
|
||||
| Field | Type | Required | Description |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `pin_id` | *str* | :heavy_check_mark: | The PinID to retrieve an access token for |
|
||||
| `x_plex_client_identifier` | *str* | :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/> |
|
||||
@@ -1,5 +1,94 @@
|
||||
# Plex
|
||||
(*plex*)
|
||||
|
||||
## Overview
|
||||
|
||||
API Calls that perform operations directly against https://Plex.tv
|
||||
|
||||
|
||||
### Available Operations
|
||||
|
||||
* [get_pin](#get_pin) - Get a Pin
|
||||
* [get_token](#get_token) - Get Access Token
|
||||
|
||||
## get_pin
|
||||
|
||||
Retrieve a Pin from Plex.tv for authentication flows
|
||||
|
||||
### Example Usage
|
||||
|
||||
```python
|
||||
import plex_api
|
||||
from plex_api.models import operations
|
||||
|
||||
s = plex_api.PlexAPI(
|
||||
access_token="<YOUR_API_KEY_HERE>",
|
||||
)
|
||||
|
||||
|
||||
res = s.plex.get_pin(x_plex_client_identifier='string', strong=False)
|
||||
|
||||
if res.object is not None:
|
||||
# handle response
|
||||
pass
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `x_plex_client_identifier` | *str* | :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` | *Optional[bool]* | :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/> |
|
||||
| `server_url` | *Optional[str]* | :heavy_minus_sign: | An optional server URL to use. |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
**[operations.GetPinResponse](../../models/operations/getpinresponse.md)**
|
||||
### Errors
|
||||
|
||||
| Error Object | Status Code | Content Type |
|
||||
| ------------------------- | ------------------------- | ------------------------- |
|
||||
| errors.GetPinResponseBody | 400 | application/json |
|
||||
| errors.SDKError | 4x-5xx | */* |
|
||||
|
||||
## get_token
|
||||
|
||||
Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
|
||||
|
||||
### Example Usage
|
||||
|
||||
```python
|
||||
import plex_api
|
||||
from plex_api.models import operations
|
||||
|
||||
s = plex_api.PlexAPI(
|
||||
access_token="<YOUR_API_KEY_HERE>",
|
||||
)
|
||||
|
||||
|
||||
res = s.plex.get_token(pin_id='string', x_plex_client_identifier='string')
|
||||
|
||||
if res.status_code == 200:
|
||||
# handle response
|
||||
pass
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `pin_id` | *str* | :heavy_check_mark: | The PinID to retrieve an access token for |
|
||||
| `x_plex_client_identifier` | *str* | :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/> |
|
||||
| `server_url` | *Optional[str]* | :heavy_minus_sign: | An optional server URL to use. |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
**[operations.GetTokenResponse](../../models/operations/gettokenresponse.md)**
|
||||
### Errors
|
||||
|
||||
| Error Object | Status Code | Content Type |
|
||||
| --------------------------- | --------------------------- | --------------------------- |
|
||||
| errors.GetTokenResponseBody | 400 | application/json |
|
||||
| errors.SDKError | 4x-5xx | */* |
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
# Tv
|
||||
(*plex.tv*)
|
||||
|
||||
### Available Operations
|
||||
|
||||
* [get_pin](#get_pin) - Get a Pin
|
||||
* [get_token](#get_token) - Get Access Token
|
||||
|
||||
## get_pin
|
||||
|
||||
Retrieve a Pin from Plex.tv for authentication flows
|
||||
|
||||
### Example Usage
|
||||
|
||||
```python
|
||||
import plex_api
|
||||
from plex_api.models import operations
|
||||
|
||||
s = plex_api.PlexAPI(
|
||||
access_token="<YOUR_API_KEY_HERE>",
|
||||
)
|
||||
|
||||
|
||||
res = s.plex.tv.get_pin(x_plex_client_identifier='string', strong=False)
|
||||
|
||||
if res.object is not None:
|
||||
# handle response
|
||||
pass
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `x_plex_client_identifier` | *str* | :heavy_check_mark: | Plex Authentication Token |
|
||||
| `strong` | *Optional[bool]* | :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/> |
|
||||
| `server_url` | *Optional[str]* | :heavy_minus_sign: | An optional server URL to use. |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
**[operations.GetPinResponse](../../models/operations/getpinresponse.md)**
|
||||
### Errors
|
||||
|
||||
| Error Object | Status Code | Content Type |
|
||||
| ------------------------- | ------------------------- | ------------------------- |
|
||||
| errors.GetPinResponseBody | 400 | application/json |
|
||||
| errors.SDKError | 4x-5xx | */* |
|
||||
|
||||
## get_token
|
||||
|
||||
Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
|
||||
|
||||
### Example Usage
|
||||
|
||||
```python
|
||||
import plex_api
|
||||
from plex_api.models import operations
|
||||
|
||||
s = plex_api.PlexAPI(
|
||||
access_token="<YOUR_API_KEY_HERE>",
|
||||
)
|
||||
|
||||
|
||||
res = s.plex.tv.get_token(pin_id='string', x_plex_client_identifier='string')
|
||||
|
||||
if res.status_code == 200:
|
||||
# handle response
|
||||
pass
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
| ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- |
|
||||
| `pin_id` | *str* | :heavy_check_mark: | The PinID to retrieve an access token for |
|
||||
| `x_plex_client_identifier` | *str* | :heavy_check_mark: | Plex Authentication Token |
|
||||
| `server_url` | *Optional[str]* | :heavy_minus_sign: | An optional server URL to use. |
|
||||
|
||||
|
||||
### Response
|
||||
|
||||
**[operations.GetTokenResponse](../../models/operations/gettokenresponse.md)**
|
||||
### Errors
|
||||
|
||||
| Error Object | Status Code | Content Type |
|
||||
| --------------------------- | --------------------------- | --------------------------- |
|
||||
| errors.GetTokenResponseBody | 400 | application/json |
|
||||
| errors.SDKError | 4x-5xx | */* |
|
||||
2
gen.yaml
2
gen.yaml
@@ -9,7 +9,7 @@ generation:
|
||||
nameResolutionDec2023: false
|
||||
parameterOrderingFeb2024: false
|
||||
python:
|
||||
version: 0.1.0
|
||||
version: 0.1.1
|
||||
author: LukeHagar
|
||||
clientServerStatusCodesAsErrors: true
|
||||
description: Python Client SDK Generated by Speakeasy
|
||||
|
||||
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ except FileNotFoundError:
|
||||
|
||||
setuptools.setup(
|
||||
name="plex-api-client",
|
||||
version="0.1.0",
|
||||
version="0.1.1",
|
||||
author="LukeHagar",
|
||||
description="Python Client SDK Generated by Speakeasy",
|
||||
long_description=long_description,
|
||||
|
||||
@@ -17,7 +17,10 @@ GET_PIN_SERVERS = [
|
||||
@dataclasses.dataclass
|
||||
class GetPinRequest:
|
||||
x_plex_client_identifier: str = dataclasses.field(metadata={'header': { 'field_name': 'X-Plex-Client-Identifier', 'style': 'simple', 'explode': False }})
|
||||
r"""Plex Authentication Token"""
|
||||
r"""The unique identifier for the client application
|
||||
This is used to track the client application and its usage
|
||||
(UUID, serial number, or other number unique per device)
|
||||
"""
|
||||
strong: Optional[bool] = dataclasses.field(default=False, metadata={'query_param': { 'field_name': 'strong', 'style': 'form', 'explode': True }})
|
||||
r"""Determines the kind of code returned by the API call
|
||||
Strong codes are used for Pin authentication flows
|
||||
|
||||
@@ -14,7 +14,10 @@ class GetTokenRequest:
|
||||
pin_id: str = dataclasses.field(metadata={'path_param': { 'field_name': 'pinID', 'style': 'simple', 'explode': False }})
|
||||
r"""The PinID to retrieve an access token for"""
|
||||
x_plex_client_identifier: str = dataclasses.field(metadata={'header': { 'field_name': 'X-Plex-Client-Identifier', 'style': 'simple', 'explode': False }})
|
||||
r"""Plex Authentication Token"""
|
||||
r"""The unique identifier for the client application
|
||||
This is used to track the client application and its usage
|
||||
(UUID, serial number, or other number unique per device)
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,110 @@
|
||||
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
|
||||
|
||||
from .sdkconfiguration import SDKConfiguration
|
||||
from .tv import Tv
|
||||
from plex_api import utils
|
||||
from plex_api.models import errors, operations
|
||||
from typing import Optional
|
||||
|
||||
class Plex:
|
||||
tv: Tv
|
||||
r"""API Calls that perform operations directly against https://Plex.tv"""
|
||||
sdk_configuration: SDKConfiguration
|
||||
|
||||
def __init__(self, sdk_config: SDKConfiguration) -> None:
|
||||
self.sdk_configuration = sdk_config
|
||||
self._init_sdks()
|
||||
|
||||
def _init_sdks(self):
|
||||
self.tv = Tv(self.sdk_configuration)
|
||||
|
||||
|
||||
|
||||
def get_pin(self, x_plex_client_identifier: str, strong: Optional[bool] = None, server_url: Optional[str] = None) -> operations.GetPinResponse:
|
||||
r"""Get a Pin
|
||||
Retrieve a Pin from Plex.tv for authentication flows
|
||||
"""
|
||||
request = operations.GetPinRequest(
|
||||
x_plex_client_identifier=x_plex_client_identifier,
|
||||
strong=strong,
|
||||
)
|
||||
|
||||
base_url = utils.template_url(operations.GET_PIN_SERVERS[0], {
|
||||
})
|
||||
if server_url is not None:
|
||||
base_url = server_url
|
||||
|
||||
url = base_url + '/pins'
|
||||
headers = utils.get_headers(request)
|
||||
query_params = utils.get_query_params(operations.GetPinRequest, request)
|
||||
headers['Accept'] = 'application/json'
|
||||
headers['user-agent'] = self.sdk_configuration.user_agent
|
||||
|
||||
if callable(self.sdk_configuration.security):
|
||||
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security())
|
||||
else:
|
||||
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)
|
||||
|
||||
http_res = client.request('POST', url, params=query_params, headers=headers)
|
||||
content_type = http_res.headers.get('Content-Type')
|
||||
|
||||
res = operations.GetPinResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
|
||||
|
||||
if http_res.status_code == 200:
|
||||
if utils.match_content_type(content_type, 'application/json'):
|
||||
out = utils.unmarshal_json(http_res.text, Optional[operations.GetPinResponseBody])
|
||||
res.object = out
|
||||
else:
|
||||
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
||||
elif http_res.status_code == 400:
|
||||
if utils.match_content_type(content_type, 'application/json'):
|
||||
out = utils.unmarshal_json(http_res.text, errors.GetPinResponseBody)
|
||||
out.raw_response = http_res
|
||||
raise out
|
||||
else:
|
||||
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
||||
elif http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code >= 500 and http_res.status_code < 600:
|
||||
raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def get_token(self, pin_id: str, x_plex_client_identifier: str, server_url: Optional[str] = None) -> operations.GetTokenResponse:
|
||||
r"""Get Access Token
|
||||
Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
|
||||
"""
|
||||
request = operations.GetTokenRequest(
|
||||
pin_id=pin_id,
|
||||
x_plex_client_identifier=x_plex_client_identifier,
|
||||
)
|
||||
|
||||
base_url = utils.template_url(operations.GET_TOKEN_SERVERS[0], {
|
||||
})
|
||||
if server_url is not None:
|
||||
base_url = server_url
|
||||
|
||||
url = utils.generate_url(operations.GetTokenRequest, base_url, '/pins/{pinID}', request)
|
||||
headers = utils.get_headers(request)
|
||||
headers['Accept'] = 'application/json'
|
||||
headers['user-agent'] = self.sdk_configuration.user_agent
|
||||
|
||||
if callable(self.sdk_configuration.security):
|
||||
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security())
|
||||
else:
|
||||
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)
|
||||
|
||||
http_res = client.request('GET', url, headers=headers)
|
||||
content_type = http_res.headers.get('Content-Type')
|
||||
|
||||
res = operations.GetTokenResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
|
||||
|
||||
if http_res.status_code == 200:
|
||||
pass
|
||||
elif http_res.status_code == 400:
|
||||
if utils.match_content_type(content_type, 'application/json'):
|
||||
out = utils.unmarshal_json(http_res.text, errors.GetTokenResponseBody)
|
||||
out.raw_response = http_res
|
||||
raise out
|
||||
else:
|
||||
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
||||
elif http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code >= 500 and http_res.status_code < 600:
|
||||
raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ class PlexAPI:
|
||||
log: Log
|
||||
r"""Submit logs to the Log Handler for Plex Media Server"""
|
||||
plex: Plex
|
||||
r"""API Calls that perform operations directly against https://Plex.tv"""
|
||||
playlists: Playlists
|
||||
r"""Playlists are ordered collections of media. They can be dumb (just a list of media) or smart (based on a media query, such as \\"all albums from 2017\\").
|
||||
They can be organized in (optionally nesting) folders.
|
||||
|
||||
@@ -30,9 +30,9 @@ class SDKConfiguration:
|
||||
server_defaults: List[Dict[str, str]] = field(default_factory=List)
|
||||
language: str = 'python'
|
||||
openapi_doc_version: str = '0.0.3'
|
||||
sdk_version: str = '0.1.0'
|
||||
gen_version: str = '2.248.1'
|
||||
user_agent: str = 'speakeasy-sdk/python 0.1.0 2.248.1 0.0.3 plex-api-client'
|
||||
sdk_version: str = '0.1.1'
|
||||
gen_version: str = '2.249.1'
|
||||
user_agent: str = 'speakeasy-sdk/python 0.1.1 2.249.1 0.0.3 plex-api-client'
|
||||
retry_config: RetryConfig = None
|
||||
|
||||
def get_server_details(self) -> Tuple[str, Dict[str, str]]:
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
|
||||
|
||||
from .sdkconfiguration import SDKConfiguration
|
||||
from plex_api import utils
|
||||
from plex_api.models import errors, operations
|
||||
from typing import Optional
|
||||
|
||||
class Tv:
|
||||
sdk_configuration: SDKConfiguration
|
||||
|
||||
def __init__(self, sdk_config: SDKConfiguration) -> None:
|
||||
self.sdk_configuration = sdk_config
|
||||
|
||||
|
||||
|
||||
def get_pin(self, x_plex_client_identifier: str, strong: Optional[bool] = None, server_url: Optional[str] = None) -> operations.GetPinResponse:
|
||||
r"""Get a Pin
|
||||
Retrieve a Pin from Plex.tv for authentication flows
|
||||
"""
|
||||
request = operations.GetPinRequest(
|
||||
x_plex_client_identifier=x_plex_client_identifier,
|
||||
strong=strong,
|
||||
)
|
||||
|
||||
base_url = utils.template_url(operations.GET_PIN_SERVERS[0], {
|
||||
})
|
||||
if server_url is not None:
|
||||
base_url = server_url
|
||||
|
||||
url = base_url + '/pins'
|
||||
headers = utils.get_headers(request)
|
||||
query_params = utils.get_query_params(operations.GetPinRequest, request)
|
||||
headers['Accept'] = 'application/json'
|
||||
headers['user-agent'] = self.sdk_configuration.user_agent
|
||||
|
||||
if callable(self.sdk_configuration.security):
|
||||
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security())
|
||||
else:
|
||||
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)
|
||||
|
||||
http_res = client.request('POST', url, params=query_params, headers=headers)
|
||||
content_type = http_res.headers.get('Content-Type')
|
||||
|
||||
res = operations.GetPinResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
|
||||
|
||||
if http_res.status_code == 200:
|
||||
if utils.match_content_type(content_type, 'application/json'):
|
||||
out = utils.unmarshal_json(http_res.text, Optional[operations.GetPinResponseBody])
|
||||
res.object = out
|
||||
else:
|
||||
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
||||
elif http_res.status_code == 400:
|
||||
if utils.match_content_type(content_type, 'application/json'):
|
||||
out = utils.unmarshal_json(http_res.text, errors.GetPinResponseBody)
|
||||
out.raw_response = http_res
|
||||
raise out
|
||||
else:
|
||||
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
||||
elif http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code >= 500 and http_res.status_code < 600:
|
||||
raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def get_token(self, pin_id: str, x_plex_client_identifier: str, server_url: Optional[str] = None) -> operations.GetTokenResponse:
|
||||
r"""Get Access Token
|
||||
Retrieve an Access Token from Plex.tv after the Pin has already been authenticated
|
||||
"""
|
||||
request = operations.GetTokenRequest(
|
||||
pin_id=pin_id,
|
||||
x_plex_client_identifier=x_plex_client_identifier,
|
||||
)
|
||||
|
||||
base_url = utils.template_url(operations.GET_TOKEN_SERVERS[0], {
|
||||
})
|
||||
if server_url is not None:
|
||||
base_url = server_url
|
||||
|
||||
url = utils.generate_url(operations.GetTokenRequest, base_url, '/pins/{pinID}', request)
|
||||
headers = utils.get_headers(request)
|
||||
headers['Accept'] = 'application/json'
|
||||
headers['user-agent'] = self.sdk_configuration.user_agent
|
||||
|
||||
if callable(self.sdk_configuration.security):
|
||||
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security())
|
||||
else:
|
||||
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)
|
||||
|
||||
http_res = client.request('GET', url, headers=headers)
|
||||
content_type = http_res.headers.get('Content-Type')
|
||||
|
||||
res = operations.GetTokenResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
|
||||
|
||||
if http_res.status_code == 200:
|
||||
pass
|
||||
elif http_res.status_code == 400:
|
||||
if utils.match_content_type(content_type, 'application/json'):
|
||||
out = utils.unmarshal_json(http_res.text, errors.GetTokenResponseBody)
|
||||
out.raw_response = http_res
|
||||
raise out
|
||||
else:
|
||||
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
||||
elif http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code >= 500 and http_res.status_code < 600:
|
||||
raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user