mirror of
https://github.com/LukeHagar/plexpy.git
synced 2025-12-06 04:20:52 +00:00
153 lines
7.8 KiB
Python
153 lines
7.8 KiB
Python
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
|
|
|
|
import requests as requests_http
|
|
from .sdkconfiguration import SDKConfiguration
|
|
from plex_api import utils
|
|
from plex_api._hooks import HookContext
|
|
from plex_api.models import errors, operations
|
|
from typing import Optional
|
|
|
|
class Activities:
|
|
r"""Activities are awesome. They provide a way to monitor and control asynchronous operations on the server. In order to receive real-time updates for activities, a client would normally subscribe via either EventSource or Websocket endpoints.
|
|
Activities are associated with HTTP replies via a special `X-Plex-Activity` header which contains the UUID of the activity.
|
|
Activities are optional cancellable. If cancellable, they may be cancelled via the `DELETE` endpoint. Other details:
|
|
- They can contain a `progress` (from 0 to 100) marking the percent completion of the activity.
|
|
- They must contain an `type` which is used by clients to distinguish the specific activity.
|
|
- They may contain a `Context` object with attributes which associate the activity with various specific entities (items, libraries, etc.)
|
|
- The may contain a `Response` object which attributes which represent the result of the asynchronous operation.
|
|
"""
|
|
sdk_configuration: SDKConfiguration
|
|
|
|
def __init__(self, sdk_config: SDKConfiguration) -> None:
|
|
self.sdk_configuration = sdk_config
|
|
|
|
|
|
|
|
def get_server_activities(self) -> operations.GetServerActivitiesResponse:
|
|
r"""Get Server Activities
|
|
Get Server Activities
|
|
"""
|
|
hook_ctx = HookContext(operation_id='getServerActivities', oauth2_scopes=[], security_source=self.sdk_configuration.security)
|
|
base_url = utils.template_url(*self.sdk_configuration.get_server_details())
|
|
|
|
url = base_url + '/activities'
|
|
|
|
if callable(self.sdk_configuration.security):
|
|
headers, query_params = utils.get_security(self.sdk_configuration.security())
|
|
else:
|
|
headers, query_params = utils.get_security(self.sdk_configuration.security)
|
|
|
|
headers['Accept'] = 'application/json'
|
|
headers['user-agent'] = self.sdk_configuration.user_agent
|
|
client = self.sdk_configuration.client
|
|
|
|
try:
|
|
req = self.sdk_configuration.get_hooks().before_request(
|
|
hook_ctx,
|
|
requests_http.Request('GET', url, params=query_params, headers=headers).prepare(),
|
|
)
|
|
http_res = client.send(req)
|
|
except Exception as e:
|
|
_, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e)
|
|
raise e
|
|
|
|
if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
|
|
http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None)
|
|
if e:
|
|
raise e
|
|
else:
|
|
result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res)
|
|
if isinstance(result, Exception):
|
|
raise result
|
|
http_res = result
|
|
|
|
|
|
res = operations.GetServerActivitiesResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type'), raw_response=http_res)
|
|
|
|
if http_res.status_code == 200:
|
|
if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'):
|
|
out = utils.unmarshal_json(http_res.text, Optional[operations.GetServerActivitiesResponseBody])
|
|
res.object = out
|
|
else:
|
|
content_type = http_res.headers.get('Content-Type')
|
|
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 or 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)
|
|
elif http_res.status_code == 401:
|
|
if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'):
|
|
out = utils.unmarshal_json(http_res.text, errors.GetServerActivitiesResponseBody)
|
|
out.raw_response = http_res
|
|
raise out
|
|
else:
|
|
content_type = http_res.headers.get('Content-Type')
|
|
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
|
else:
|
|
raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
|
|
|
|
return res
|
|
|
|
|
|
|
|
def cancel_server_activities(self, activity_uuid: str) -> operations.CancelServerActivitiesResponse:
|
|
r"""Cancel Server Activities
|
|
Cancel Server Activities
|
|
"""
|
|
hook_ctx = HookContext(operation_id='cancelServerActivities', oauth2_scopes=[], security_source=self.sdk_configuration.security)
|
|
request = operations.CancelServerActivitiesRequest(
|
|
activity_uuid=activity_uuid,
|
|
)
|
|
|
|
base_url = utils.template_url(*self.sdk_configuration.get_server_details())
|
|
|
|
url = utils.generate_url(operations.CancelServerActivitiesRequest, base_url, '/activities/{activityUUID}', request, self.sdk_configuration.globals)
|
|
|
|
if callable(self.sdk_configuration.security):
|
|
headers, query_params = utils.get_security(self.sdk_configuration.security())
|
|
else:
|
|
headers, query_params = utils.get_security(self.sdk_configuration.security)
|
|
|
|
headers['Accept'] = 'application/json'
|
|
headers['user-agent'] = self.sdk_configuration.user_agent
|
|
client = self.sdk_configuration.client
|
|
|
|
try:
|
|
req = self.sdk_configuration.get_hooks().before_request(
|
|
hook_ctx,
|
|
requests_http.Request('DELETE', url, params=query_params, headers=headers).prepare(),
|
|
)
|
|
http_res = client.send(req)
|
|
except Exception as e:
|
|
_, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e)
|
|
raise e
|
|
|
|
if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
|
|
http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None)
|
|
if e:
|
|
raise e
|
|
else:
|
|
result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res)
|
|
if isinstance(result, Exception):
|
|
raise result
|
|
http_res = result
|
|
|
|
|
|
res = operations.CancelServerActivitiesResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type'), raw_response=http_res)
|
|
|
|
if http_res.status_code == 200:
|
|
pass
|
|
elif http_res.status_code == 400 or 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)
|
|
elif http_res.status_code == 401:
|
|
if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'):
|
|
out = utils.unmarshal_json(http_res.text, errors.CancelServerActivitiesResponseBody)
|
|
out.raw_response = http_res
|
|
raise out
|
|
else:
|
|
content_type = http_res.headers.get('Content-Type')
|
|
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
|
else:
|
|
raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
|
|
|
|
return res
|
|
|
|
|