Skip to main content

Create Event Preset

Description

The create_event_preset function is responsible for creating a new event preset by sending a POST request to the web service. It accepts an event preset, event type, and event parameters, and constructs the appropriate JSON payload based on the event type. The function returns the HTTP response code and response message, indicating the result of the operation.

Function Signature:

def create_event_preset(ws_config: WebServiceConfig, event_preset: Model.EventPreset, event_type: Model.EventType, event_parameters: Model.RecordingArgs | Model.RTMPArgs | Model.ConferenceArgs) -> tuple[int, str]:

Parameters

  • ws_config (WebServiceConfig): Configuration object containing the base URL and other settings for the web service.
  • event_preset (Model.EventPreset): The event preset object that contains the details to be created.
  • event_type (Model.EventType): The type of event being created (e.g., Start Recording, Stop Recording, Start RTMP, Stop RTMP, Join Conference, Leave Conference).
  • event_parameters (Model.RecordingArgs | Model.RTMPArgs | Model.ConferenceArgs): Event-specific parameters that will be serialized to JSON, depending on the event type.

Returns

  • tuple[int, str]: A tuple containing:
    • response_code: The HTTP response code returned by the web service (e.g., 200 for success).
    • response_string: The response message or error description from the web service.

Example Usage

ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
event_preset = Model.EventPreset(id=1, name="Preset 1")
event_type = Model.EventType.Video.Start_recording
event_parameters = Model.RecordingArgs(param1="value1", param2="value2")

response_code, response_string = create_event_preset(ws_config, event_preset, event_type, event_parameters)
print(response_code)
print(response_string)

Behavior

  • Sends a POST request to the server to create a new event preset with the specified parameters.
  • The event parameters are serialized to JSON based on the event type and assigned to the event preset.
  • The response from the server is captured, including the HTTP status code and response content.
  • Returns a tuple with the response code and response message.

Error Handling

  • Invalid Event Type: If an invalid event type is provided, a ValueError is raised, and the error is handled.
  • General Exception: Any other errors during the request or processing are caught and logged, and a descriptive error message is returned.