项目作者: cp6

项目描述 :
Featured packed PHP class for BunnyCDN pull and storage zone API
高级语言: PHP
项目地址: git://github.com/cp6/BunnyCDN-API.git
创建时间: 2019-11-23T05:24:55Z
项目社区:https://github.com/cp6/BunnyCDN-API

开源协议:

下载


BunnyNET CDN API Class

The most comprehensive, feature-packed and easy to use PHP class for bunny.net (
BunnyCDN) pull, video streaming, DNS and storage zones API.

This class whilst having a main focus on storage zone interaction includes pull zone features, DNS, Video streaming and
more. Combining API with FTP managing and using your BunnyNet storage zones just got easier.

Generic badge
Generic badge

Table of contents

1.9.7 changes

14th May 2024

  • Fixed dirSize() needing a slash
  • Fixed createFolder() throwing warning messages
  • Added fileExists()

Requirements

  • PHP 8.2

For Pull zone, billing and statistics API interaction you will need your BunnyNet API key, this is found in your
dashboard in the My Account section.

The video streaming API you need the video stream library access key which is found in the settings for the library at
bunny.net.

If you want to interact with storage zones you will need your BunnyCDN API key set and the name of the storage zone.

You can get this with listStorageZones() as it returns all the storage zone data/info for the account.

Features & abilities

  • List storage zones
  • Add/create storage zone
  • Delete storage zone
  • Create folder in storage zone
  • Delete folder in storage zone
  • Delete file in storage zone
  • Delete all files in a folder in storage zone
  • Download a file from storage zone
  • Download a file from storage zone with progress percentage
  • Download all files in a folder from storage zone
  • Upload file to storage zone
  • Upload file to storage zone with progress percentage
  • Upload all files in a folder to storage zone
  • Rename file or folder in storage zone
  • Move file in storage zone
  • Get file size in storage zone
  • Get directory size in storage zone
  • Navigate/List directories in storage zone
  • List all from storage zone directory
  • List all files formatted from storage zone directory
  • List all folders formatted from storage zone directory
  • List all formatted from storage zone directory
  • Create, edit and delete videos
  • Create, edit and delete DNS zones
  • Get usage statistics
  • Get billing data
  • View balance
  • View monthly charge
  • View monthly charge breakdown
  • Apply coupon code
  • List pull zones
  • Get pull zone
  • Add pull zone
  • Update pull zone
  • Delete pull zone
  • Purge pull zone
  • Add hostname to pull zone
  • Remove hostname from pull zone
  • Set force SSL for pull zone
  • List pull zone HTTP access logs
  • Calculate costs

Usage

Install with composer:

  1. composer require corbpie/bunny-cdn-api

Use like:

  1. require __DIR__ . '/vendor/autoload.php';
  2. use Corbpie\BunnyCdn\BunnyAPIPull;
  3. $bunny = new BunnyAPIPull();//Initiate the class
  4. echo $bunny->listPullZones();

Setting API key:


option 1 (preferred)

Line 12 bunnyAPI.php

  1. const API_KEY = 'XXXX-XXXX-XXXX';

option 2

With apiKey() (needs setting with each calling of class)

  1. $bunny->apiKey('XXXX-XXXX-XXXX');//Bunny api key

Storage zone interaction

  1. require __DIR__ . '/vendor/autoload.php';
  2. use Corbpie\BunnyCdn\BunnyAPIStorage;
  3. $bunny = new BunnyAPIStorage();

Storage zone name and access key for storage zone interaction (not needed if just using pull zone functions)

Set $access_key = '' to obtain key automatically (storage name must be accurate)

  1. $bunny->zoneConnect($storagename, $access_key);

$storagename name of storage zone string

$access_key key/password to storage zone string optional


List storage zones

  1. $bunny->listStorageZones();

returns array


Add a storage zone

  1. $bunny->addStorageZone($newstoragezone);

$newstoragezone name of storage zone to create string


Delete a storage zone

  1. $bunny->deleteStorageZone($id);

$id id of storage zone to delete int


Get directory size

  1. $dir = "media/images/dogs";
  2. $bunny->dirSize($dir);

$dir directory to get size of string


Return current directory

  1. $bunny->currentDir();

returns string


Change directory

  1. $dir = "media/images/dogs";
  2. $bunny->changeDir($dir);

$dir directory navigation (FTP rules) string


Check folder exists

  1. $bunny->folderExists($path);

