Skip to content

FastPix/fastpix-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastPix PHP SDK

Developer-friendly & type-safe PHP SDK specifically designed to leverage the FastPix platform API.

Introduction

The FastPix PHP SDK simplifies integration with the FastPix platform. This SDK is designed for secure and efficient communication with the FastPix API, enabling easy management of media uploads, live streaming, and simulcasting.

Key Features

  • Media API

    • Upload Media: Upload media files seamlessly from URLs or devices
    • Manage Media: Perform operations such as listing, fetching, updating, and deleting media assets
    • Playback IDs: Generate and manage playback IDs for media access
  • Live API

    • Create & Manage Live Streams: Create, list, update, and delete live streams effortlessly
    • Control Stream Access: Generate playback IDs for live streams to control and manage access
    • Simulcast to Multiple Platforms: Stream content to multiple platforms simultaneously

For detailed usage, refer to the FastPix API Reference.

Prerequisites:

  • PHP 7.4 or later
  • Composer package manager
  • FastPix API credentials (Access Token and Secret Key)

Getting started with FastPix:

Table of Contents

SDK Installation

The SDK relies on Composer to manage its dependencies.

To install the SDK first add the below to your composer.json file:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/FastPix/fastpix-php.git"
        }
    ],
    "require": {
        "fastpix/sdk": "*"
    }
}

Then run the following command:

composer update

Initialization

You can set the security parameters through the security builder method when initializing the SDK client instance. For example:

declare(strict_types=1);

require 'vendor/autoload.php';

use FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$sdk = Sdk\FastPix::builder()
    ->setSecurity(
        new Components\Security(
            username: 'your-access-token-id',
            password: 'your-security-key',
        )
    )
    ->build();

SDK Example Usage

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$sdk = Sdk\FastPix::builder()
    ->setSecurity(
        new Components\Security(
            username: 'your-access-token-id',
            password: 'your-security-key',
        )
    )
    ->build();

$request = new Components\CreateLiveStreamRequest(
    playbackSettings: new Components\PlaybackSettings(),
    inputMediaSettings: new Components\InputMediaSettings(
        metadata: new Components\CreateLiveStreamRequestMetadata(),
    ),
);

$response = $sdk->startLiveStream->createNewStream(
    request: $request
);

if ($response->liveStreamResponseDTO !== null) {
    // handle response
}

Available Resources and Operations

Available methods

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default an API error will raise a Errors\APIException exception, which has the following properties:

Property Type Description
$message string The error message
$statusCode int The HTTP status code
$rawResponse ?\Psr\Http\Message\ResponseInterface The raw HTTP response
$body string The response content

When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the createNewStream method throws the following exceptions:

Error Type Status Code Content Type
Errors\UnauthorizedException 401 application/json
Errors\InvalidPermissionException 403 application/json
Errors\ValidationErrorResponse 422 application/json
Errors\APIException 4XX, 5XX */*

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use FastPix\Sdk;
use FastPix\Sdk\Models\Components;
use FastPix\Sdk\Models\Errors;

$sdk = Sdk\FastPix::builder()
    ->setSecurity(
        new Components\Security(
            username: 'your-access-token-id',
            password: 'your-security-key',
        )
    )
    ->build();

try {
    $request = new Components\CreateLiveStreamRequest(
        playbackSettings: new Components\PlaybackSettings(),
        inputMediaSettings: new Components\InputMediaSettings(
            metadata: new Components\CreateLiveStreamRequestMetadata(),
        ),
    );

    $response = $sdk->startLiveStream->createNewStream(
        request: $request
    );

    if ($response->liveStreamResponseDTO !== null) {
        // handle response
    }
} catch (Errors\UnauthorizedExceptionThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\InvalidPermissionExceptionThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\ValidationErrorResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\APIException $e) {
    // handle default exception
    throw $e;
}

Server Selection

Override Server URL Per-Client

The default server can be overridden globally using the setServerUrl(string $serverUrl) builder method when initializing the SDK client instance. For example:

declare(strict_types=1);

require 'vendor/autoload.php';

use FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$sdk = Sdk\FastPix::builder()
    ->setServerURL('https://v1.fastpix.io/live')
    ->setSecurity(
        new Components\Security(
            username: 'your-access-token-id',
            password: 'your-security-key',
        )
    )
    ->build();

$request = new Components\CreateLiveStreamRequest(
    playbackSettings: new Components\PlaybackSettings(),
    inputMediaSettings: new Components\InputMediaSettings(
        metadata: new Components\CreateLiveStreamRequestMetadata(),
    ),
);

$response = $sdk->startLiveStream->createNewStream(
    request: $request
);

if ($response->liveStreamResponseDTO !== null) {
    // handle response
}

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Detailed Usage

For a complete understanding of each API's functionality, including request and response details, parameter descriptions, and additional examples, please refer to the FastPix API Reference.

The API reference provides comprehensive documentation for all available endpoints and features, ensuring developers can integrate and utilize FastPix APIs efficiently.

About

Developer-friendly & type-safe PHP SDK for the FastPix platform API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages