All Projects → SociallyDev → Spaces Api

SociallyDev / Spaces Api

Licence: mit
An API wrapper for DigitalOcean's Spaces object storage designed for easy use.

Projects that are alternatives of or similar to Spaces Api

Tlaw
The Last API Wrapper: Pragmatic API wrapper framework
Stars: ✭ 112 (-32.53%)
Mutual labels:  api, wrapper
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-27.11%)
Mutual labels:  api, wrapper
Ovoid
Un-Official OVO API Wrapper
Stars: ✭ 121 (-27.11%)
Mutual labels:  api, wrapper
Binance.api.csharp.client
C#.NET client for Binance Exchange API.
Stars: ✭ 98 (-40.96%)
Mutual labels:  api, wrapper
Python Twitch Client
Python wrapper for Twitch API
Stars: ✭ 137 (-17.47%)
Mutual labels:  api, wrapper
Typhoon
Minimal and free Kubernetes distribution with Terraform
Stars: ✭ 1,397 (+741.57%)
Mutual labels:  aws, digitalocean
Kayn
superagent-inspired Node.js lib (w/ **some** TypeScript support) for accessing Riot's League of Legend's API (discord: cnguy#3614)
Stars: ✭ 122 (-26.51%)
Mutual labels:  api, wrapper
S3 Beam
🚀 direct-to-S3 uploading using ClojureScript
Stars: ✭ 91 (-45.18%)
Mutual labels:  aws, digitalocean
Generate Ssh Configs
Automatically generate ssh config files for your cloud servers
Stars: ✭ 136 (-18.07%)
Mutual labels:  aws, digitalocean
Mastodonkit
MastodonKit is a Swift Framework that wraps Mastodon's API
Stars: ✭ 134 (-19.28%)
Mutual labels:  api, wrapper
Discord.jl
The Julia Discord API Wrapper
Stars: ✭ 93 (-43.98%)
Mutual labels:  api, wrapper
Learn Devops
🚧 Learn the craft of "DevOps" (Developer Operations) to Deploy your App and Monitor it so it stays "Up"!
Stars: ✭ 139 (-16.27%)
Mutual labels:  aws, digitalocean
Spotify Web Api Js
A client-side JS wrapper for the Spotify Web API
Stars: ✭ 1,313 (+690.96%)
Mutual labels:  api, wrapper
Json Serverless
Transform a JSON file into a serverless REST API in AWS cloud
Stars: ✭ 108 (-34.94%)
Mutual labels:  api, aws
Apipeline
Feature-rich and pluggable offline-first API wrapper for all your javascript environements ! Easily wire-up your API and make your app work offline in minutes.
Stars: ✭ 92 (-44.58%)
Mutual labels:  api, wrapper
Cluster.dev
Kubernetes-based Dev Environments with GitOps
Stars: ✭ 122 (-26.51%)
Mutual labels:  aws, digitalocean
Termux
Node.js module for Termux-API
Stars: ✭ 87 (-47.59%)
Mutual labels:  api, wrapper
Black.box
Plug-and-Play VPN router and unblocker
Stars: ✭ 89 (-46.39%)
Mutual labels:  aws, digitalocean
Covid 19 Api
This is the code running in AWS Lambda powering covid-api.mmediagroup.fr/v1. The API provides realtime and historical data on Coronavirus COVID-19 confirmed cases, deaths, and recovered cases. This API has now been called over 3 million times, thank you!
Stars: ✭ 122 (-26.51%)
Mutual labels:  api, aws
Mailjet Apiv3 Nodejs
[API v3] Official Mailjet API v3 NodeJS wrapper
Stars: ✭ 137 (-17.47%)
Mutual labels:  api, wrapper

Spaces-API

Makes using DigitalOcean's Spaces object storage super easy.  

  • Makes everything super simple.
  • Automatically handles multipart & stream uploads for large files.
  • Uses Spaces terminology for objects instead of S3.

 

Example

Create a Space & upload, it's as easy as that.

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Upload some text.
$my_space->upload("Super cool content", "example.txt");

//Uploaded!

tl;dr

 

Installing Spaces-API

There are two ways to install Spaces-API. You can either download the project & put it directly in your code's folder, or you can use Composer.

 

a) The Manual Method

  1. Download Spaces-API & place it in your project.
  2. Load it from your code:
require_once("spaces.php");

 

b) The Composer Method

  1. Make sure you have Composer.
  2. Install Spaces-API:
composer require sociallydev/spaces-api:v2
  1. Make sure your code has the Composer autoloader:
require_once("vendor/autoload.php");

 

Setup

You'll need a DigitalOcean account & API keys to use Spaces-API. You should be able to generate a pair of keys from the DigitalOcean Dashboard. In the API page, there should be a section with the title "Spaces access keys". Click "Generate New Key" & follow the steps. That'll give you an access key & a secret key.

We'll be using these keys to initiate a Spaces instance:

