Skip to content

Commit

Permalink
Merge pull request #198 from uploadcare/develop
Browse files Browse the repository at this point in the history
Fix calls to removed/changed API methods
  • Loading branch information
rsedykh authored Dec 18, 2022
2 parents eec01f2 + 23b2f40 commit 66233f8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 30 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ The format is based now on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.0.1]
### Removed
- `GroupApiInterface::storeGroup($id)` method: see [Uploadcare API changelog](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Changelog)
### Deprecated
- The `$addFields` parameter of `FileApiInterface::listFiles` method
### Added
- `GroupApiInterface::removeGroup($id)` method to delete a group

## [4.0.0]
### Removed
- PHP 7.1 support (now minimal version is 7.4, PHP 8.0 is also supported)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ After that, you can access to file operation methods:
- int `$limit` A preferred amount of files in a list for a single response. Defaults to 100, while the maximum is 1000.
- string `$orderBy` Specifies the way to sort files in a returned list.
- string|int|null `$from` A starting point for a file filter. The value depends on your `$orderBy` parameter value.
- array `$addFields` Adds special fields to the file object.
- array `$addFields` **Deprecated** This parameter is deprecated since v4.0.1 and will be removed in v4.1
- bool|null `$stored` `true` includes the only stored files, `false` includes temporary files. If not set (default): both stored and not stored files will be included.
- bool `$removed` `true` to only include removed files in the response, `false` to include existing files. The default value is false.
- `nextPage(FileListResponseInterface $response)` — next page from previous answer, if next pages exist. You can use it in a simple `while` loop, for example:
Expand Down Expand Up @@ -325,7 +325,7 @@ After that, you can access group operation methods:
- `createGroup($files)` — Creates a file group. You can pass the array of IDs or `Uploadcare\File\FileCollection` as an argument. Returns an `Uploadcare\File\Group` object.
- `listGroups($limit, $asc = true)` — Gets a paginated list of groups. The default limit is 100, and the default sorting is by the date and time created (ascending). You can reverse the sorting order to descending dates with `$asc = false`. Returns `Uploadcare\Response\GroupListResponse`.
- `groupInfo($id)` — Gets a file group info by UUID. Returns an `Uploadcare\Group` object.
- `storeGroup($id)`Marks all files in a group as stored. Returns an `Uploadcare\Group` object.
- `removeGroup($id): void`delete group by UUID or `Uploadcare\Group` object.

### `Uploadcare\Group` class

Expand Down
8 changes: 5 additions & 3 deletions src/Apis/FileApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ public function nextPage(ListResponseInterface $response): ?ListResponseInterfac
* @param int $limit A preferred amount of files in a list for a single response. Defaults to 100, while the maximum is 1000.
* @param string $orderBy specifies the way files are sorted in a returned list
* @param string|int|null $from A starting point for filtering files. The value depends on your $orderBy parameter value.
* @param array $addFields Add special fields to the file object
* @param array $addFields This parameter is deprecated since v4.0.1 and will be removed in v4.1
* @param bool|null $stored `true` to only include files that were stored, `false` to include temporary ones. The default is unset: both stored and not stored files are returned.
* @param bool $removed `true` to only include removed files in the response, `false` to include existing files. Defaults to false.
*/
public function listFiles(int $limit = 100, string $orderBy = 'datetime_uploaded', $from = null, array $addFields = [], ?bool $stored = null, bool $removed = false): ListResponseInterface
{
if (!empty($addFields)) {
\trigger_deprecation('uploadcare/uploadcare-php', '4.0.1', 'This parameter was removed from Uploadcare API');
}
$parameters = [
'limit' => $limit,
'ordering' => $orderBy,
'removed' => $removed,
'add_fields' => $addFields,
'from' => $from,
];
if (\is_bool($stored)) {
Expand Down Expand Up @@ -121,7 +123,7 @@ public function deleteFile($id): FileInfoInterface
if ($id instanceof FileInfoInterface) {
$id = $id->getUuid();
}
$response = $this->request('DELETE', \sprintf('/files/%s/', $id));
$response = $this->request('DELETE', \sprintf('/files/%s/storage/', $id));

return $this->deserializeFileInfo($response, false);
}
Expand Down
19 changes: 6 additions & 13 deletions src/Apis/GroupApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,17 @@ public function groupInfo(string $id): GroupInterface

/**
* {@inheritDoc}
*
* @deprecated since Uploadcare API 0.7.0
* @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Changelog
*/
public function storeGroup($id): GroupInterface
{
if ($id instanceof GroupInterface) {
$strId = $id->getId();
if ($strId === null) {
throw new HttpException();
}
$id = $strId;
}
\trigger_deprecation('uploadcare/uploadcare-php', '4.0.1', 'This parameter was removed from Uploadcare API');

$uri = \sprintf('/groups/%s/storage/', $id);
$response = $this->request('PUT', $uri);
if ($response->getStatusCode() === 200) {
return $this->groupInfo($id);
}
$result = $id instanceof GroupInterface ? $id : (new Group())->setId($id);

throw new HttpException('Wrong response from API', $response->getStatusCode());
return (new GroupDecorator($result, $this))->setConfiguration($this->configuration);
}

public function removeGroup($id): void
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
final class Configuration implements ConfigurationInterface
{
public const LIBRARY_VERSION = 'v4.0.0';
public const LIBRARY_VERSION = 'v4.0.1';
public const API_VERSION = '0.7';
public const API_BASE_URL = 'api.uploadcare.com';
public const USER_AGENT_TEMPLATE = 'PHPUploadcare/{lib-version}/{publicKey} (PHP/{lang-version})';
Expand Down
5 changes: 5 additions & 0 deletions src/File/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public function offsetExists($offset): bool
return isset($this->elements[$offset]) || \array_key_exists($offset, $this->elements);
}

/**
* @param string|int $offset
*
* @return mixed|null
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Interfaces/Api/GroupApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function groupInfo(string $id): GroupInterface;
* @param string|GroupInterface $id Group UUID
*
* @throws HttpException
*
* @deprecated
*/
public function storeGroup($id): GroupInterface;

Expand Down
11 changes: 0 additions & 11 deletions tests/Uploader/UploaderMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ public function testFromPathMethod(): void
self::assertInstanceOf(FileInfoInterface::class, $response);
}

/**
* @group local-only
*/
public function testFromUrlMethod(): void
{
$body = ['file' => \uuid_create()];
$uploader = $this->makeUploaderWithResponse($body);

self::assertInstanceOf(FileInfoInterface::class, $uploader->fromUrl('https://httpbin.org/image/jpeg'));
}

public function testFromResourceMethod(): void
{
$body = ['file' => \uuid_create()];
Expand Down

0 comments on commit 66233f8

Please sign in to comment.