Skip to content

Commit

Permalink
Merge pull request #28 from cp6/dev
Browse files Browse the repository at this point in the history
Added $stream_library_access_key and streamLibraryAccessKey()
  • Loading branch information
cp6 committed Oct 11, 2023
2 parents 4b8293d + f772a2f commit d34ab75
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/BunnyAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d34ab75

Please sign in to comment.