mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-07-05 20:41:31 -07:00
Added array keys for space and file listing
This commit is contained in:
parent
f9b49002c7
commit
cfea1967ab
11 changed files with 41 additions and 27 deletions
10
README.md
10
README.md
|
@ -15,16 +15,24 @@ Obtain API keys from the [Digital Ocean Applications & API dashboard](https://cl
|
|||
```php
|
||||
use SpacesAPI\Spaces;
|
||||
|
||||
// Connect to a space
|
||||
$spaces = new Spaces('api-key', 'api-secret');
|
||||
$space = $spaces->space('space-name');
|
||||
|
||||
// Download a file
|
||||
$file = $space->file('remote-file-1.txt');
|
||||
$file->download('local/file/path/file.txt');
|
||||
|
||||
// Upload text to a file
|
||||
$file2 = $space->uploadText("Lorem ipsum","remote-file-2.txt");
|
||||
|
||||
// Get a signed public link, valid for 2 hours
|
||||
$file2url = $file2->getSignedURL("2 hours");
|
||||
|
||||
// Make a copy
|
||||
$file3 = $file2->copy('remote-file-3.txt');
|
||||
|
||||
// Make a file public and get the URL
|
||||
$file3->makePublic();
|
||||
$file3url = $file3->getURL();
|
||||
```
|
||||
|
@ -32,7 +40,7 @@ $file3url = $file3->getURL();
|
|||
See more examples in [docs/Examples.md](docs/Examples.md)
|
||||
|
||||
## Upgrading?
|
||||
Version 3 has many changes over verison 2, so we have written a [migration guide](docs/Upgrade2-3.md)
|
||||
Version 3 has many changes over version 2, so we have written a [migration guide](docs/Upgrade2-3.md)
|
||||
|
||||
## API reference
|
||||
* [\SpacesAPI\Spaces](docs/Spaces.md)
|
||||
|
|
|
@ -10,6 +10,7 @@ use SpacesAPI\Exceptions\FileDoesntExistException;
|
|||
* You wouldn't normally instantiate this class directly,
|
||||
* Rather obtain an instance from `\SpacesAPI\Space::list()`, `\SpacesAPI\Spaces::file()`, `\SpacesAPI\Spaces::uploadText()` or `\SpacesAPI\Spaces::uploadFile()`
|
||||
*
|
||||
* @property string $filename
|
||||
* @property string $expiration
|
||||
* @property string $e_tag
|
||||
* @property int $last_modified
|
||||
|
|
|
@ -252,16 +252,16 @@ class Space
|
|||
])
|
||||
);
|
||||
|
||||
if (!isset($data['Contents'])) {
|
||||
return ['files' => []];
|
||||
}
|
||||
|
||||
$files = [
|
||||
'files' => $data['Contents'],
|
||||
'files' => [],
|
||||
];
|
||||
|
||||
foreach ($files['files'] as $index => $fileInfo) {
|
||||
$files['files'][$index] = new File($this, $fileInfo['Key'], $fileInfo);
|
||||
if (!isset($data['Contents'])) {
|
||||
return $files;
|
||||
}
|
||||
|
||||
foreach ($data['Contents'] as $fileInfo) {
|
||||
$files['files'][$fileInfo['Key']] = new File($this, $fileInfo['Key'], $fileInfo);
|
||||
}
|
||||
|
||||
if (isset($data["NextContinuationToken"]) && $data["NextContinuationToken"] != "") {
|
||||
|
|
|
@ -61,7 +61,7 @@ class Spaces
|
|||
$spaces = [];
|
||||
|
||||
foreach (Result::parse($this->s3->listBuckets()['Buckets']) as $bucket) {
|
||||
$spaces[] = new Space($this->s3, $bucket['Name']);
|
||||
$spaces[$bucket['Name']] = new Space($this->s3, $bucket['Name']);
|
||||
}
|
||||
|
||||
return $spaces;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "sociallydev/spaces-api",
|
||||
"description": "Library for accessing Digital Ocean spaces",
|
||||
"version":"3.0.0",
|
||||
"version":"3.1.0",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
|
|
14
composer.lock
generated
14
composer.lock
generated
|
@ -4,20 +4,20 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "c76b703f4b3b49f8421bcb693ece4aa8",
|
||||
"content-hash": "77328f11e2ce84c590e531213fe931c6",
|
||||
"packages": [
|
||||
{
|
||||
"name": "aws/aws-sdk-php",
|
||||
"version": "3.187.2",
|
||||
"version": "3.190.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/aws/aws-sdk-php.git",
|
||||
"reference": "0ec4ae120cfae758efa3c283dc56eb20602f094c"
|
||||
"reference": "8ca6a5f9834de3eb3fb84b28fc12c9088bc01293"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/0ec4ae120cfae758efa3c283dc56eb20602f094c",
|
||||
"reference": "0ec4ae120cfae758efa3c283dc56eb20602f094c",
|
||||
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/8ca6a5f9834de3eb3fb84b28fc12c9088bc01293",
|
||||
"reference": "8ca6a5f9834de3eb3fb84b28fc12c9088bc01293",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -92,9 +92,9 @@
|
|||
"support": {
|
||||
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
|
||||
"issues": "https://github.com/aws/aws-sdk-php/issues",
|
||||
"source": "https://github.com/aws/aws-sdk-php/tree/3.187.2"
|
||||
"source": "https://github.com/aws/aws-sdk-php/tree/3.190.2"
|
||||
},
|
||||
"time": "2021-08-04T18:12:21+00:00"
|
||||
"time": "2021-08-13T18:12:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
|
|
|
@ -332,6 +332,7 @@ List all files in the space (recursively)
|
|||
|
||||
`array`
|
||||
|
||||
> An array of `\SpacesAPI\File` instances indexed by the file name
|
||||
|
||||
<hr />
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ List all your spaces
|
|||
|
||||
`array`
|
||||
|
||||
> An array of \SpacesAPI\Space instances
|
||||
> An array of `\SpacesAPI\Space` instances indexed by the space name
|
||||
|
||||
|
||||
<hr />
|
||||
|
|
|
@ -20,7 +20,7 @@ class FileTest extends TestCase
|
|||
$spaces = new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']);
|
||||
|
||||
try {
|
||||
$spaces->space('spaces-api-test')->destroySpace();
|
||||
$spaces->space('spaces-api-test')->destroy();
|
||||
} catch (SpaceDoesntExistException $e) {
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ class FileTest extends TestCase
|
|||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroySpace();
|
||||
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroy();
|
||||
}
|
||||
|
||||
public function testCanUpdatePrivacy()
|
||||
|
|
|
@ -20,7 +20,7 @@ class SpaceTest extends TestCase
|
|||
$spaces = new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']);
|
||||
|
||||
try {
|
||||
$spaces->space('spaces-api-test')->destroySpace();
|
||||
$spaces->space('spaces-api-test')->destroy();
|
||||
} catch (SpaceDoesntExistException $e) {
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ class SpaceTest extends TestCase
|
|||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
// (new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroySpace();
|
||||
// (new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroy();
|
||||
}
|
||||
|
||||
public function testCanUpdateSpacePrivacy()
|
||||
|
@ -102,7 +102,11 @@ class SpaceTest extends TestCase
|
|||
$files = self::$space->listFiles()['files'];
|
||||
$this->assertIsArray($files);
|
||||
$this->assertCount(2, $files);
|
||||
$this->assertInstanceOf(File::class, $files[0]);
|
||||
$this->assertInstanceOf(File::class, $files[array_key_first($files)]);
|
||||
|
||||
foreach ($files as $filename => $file) {
|
||||
$this->assertEquals($file->filename, $filename);
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
|
|
|
@ -17,14 +17,14 @@ class SpacesTest extends TestCase
|
|||
$dotenv->required(['SPACES_KEY', 'SPACES_SECRET']);
|
||||
|
||||
try {
|
||||
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroySpace();
|
||||
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroy();
|
||||
} catch (SpaceDoesntExistException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroySpace();
|
||||
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroy();
|
||||
}
|
||||
|
||||
public function testAuthenticationCanFail()
|
||||
|
@ -68,8 +68,8 @@ class SpacesTest extends TestCase
|
|||
$this->assertIsArray($list);
|
||||
|
||||
$spaceFound = false;
|
||||
foreach ($list as $space) {
|
||||
if ($space->getName() == 'spaces-api-test') {
|
||||
foreach ($list as $name => $space) {
|
||||
if ($name == 'spaces-api-test' && $space->getName() == 'spaces-api-test') {
|
||||
$spaceFound = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue