2017 © Pedro Peláez
 

library spaces-api

composer package for SociallyDev's awesome Spaces-Api project

image

jtbairdsr/spaces-api

composer package for SociallyDev's awesome Spaces-Api project

  • Monday, January 29, 2018
  • by jtbairdsr
  • Repository
  • 0 Watchers
  • 0 Stars
  • 88 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Spaces-API

An API wrapper for DigitalOcean's Spaces object storage designed for easy use., (*1)

Installation

> composer require jtbairdsr/spaces-api @dev

Connecting

require_once 'vendor/autoload.php';

$key = "EXAMPLE_KEY";
$secret = "EXAMPLE_SECRET";

$space_name = "my-space";
$region = "nyc3";

$space = new SpacesConnect($key, $secret, $space_name, $region);

All available options:, (*2)

SpacesConnect(REQUIRED KEY, REQUIRED SECRET, OPTIONAL SPACE's NAME, OPTIONAL REGION, OPTIONAL HOST);

 , (*3)

Uploading/Downloading Files

$path_to_file = "image.png";

$space->uploadFile($path_to_file, "public");



$download_file = "image.png";
$save_as = "folder/downloaded-image.png";

$space->downloadFile($download_file, $save_as);

All available options:, (*4)

uploadFile(REQUIRED PATH TO FILE, OPTIONAL PRIVACY (public|private) OPTIONAL NAME TO SAVE FILE AS);
downloadFile(REQUIRED FILE TO DOWNLOAD, REQUIRED LOCATION TO SAVE IN);

 , (*5)

Changing Privacy Settings

$file = "image.png";

$space->makePublic($file);
$space->makePrivate($file);

All available options:, (*6)

makePublic(REQUIRED PATH TO FILE);
makePrivate(REQUIRED PATH TO FILE);

 , (*7)

$file = "image.png";
$valid_for = "1 day";

$link = $space->CreateTemporaryURL($file, $valid_for);

All available options:, (*8)

   , (*9)

Other File APIs

//List all files and folders
$files = $space->listObjects();


//Check if a file/folder by that name already exists. True/False.
$space->doesObjectExist($file_name);


//Pull information about a single object.
$file_info = $space->getObject($file_name);


//Delete a file/folder.
$space->deleteObject($file_name);


//Upload a complete directory instead of a single file.
$space->uploadDirectory($path_to_directory, $key_prefix);


//Pull Access Control List information.
$acl = $space-listObjectACL($file_name);


//Update Access Control List information.
$space->PutObjectACL($file_name, $acl_info_array);

         , (*10)

Creating Spaces

$new_space = "my-new-space";

$space->createSpace($new_space);

All available options:, (*11)

createSpace(REQUIRED SPACE NAME, OPTIONAL REGION FOR SPACE);

 , (*12)

Switching Spaces

$new_space = "my-new-space";

$space->setSpace($new_space);

All available options:, (*13)

setSpace(REQUIRED SPACE NAME, OPTIONAL REGION FOR SPACE, OPTIONAL HOST);

   , (*14)

Other Spaces APIs

//List all Spaces available in account.
$spaces = $space->listSpaces();


//Delete a Space.
$space->destroyThisSpace();


//Download whole Space to a folder.
$space->downloadSpaceToDirectory($directory_to_download_to);


//Get the name of the current Space.
$space_name = $space->getSpaceName();


//Pull the CORS policy of the Space.
$cors = $space->listCORS();


//Update the CORS policy of the Space.
$space->putCORS($new_policy);


//Pull the Access Control List information of the Space.
$acl = $space->listSpaceACL();


//Update the Access Control List information of the Space.
$space->PutSpaceACL($new_acl);

Handling Errors

try {
   $space->createSpace("dev");
} catch (\Exception $e) {
  $error = $space->GetError($e);

   //Error management code.
   echo "

<

pre>";
   print_r($error);
   /*
   EG:
   Array (
    [message] => Bucket already exists
    [code] => BucketAlreadyExists
    [type] => client
    [http_code] => 409
   )
   */
}

The Versions

29/01 2018

dev-master

9999999-dev

composer package for SociallyDev's awesome Spaces-Api project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jonathan Baird