mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2024-11-21 09:40:09 -08:00
2.4 KiB
2.4 KiB
Examples
Connecting to Digital Ocean and selecting a space
use SpacesAPI\Spaces;
$spaces = new Spaces('api-key', 'api-secret');
$space = $spaces->space('space-name');
API docs for \SpacesAPI\Spaces
Creating a new space
$spaces = new Spaces('api-key', 'api-secret');
$space = $spaces->create('new-space-name');
Listing files
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$files = $space->listFiles();
foreach ($files['files'] as $file) {
echo "{$file->filename}\n";
}
Uploading a file
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$file = $space->uploadFile('./localfile.txt', 'remote-filename.txt');
Uploading text to a file
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$file = $space->uploadText('Lorem ipsum', 'remote-filename.txt');
Downloading a file
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->download('./localfile.txt');
API docs for downloading a file
Get the contents of a file
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
echo $space->file('filename.txt')->getContents();
API docs for getting the contents of a file
Deleting a file
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->delete();
Get a public URL
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->getURL();
API docs for getting the public URL
Get a signed URL
a time limited link to provide access to a private file
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->getSignedURL("1 day");
API docs for getting a signed URL
Make a file publicly accessible
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->makePublic();