$path the folder path string

Returns bool


Check file exists

  1. $file = "media/images/dogs/collie.jpg";
  2. $bunny->fileExists($file);

$file the full file path including the filename string

Returns bool


Move to the parent directory

  1. $bunny->moveUpOne();

Create a folder in the current directory

  1. $new_folder = "dogs"
  2. $bunny->createFolder($new_folder);

$new_folder Create a folder in the current directory string


Delete folder

  1. $bunny->deleteFolder($folder_name);

$folder_name Name of the folder to delete (folder must be empty) string


Delete a file

  1. $bunny->deleteFile($name);

$name Name of file to delete string


Delete all files in a folder

  1. $bunny->deleteAllFiles($dir);

$dir Directory to delete all files in string


Rename a file

BunnyCDN does not allow for ftp_rename so file copied to a new name and then the old file is deleted.

  1. $directory = "media/images/dogs";
  2. $old_file_name = "collie.jpg";
  3. $new_file_name = "poodle.jpg";
  4. $bunny->renameFile($directory, $old_file_name, $new_file_name);

$directory Directory that contains the file string

$old_name Object that is being renamed string

$new_name New name for object string


Move a file

  1. $bunny->moveFile($file, $move_to);

$file File to move string

$move_to Directory to move file to string


Download a file

  1. $bunny->downloadFile($save_as, $get_file, $mode);

$save_as Save file as string

$get_file File to download string

$mode FTP mode to use INT


Download all files in a directory

  1. $bunny->downloadAll($dir_dl_from, $dl_into, $mode);

$dir_dl_from Directory to download all from string

$dl_into Download into string

$mode FTP mode to use INT


Upload a file

  1. $bunny->uploadFile($upload, $upload_as, $mode);

$upload File to upload string

$upload_as Upload as string

$mode FTP mode to use INT


Upload all files from a local folder

  1. $bunny->uploadAllFiles($dir, $place, $mode);

$dir Upload all files from this directory string

$place Upload to string

$mode FTP mode to use INT


Return storage zone files and folder data (Original)

  1. $bunny->listAllOG();

returns array


Return storage zone directory files formatted

  1. $bunny->listFiles($location);

$location Directory to get and return data string

returns array


Return storage zone directory folders formatted

  1. $bunny->listFolders($location);

$location Directory to get and return data string

returns array


Return storage zone directory file and folders formatted

  1. $bunny->listAll($location);

$location Directory to get and return data string

returns array




List all pull zones and data

  1. $bunny->listPullZones();

returns array



List pull zones data for id

  1. $bunny->pullZoneData($id);

$id Pull zone to get data from int

returns array



Purge pull zone data

  1. $bunny->purgePullZone($id);

$id Pull zone to purge int



Delete pull zone data

  1. $bunny->deletePullZone($id);

$id Pull zone to delete int



Lists pullzone hostnames and amount

  1. $bunny->pullZoneHostnames($pullzone_id);


Add hostname to pull zone

  1. $bunny->addHostnamePullZone($id, $hostname);

$id Pull zone hostname will be added to int

$hostname Hostname to add string



Remove a hostname from pull zone

  1. $bunny->removeHostnamePullZone($id, $hostname);

$id Pull zone hostname be removed from int

$hostname Hostname to remove string



Change force SSL status for pull zone

  1. $bunny->forceSSLPullZone($id, $hostname, $force_ssl);

$id Pull zone hostname change status int

$hostname Affected hostname string

$force_ssl True = on, FALSE = off bool



Add ip to block for pullzone

  1. $bunny->addBlockedIpPullZone($pullzone_id, $ip, $db_log = false);


Un block an ip for pullzone

  1. $bunny->unBlockedIpPullZone($pullzone_id, $ip, $db_log = false);


List all blocked ip’s for pullzone

  1. $bunny->listBlockedIpPullZone($pullzone_id);


Purge cache for a URL

  1. $bunny->purgeCache($url, $async = false);

$url Purge cache for this url string

$async Dont wait for the purge before returning result bool



Pull zone logs as formatted array

  1. $bunny->pullZoneLogs($id, $date);

$id Pull zone id int

$date Date for logs, only past 3 days (mm-dd-yy) string


Get usage statistics

  1. $bunny->getStatistics();

returns array


Get billing data

  1. $bunny->getBilling();

returns array


Get account balance

  1. $bunny->balance();

returns float


Get monthly charge

  1. $bunny->monthCharges();

returns float


Get monthly charge breakdown for region

  1. $bunny->monthChargeBreakdown();

returns array


Lists total billing amount and first date time

  1. $bunny->totalBillingAmount();

returns array


Apply a coupon code

  1. $bunny->applyCoupon($code);

Set Json header

  1. $bunny->jsonHeader();

Convert/format bytes to other data types

  1. $bunny->convertBytes($bytes, $convert_to = 'GB', $format = true, $decimals = 2);

Convert bool to int value

  1. $bunny->boolToInt($bool);

returns int


Close connection (Optional)

  1. $bunny->closeConnection();

Video streaming zone interaction

Calling and setting stream library access key

  1. require __DIR__ . '/vendor/autoload.php';
  2. use Corbpie\BunnyCdn\BunnyAPIStream;
  3. $bunny = new BunnyAPIStream();
  4. $bunny->streamLibraryAccessKey('XXXX-XXXXX-XXXX-XXXX');
  5. //Or set stream library access key at line 14 in BunnyAPI.php

You can only get the video library id from your bunny.net stream library page

Set video stream library id

  1. $bunny->setStreamLibraryId($library_id);

$library_id stream library id int


Get video collections

Requires setStreamLibraryId() to be set.

  1. $bunny->getVideoCollections();

Set video collection guid

  1. $bunny->setStreamCollectionGuid($collection_guid);

$collection_guid video collection guid string


Set video guid

  1. $bunny->setStreamVideoGuid($video_guid);

$video_guid video guid string



Get video collections for library id

Requires setStreamLibraryId() to be set.

  1. $bunny->getStreamCollections($page, $items_pp,$order_by);

$page page number int

$items_pp items to show int

$order_by order by string



Get streams for a collection

Requires setStreamLibraryId() and setStreamCollectionGuid() to be set.

  1. $bunny->getStreamForCollection();


Update stream collection

Requires setStreamLibraryId() and setStreamCollectionGuid() to be set.

  1. $bunny->updateCollection($updated_collection_name);

$updated_collection_name the name to update video collection to string



Delete stream collection

Requires setStreamLibraryId() and setStreamCollectionGuid() to be set.

  1. $bunny->deleteCollection();


Create stream collection

Requires setStreamLibraryId() to be set.

  1. $bunny->createCollection($new_collection_name);

$new_collection_name the name for your new video collection string



List videos for library

Requires setStreamLibraryId() to be set.

  1. $bunny->listVideos($collection_guid);

$collection_guid video collection guid string



Get video information

Requires setStreamLibraryId() to be set.

  1. $bunny->getVideo($collection_guid);

$collection_guid video collection guid string



Delete video

Requires setStreamLibraryId() to be set.

  1. $bunny->deleteVideo($collection_guid);

$library_id library id int

$collection_guid video collection guid string



Create video

Requires setStreamLibraryId() to be set.

  1. $bunny->createVideo($video_title);

$video_title video title string



Create video for collection

Requires setStreamLibraryId() and setStreamCollectionGuid() to be set.

  1. $bunny->createVideoForCollection($video_title);

$video_title video title string



Upload video

Requires setStreamLibraryId() to be set.

Need to use createVideo() first to get video guid

  1. $bunny->uploadVideo($video_guid, $video_to_upload);

$video_guid video guid string

$video_to_upload video filename string



Set thumbnail for video

Requires setStreamLibraryId() to be set.

  1. $bunny->setThumbnail($video_guid, $thumbnail_url);

$video_guid video guid string

$thumbnail_url image url string



Get video resolutions

Requires setStreamLibraryId() to be set.

  1. $bunny->videoResolutionsArray($video_guid);


Get video size

Requires setStreamLibraryId() to be set.

  1. $bunny->videoSize($video_guid);


Add captions

Requires setStreamLibraryId() to be set.

  1. $bunny->addCaptions($video_guid, $collection_guid, $label, $captions_file);

$video_guid video guid string

$srclang caption srclang string

$label label for captions string

$captions_file caption file URL string



Delete captions

Requires setStreamLibraryId() to be set.

  1. $bunny->deleteCaptions($library_id, $video_guid, $srclang);

$video_guid video guid string

$srclang captions srclang string


DNS zone interaction

  1. require __DIR__ . '/vendor/autoload.php';
  2. use Corbpie\BunnyCdn\BunnyAPIDNS;
  3. $bunny = new BunnyAPIDNS();