$spaces = Spaces("ACCESS KEY", "SECRET KEY");

 

Usage

Once you have a Spaces instance, you can do pretty much anything the Spaces API allows.

Here is an example of downloading all your files to a local directory:

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Download entire Space to a directory.
$my_space->downloadToDirectory("local_backup");

       

Spaces-API

 

Top-Level Spaces Functions

These are all the functions a Spaces instance can perform.

 

Create a new Space

$spaces = Spaces("ACCESS KEY", "SECRET KEY");

//Creates a new Space.
$spaces->create("my-new-space", "nyc3", "private");
  • The third (Space privacy) argument is optional. Defaults to private.
  • Returns a new single Space instance. Same as $spaces->space("my-new-space").

 

Use an existing Space

$spaces = Spaces("ACCESS KEY", "SECRET KEY");

//Get an existing Space.
$my_space = $spaces->space("my-space", "nyc3");

 

List all Spaces

$spaces = Spaces("ACCESS KEY", "SECRET KEY");

//Returns an array of all available Spaces.
$spaces->listSpaces();

 


 

Single Space Functions

These are all the functions a Space instance (From $spaces->space("my-new-space")) can perform!

 

Upload a stored file

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Upload a local stored file.
$my_space->uploadFile("path/to/my/file.txt", "path/on/space.txt", "private");
  • The second (Save as) argument is optional. Spaces-API attempts to use the original file path as the path on your Space if no save as path is provided.
  • The third argument (File privacy) is optional. It defaults to private.
  • Returns available info on the file.

 

Upload text directly

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Upload a local stored file.
$my_space->upload("my content", "path/on/space.txt", "private");
  • The first argument (Content) can be a string, but it can also be a StreamInterface or PHP stream resource.
  • The third argument (File privacy) is optional. It defaults to private.
  • Returns available info on the file.

 

Upload a local folder

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Uploads an entire local directory.
$my_space->uploadDirectory("my-local-folder");
  • You can provide a second argument which can be a folder inside your Space where to upload all the files inside the local folder.

 

Download a file

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns the file content as result.
$content = $my_space->downloadFile("my-file.txt");

//Saves the file content to the local path, and returns file info.
$info = $my_space->downloadFile("my-file.txt", "save-path/file.txt");

 

Download your Space to a local folder

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Uploads an entire local directory.
$my_space->downloadToDirectory("my-local-folder");
  • You can provide a second argument which can be a folder on your Space. Spaces-API will only download the files inside this folder.

 

Copy a file inside your Space

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Copies the file to the same Space.
$my_space->copyFile("my-file.txt", "my-new-file.txt");

//Copies the file to another Space.
$my_space->copyFile("my-file.txt", "my-new-file.txt", "my-other-space");
  • DigitalOcean only allows copying across Spaces in the same region.
  • You can supply a fourth argument to set the new file's privacy (public/private).
  • Returns info on the new file.

 

List all files inside your Space

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Lists all files inside your Space.
$my_space->listFiles();

//Lists all files in a folder inside your Space.
$my_space->listFiles("my-folder");
  • This function automatically iterates till it gets all files but you can set the second argument to false if you want to handle pagination yourself.
  • If you set the second argument to false, you can set the third argument to a ContinuationToken.
  • Returns an array of files but if the second argument is set to false, the original object is returned.

 

Check whether a file exists

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns true if this file exists, otherwise false.
$my_space->fileExists("my-file.txt");

 

Get info on a file

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns all available data on a file.
$my_space->fileInfo("my-file.txt");

 

Create a signed URL (Used for sharing private files)

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns a URL that'll work for 15 minutes for this file.
$my_space->signedURL("my-file.txt", "15 minutes");

 

Create an unsigned URL (Used for sharing public files)

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns a URL that'll work as long as the file is public.
$my_space->url("my-file.txt");

 

Change a file's privacy (Public & Private ACL)

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Make a file public.
$my_space->filePrivacy("my-file.txt", "public");

//Make a file private.
$my_space->filePrivacy("my-file.txt", "private");

 

Delete a file

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Deletes a single file.
$my_space->deleteFile("my-file.txt");

 

Delete an entire folder

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Deletes all content of a folder (Or any file paths that match the provided check string).
$my_space->deleteFolder("my-folder");

 

Change your Space's privacy (ACL)

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Makes your Space public. All your Space's files will be displayed to anyone.
$my_space->privacy("public");

//Makes your Space private.
$my_space->privacy("private");

 

List your Space's CORS rules

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns an array of your Space's CORS rules.
$my_space->getCORS();
  • This will throw an error if no CORS rules exist.

 

Set your Space's CORS rules

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//This allows all sources to use your file.
$my_space->setCORS([["origins" => ["*"], "methods" => ["GET", "HEAD", "OPTIONS"]]]);

 

Destroy your Space

Also deletes all files inside your Space

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Destroys your Space & deletes all its files.
$my_space->destroy();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].