diff --git a/src/BunnyAPI.php b/src/BunnyAPI.php index cd85c24..96492c1 100644 --- a/src/BunnyAPI.php +++ b/src/BunnyAPI.php @@ -13,6 +13,8 @@ class BunnyAPI protected const HOSTNAME = 'storage.bunnycdn.com';//FTP hostname private const STREAM_LIBRARY_ACCESS_KEY = 'XXXX-XXXX-XXXX'; protected string $api_key; + + protected string $stream_library_access_key; protected string $access_key; protected $connection; private array $data; @@ -26,6 +28,9 @@ public function __construct() throw new BunnyAPIException("You must provide an API key"); } $this->api_key = self::API_KEY; + if (!isset($this->stream_library_access_key)) { + $this->stream_library_access_key = self::STREAM_LIBRARY_ACCESS_KEY; + } } catch (BunnyAPIException $e) {//display error message echo $e->errorMessage(); } @@ -43,6 +48,18 @@ public function apiKey(string $api_key = ''): void } } + public function streamLibraryAccessKey(string $stream_library_access_key = ''): void + { + try { + if (!isset($stream_library_access_key) || trim($stream_library_access_key) === '') { + throw new BunnyAPIException('$stream_library_access_key cannot be empty'); + } + $this->stream_library_access_key = $stream_library_access_key; + } catch (BunnyAPIException $e) {//display error message + echo $e->errorMessage(); + } + } + protected function constApiKeySet(): bool { return !(!defined("self::API_KEY") || empty(self::API_KEY)); @@ -88,8 +105,10 @@ protected function APIcall(string $method, string $url, array $params = [], stri curl_setopt($curl, CURLOPT_HTTPHEADER, array("AccessKey: $this->access_key")); } else {//Video stream curl_setopt($curl, CURLOPT_URL, self::VIDEO_STREAM_URL . $url); - curl_setopt($curl, CURLOPT_HTTPHEADER, array("AccessKey: " . self::STREAM_LIBRARY_ACCESS_KEY, "Content-Type: application/*+json")); - curl_setopt($curl, CURLOPT_POSTFIELDS, file_get_contents($params['file'])); + curl_setopt($curl, CURLOPT_HTTPHEADER, array("AccessKey: " . $this->stream_library_access_key, "Content-Type: application/*+json")); + if ($method === "PUT") { + curl_setopt($curl, CURLOPT_POSTFIELDS, file_get_contents($params['file'])); + } } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);