Get DNS all zones

  1. $bunny->getDNSZones();

$library_id stream library id int



Get DNS zone

  1. $bunny->getDNSZone($zone_id);

$zone_id DNS zone id int



Add a DNS zone

  1. $bunny->addDNSZone($domain, $logging);

$domain domain name string
$logging use logging bool



Add a DNS zone full

  1. $parameters = array(
  2. 'Domain' => 'zonedomain.com', 'NameserversDetected' => true, 'CustomNameserversEnabled' => true,
  3. 'Nameserver1' => 'customns1.com', 'Nameserver2' => 'customns2.com', 'SoaEmail' => 'contact@zonedomain.com',
  4. 'DateModified' => '2022-08-18 23:59:59', 'DateCreated' => '2022-08-18 23:59:59', 'NameserversNextCheck' => '2022-08-28 23:59:59',
  5. 'LoggingEnabled' => true, 'LoggingIPAnonymizationEnabled' => true
  6. );
  7. $bunny->addDNSZoneFull($parameters);

$parameters parameters to create array



Delete DNS zone

  1. $bunny->deleteDNSZone($zone_id);

$zone_id DNS zone id int



DNS zone statistics

  1. $bunny->getDNSZoneStatistics($zone_id);

$zone_id DNS zone id int



Update DNS nameservers

  1. $bunny->updateDNSZoneNameservers($zone_id, $custom_ns, $ns_one, $ns_two);

$zone_id DNS zone id int
$custom_ns use custom nameservers bool
$ns_one NS one string
$ns_two NS two string



Update DNS SOA email

  1. $bunny->updateDNSZoneNameservers($zone_id, $soa_email);

$zone_id DNS zone id int
$soa_email NS one string



Add a DNS record by using parameters https://docs.bunny.net/reference/dnszonepublic_addrecord

  1. $parameters = array('Type' => 0, 'Ttl' => 120, 'Accelerated' => true, 'Weight' => 200);
  2. $bunny->addDNSRecord($zone_id, $name, $value, $parameters);

$zone_id DNS zone id int
$name name string
$value IP address string
$parameters array



Add DNS A record

  1. $bunny->addDNSRecordA($zone_id, $hostname, $ipv4);

$zone_id DNS zone id int
$hostname hostname string
$ipv4 IPv4 address string



Add DNS AAAA record

  1. $bunny->addDNSRecordAAAA($zone_id, $hostname, $ipv6);

$zone_id DNS zone id int
$hostname hostname string
$ipv6 IPv6 address string



Add DNS CNAME record

  1. $bunny->addDNSRecordCNAME($zone_id, $hostname, $target);

$zone_id DNS zone id int
$hostname hostname string
$target string



Add DNS MX record

  1. $bunny->addDNSRecordMX($zone_id, $hostname, $mail, $priority);

$zone_id DNS zone id int
$hostname hostname string
$mail mail server string
$priority int



Add DNS TXT record

  1. $bunny->addDNSRecordTXT($zone_id, $hostname, $content);

$zone_id DNS zone id int
$hostname hostname string
$content txt contents string



Add DNS NS record

  1. $bunny->addDNSRecordNS($zone_id, $hostname, $target);

$zone_id DNS zone id int
$hostname hostname string
$target string



Add DNS redirect

  1. $bunny->addDNSRecordRedirect($zone_id, $hostname, $url);

$zone_id DNS zone id int
$hostname hostname string
$url redirect to string



Update DNS A record

  1. $bunny->updateDNSRecordA($zone_id, $dns_id, $hostname, $ipv4);

$zone_id DNS zone id int
$dns_id DNS record id int
$hostname hostname string
$ipv4 ipv4 address string



Update DNS AAAA record

  1. $bunny->updateDNSRecordAAAA($zone_id, $dns_id, $hostname, $ipv6);

$zone_id DNS zone id int
$dns_id DNS record id int
$hostname hostname string
$ipv6 ipv6 address string



Disable DNS record

  1. $bunny->disableDNSRecord($zone_id, $dns_id);

$zone_id DNS zone id int
$dns_id DNS record id int



Enable DNS record

  1. $bunny->enableDNSRecord($zone_id, $dns_id);

$zone_id DNS zone id int
$dns_id DNS record id int



Delete DNS record

  1. $bunny->deleteDNSRecord($zone_id, $dns_id);

$zone_id DNS zone id int
$dns_id DNS record id int