mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-14 02:27:23 -07:00
Version 3 release. Major re-write
This commit is contained in:
parent
127ad7e14a
commit
f9b49002c7
1507 changed files with 6592 additions and 94204 deletions
98
docs/Examples.md
Normal file
98
docs/Examples.md
Normal file
|
@ -0,0 +1,98 @@
|
|||
# Examples
|
||||
|
||||
## Connecting to Digital Ocean and selecting a space
|
||||
|
||||
```php
|
||||
use SpacesAPI\Spaces;
|
||||
|
||||
$spaces = new Spaces('api-key', 'api-secret');
|
||||
$space = $spaces->space('space-name');
|
||||
```
|
||||
[API docs for \SpacesAPI\Spaces](Spaces.md)
|
||||
|
||||
## Creating a new space
|
||||
```php
|
||||
$spaces = new Spaces('api-key', 'api-secret');
|
||||
$space = $spaces->create('new-space-name');
|
||||
```
|
||||
[API docs for creating a space](Spaces.md#spacescreate)
|
||||
|
||||
## Listing files
|
||||
|
||||
```php
|
||||
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
|
||||
$files = $space->listFiles();
|
||||
|
||||
foreach ($files['files'] as $file) {
|
||||
echo "{$file->filename}\n";
|
||||
}
|
||||
```
|
||||
[API docs for listing files](Space.md#spacelistfiles)
|
||||
|
||||
## Uploading a file
|
||||
|
||||
```php
|
||||
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
|
||||
$file = $space->uploadFile('./localfile.txt');
|
||||
```
|
||||
[API docs for uploading files](Space.md#spaceuploadfile)
|
||||
|
||||
## Uploading text to a file
|
||||
```php
|
||||
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
|
||||
$file = $space->uploadText('Lorem ipsum', 'remote-filename.txt');
|
||||
```
|
||||
|
||||
[API docs for uploading text](Space.md#spaceuploadtext)
|
||||
|
||||
## Downloading a file
|
||||
```php
|
||||
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
|
||||
$space->file('filename.txt')->download('./localfile.txt');
|
||||
```
|
||||
|
||||
[API docs for downloading a file](File.md#filedownload)
|
||||
|
||||
## Get the contents of a file
|
||||
|
||||
```php
|
||||
$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](File.md#filegetcontents)
|
||||
|
||||
## Deleting a file
|
||||
```php
|
||||
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
|
||||
$space->file('filename.txt')->delete();
|
||||
```
|
||||
|
||||
[API docs for deleting a file](File.md#filedelete)
|
||||
|
||||
## Get a public URL
|
||||
|
||||
```php
|
||||
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
|
||||
$space->file('filename.txt')->getURL();
|
||||
```
|
||||
|
||||
[API docs for getting the public URL](File.md#filegeturl)
|
||||
|
||||
## Get a signed URL
|
||||
#### a time limited link to provide access to a private file
|
||||
|
||||
```php
|
||||
$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](File.md#filegetsignedurl)
|
||||
|
||||
## Make a file publicly accessible
|
||||
```php
|
||||
$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
|
||||
$space->file('filename.txt')->makePublic();
|
||||
```
|
||||
|
||||
[API docs for setting file privacy](File.md#spacemakeprivate)
|
Loading…
Add table
Add a link
Reference in a new issue