2020-01-30 14:47:36 +01:00
|
|
|
###############################################################################
|
|
|
|
# This file holds the implementations for all the API clients.
|
|
|
|
#
|
|
|
|
# If you want to develop a new client, here are some suggestions: Get the fetch
|
|
|
|
# methods working first, then the push, then the liquidsoap notifier. You will
|
|
|
|
# probably want to create a script on your server side to automatically
|
|
|
|
# schedule a playlist one minute from the current time.
|
|
|
|
###############################################################################
|
|
|
|
import logging
|
2021-06-03 15:20:39 +02:00
|
|
|
|
2022-02-22 18:19:16 +01:00
|
|
|
from ._config import Config
|
2022-07-22 12:49:21 +02:00
|
|
|
from ._utils import RequestProvider
|
2020-01-30 14:47:36 +01:00
|
|
|
|
|
|
|
LIBRETIME_API_VERSION = "2.0"
|
2022-03-04 14:00:14 +01:00
|
|
|
|
2020-01-30 14:47:36 +01:00
|
|
|
|
|
|
|
api_endpoints = {}
|
|
|
|
|
2021-05-27 16:23:02 +02:00
|
|
|
api_endpoints["version_url"] = "version/"
|
|
|
|
api_endpoints["schedule_url"] = "schedule/"
|
|
|
|
api_endpoints["webstream_url"] = "webstreams/{id}/"
|
|
|
|
api_endpoints["show_instance_url"] = "show-instances/{id}/"
|
|
|
|
api_endpoints["show_url"] = "shows/{id}/"
|
|
|
|
api_endpoints["file_url"] = "files/{id}/"
|
|
|
|
api_endpoints["file_download_url"] = "files/{id}/download/"
|
|
|
|
|
2020-01-30 14:47:36 +01:00
|
|
|
|
2022-07-22 13:27:16 +02:00
|
|
|
class ApiClient:
|
2022-02-22 18:19:16 +01:00
|
|
|
API_BASE = "/api/v2"
|
|
|
|
|
2022-06-06 17:10:44 +02:00
|
|
|
def __init__(self, logger=None, config_path="/etc/libretime/config.yml"):
|
2022-02-22 18:19:16 +01:00
|
|
|
self.logger = logger or logging
|
|
|
|
|
|
|
|
config = Config(filepath=config_path)
|
|
|
|
self.base_url = config.general.public_url
|
|
|
|
self.api_key = config.general.api_key
|
2020-01-30 14:47:36 +01:00
|
|
|
|
2022-02-22 18:19:16 +01:00
|
|
|
self.services = RequestProvider(
|
|
|
|
base_url=self.base_url + self.API_BASE,
|
|
|
|
api_key=self.api_key,
|
|
|
|
endpoints=api_endpoints,
|
|
|
|
)
|
2020-01-30 14:47:36 +01:00
|
|
|
|
2021-08-20 13:35:33 +02:00
|
|
|
def update_file(self, file_id, payload):
|
|
|
|
data = self.services.file_url(id=file_id)
|
|
|
|
data.update(payload)
|
|
|
|
return self.services.file_url(id=file_id, _put_data=data)
|