Skip to content

Commit

Permalink
client accepting same body type as guzzle, readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
dam-bal committed Apr 19, 2024
1 parent 80baa0c commit 3d60177
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
45 changes: 33 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,58 @@ PHP Client for Vercel Blob Storage.
$client = new \VercelBlobPhp\Client();
```

Client constructor accepts token for blob storage, but if you connected your blob storage to project then you don't need to set it.

### Using Client

#### PUT
```php
$result = $client->put(
'test.txt', // path
'hello world' // content,
new \VercelBlobPhp\CommonCreateBlobOptions(
path: 'test.txt', // path
content: 'hello world' // content,
options: new \VercelBlobPhp\CommonCreateBlobOptions(
addRandomSuffix: true, // optional
contentType: 'text', // optional
cacheControlMaxAge: 123, // optional
)
);

// $result is instance of PutBlobResult
$result->url
$result->downloadUrl
$result->pathname
$result->contentType
$result->contentDisposition
```

Third argument is optional.
Options argument is optional.

#### DEL
```php
$client->del(['test.txt']);
```

#### COPY
```php
$result = $client->copy(
fromUrl: 'fromUrl',
toPathname: 'toPathname',
options: new \VercelBlobPhp\CommonCreateBlobOptions(
addRandomSuffix: true, // optional
contentType: 'text', // optional
cacheControlMaxAge: 123, // optional
)
);
```

#### HEAD
```php
$result = $client->head('url');
```

#### LIST
```php
$result = $client->list(
options: new \VercelBlobPhp\ListCommandOptions(
limit: 100, // optional
cursor: 'cursor', // optional
mode: \VercelBlobPhp\ListCommandMode::EXPANDED, // optional
prefix: 'prefix', // optional
)
);
```

#### LIST
Options argument is optional.
7 changes: 6 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use Iterator;
use JsonException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use VercelBlobPhp\Exception\BlobAccessException;
use VercelBlobPhp\Exception\BlobException;
use VercelBlobPhp\Exception\BlobNotFoundException;
Expand Down Expand Up @@ -83,6 +85,8 @@ public function request(string $uri, string $method, array $options = []): Respo
}

/**
* @param resource|string|null|int|float|StreamInterface|callable|Iterator $content
*
* @return PutBlobResult
* @throws BlobAccessException
* @throws BlobException
Expand All @@ -95,7 +99,7 @@ public function request(string $uri, string $method, array $options = []): Respo
* @throws GuzzleException
* @throws JsonException
*/
public function put(string $path, string $content, ?CommonCreateBlobOptions $options = null): PutBlobResult
public function put(string $path, $content, ?CommonCreateBlobOptions $options = null): PutBlobResult
{
$body = $this->getResponseBody(
$this->request(
Expand All @@ -119,6 +123,7 @@ public function put(string $path, string $content, ?CommonCreateBlobOptions $opt

/**
* @param string[] $urls
*
* @throws BlobAccessException
* @throws BlobException
* @throws BlobNotFoundException
Expand Down

0 comments on commit 3d60177

Please sign in to comment.