Skip to content

Commit

Permalink
Merge pull request #3 from moe-mizrak/feat/create-collection
Browse files Browse the repository at this point in the history
feat: createCollection, deleteCollection and listCollections added
  • Loading branch information
moe-mizrak authored Jan 21, 2025
2 parents 4bdac1e + 03b1697 commit 7c23495
Show file tree
Hide file tree
Showing 23 changed files with 1,070 additions and 492 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ Then, you can send the request using the `Rekognition` facade `detectLabels` met
$response = Rekognition::detectLabels($detectLabelsData);
```

Response will be an instance of [`ResultData`](src/Data/ResultData/ResultData.php) object.
Response will be an instance of [`DetectLabelsResultData`](src/Data/ResultData/DetectLabelsResultData.php) object.

<details>
<summary>This is the sample ResultData:</summary>
<summary>This is the sample DetectLabelsResultData:</summary>

```php
ResultData(
DetectLabelsResultData(
labels: DataCollection([
LabelData(
name: 'Adult',
Expand Down
21 changes: 21 additions & 0 deletions src/Data/Contracts/RekognitionDataFormatInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace MoeMizrak\Rekognition\Data\Contracts;

/**
* Interface for Rekognition Data Format where it uses capital letter as first letter for the properties.
* e.g. 'Image' instead of 'image', 'MaxLabels' instead of 'maxLabels'.
*
* @class RekognitionDataFormatInterface
*/
interface RekognitionDataFormatInterface
{
/**
* Convert the data to an AWS Rekognition array format, excluding null values.
*
* @return array
*/
public function toRekognitionDataFormat(): array;
}
48 changes: 48 additions & 0 deletions src/Data/CreateCollectionData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace MoeMizrak\Rekognition\Data;

use MoeMizrak\Rekognition\Data\Contracts\RekognitionDataFormatInterface;
use Spatie\LaravelData\Data;

/**
* CreateCollectionData is for the data of the Rekognition API createCollection request.
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#createcollection
*
* @class CreateCollectionData
*/
final class CreateCollectionData extends Data implements RekognitionDataFormatInterface
{
public function __construct(
/*
* ID for the collection that you are creating.
*
* @param string
*/
public string $collectionId,

/*
* A set of tags (key-value pairs) that you want to attach to the collection.
* - Associative array of custom strings keys (TagKey) to strings
*
* @param array|null
*/
public ?array $tags = null,
) {}

/**
* @inheritDoc
*/
public function toRekognitionDataFormat(): array
{
return array_filter(
[
'CollectionId' => $this->collectionId,
'Tags' => $this->tags,
],
fn ($value) => $value !== null
);
}
}
36 changes: 36 additions & 0 deletions src/Data/DeleteCollectionData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace MoeMizrak\Rekognition\Data;

use MoeMizrak\Rekognition\Data\Contracts\RekognitionDataFormatInterface;
use Spatie\LaravelData\Data;

/**
* DeleteCollectionData is for the data of the Rekognition API deleteCollection request.
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#deletecollection
*
* @class DeleteCollectionData
*/
final class DeleteCollectionData extends Data implements RekognitionDataFormatInterface
{
public function __construct(
/*
* The ID of the collection to delete.
*
* @param string
*/
public string $collectionId,
) {}

/**
* @inheritDoc
*/
public function toRekognitionDataFormat(): array
{
return [
'CollectionId' => $this->collectionId,
];
}
}
7 changes: 3 additions & 4 deletions src/Data/DetectLabelsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MoeMizrak\Rekognition\Data;

use MoeMizrak\Rekognition\Data\Contracts\RekognitionDataFormatInterface;
use Spatie\LaravelData\Data;

/**
Expand All @@ -12,7 +13,7 @@
*
* @class DetectLabelsData
*/
final class DetectLabelsData extends Data
final class DetectLabelsData extends Data implements RekognitionDataFormatInterface
{
public function __construct(
/*
Expand Down Expand Up @@ -58,9 +59,7 @@ public function __construct(
) {}

/**
* Convert the data to an AWS Rekognition array format, excluding null values.
*
* @return array
* @inheritDoc
*/
public function toRekognitionDataFormat(): array
{
Expand Down
7 changes: 3 additions & 4 deletions src/Data/DetectLabelsImagePropertiesSettingsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MoeMizrak\Rekognition\Data;

use MoeMizrak\Rekognition\Data\Contracts\RekognitionDataFormatInterface;
use Spatie\LaravelData\Data;

/**
Expand All @@ -12,7 +13,7 @@
*
* @class DetectLabelsImagePropertiesSettingsData
*/
final class DetectLabelsImagePropertiesSettingsData extends Data
final class DetectLabelsImagePropertiesSettingsData extends Data implements RekognitionDataFormatInterface
{
public function __construct(
/*
Expand All @@ -25,9 +26,7 @@ public function __construct(
) {}

/**
* Convert the data to an AWS Rekognition array format.
*
* @return array
* @inheritDoc
*/
public function toRekognitionDataFormat(): array
{
Expand Down
7 changes: 3 additions & 4 deletions src/Data/GeneralLabelsSettingsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MoeMizrak\Rekognition\Data;

use MoeMizrak\Rekognition\Data\Contracts\RekognitionDataFormatInterface;
use Spatie\LaravelData\Data;

/**
Expand All @@ -13,7 +14,7 @@
*
* @class GeneralLabelsSettingsData
*/
final class GeneralLabelsSettingsData extends Data
final class GeneralLabelsSettingsData extends Data implements RekognitionDataFormatInterface
{
public function __construct(
/*
Expand Down Expand Up @@ -46,9 +47,7 @@ public function __construct(
) {}

/**
* Convert the data to an AWS Rekognition array format.
*
* @return array
* @inheritDoc
*/
public function toRekognitionDataFormat(): array
{
Expand Down
7 changes: 3 additions & 4 deletions src/Data/ImageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MoeMizrak\Rekognition\Data;

use MoeMizrak\Rekognition\Data\Contracts\RekognitionDataFormatInterface;
use Spatie\LaravelData\Data;

/**
Expand All @@ -13,7 +14,7 @@
*
* @class ImageData
*/
final class ImageData extends Data
final class ImageData extends Data implements RekognitionDataFormatInterface
{
public function __construct(
/*
Expand All @@ -32,9 +33,7 @@ public function __construct(
) {}

/**
* Convert the data to an AWS Rekognition array format.
*
* @return array
* @inheritDoc
*/
public function toRekognitionDataFormat(): array
{
Expand Down
47 changes: 47 additions & 0 deletions src/Data/ListCollectionsData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace MoeMizrak\Rekognition\Data;

use MoeMizrak\Rekognition\Data\Contracts\RekognitionDataFormatInterface;
use Spatie\LaravelData\Data;

/**
* ListCollectionsData is for listCollections method related context data such as maxResults and nextToken.
* For more detail: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#listcollections
*
* @class ListCollectionsData
*/
final class ListCollectionsData extends Data implements RekognitionDataFormatInterface
{
public function __construct(
/*
* Maximum number of collection IDs to return.
*
* @param int|null
*/
public ?int $maxResults = null,

/*
* Pagination token from the previous response.
*
* @param string|null
*/
public ?string $nextToken = null,
) {}

/**
* @inheritDoc
*/
public function toRekognitionDataFormat(): array
{
return array_filter(
[
'MaxResults' => $this->maxResults,
'NextToken' => $this->nextToken,
],
fn ($value) => $value !== null
);
}
}
46 changes: 46 additions & 0 deletions src/Data/ResultData/CreateCollectionResultData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace MoeMizrak\Rekognition\Data\ResultData;

use Spatie\LaravelData\Data;

/**
* CreateCollectionResultData is for the result of the Rekognition API createCollection request.
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#createcollection
*
* @class CreateCollectionResultData
*/
final class CreateCollectionResultData extends Data
{
public function __construct(
/*
* Amazon Resource Name (ARN) of the collection. You can use this to manage permissions on your resources.
*
* @param string|null
*/
public ?string $collectionArn = null,

/*
* Version number of the face detection model associated with the collection you are creating.
*
* @param string|null
*/
public ?string $faceModelVersion = null,

/*
* HTTP status code indicating the result of the operation.
*
* @param int|null
*/
public ?int $statusCode = null,

/*
* Metadata about the request.
*
* @param MetaData|null
*/
public ?MetaData $metadata = null,
) {}
}
32 changes: 32 additions & 0 deletions src/Data/ResultData/DeleteCollectionResultData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace MoeMizrak\Rekognition\Data\ResultData;

use Spatie\LaravelData\Data;

/**
* DeleteCollectionResultData is for the result of the Rekognition API deleteCollection request.
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#deletecollection
*
* @class DeleteCollectionResultData
*/
final class DeleteCollectionResultData extends Data
{
public function __construct(
/*
* HTTP status code that indicates the result of the operation.
*
* @param int|null
*/
public ?int $statusCode = null,

/*
* Metadata about the request.
*
* @param MetaData|null
*/
public ?MetaData $metadata = null,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
use Spatie\LaravelData\DataCollection;

/**
* ResultData is for the result of the Rekognition API detectLabels request.
* DetectLabelsResultData is for the result of the Rekognition API detectLabels request.
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#detectlabels
*
* @class ResultData
* @class DetectLabelsResultData
*/
final class ResultData extends Data
final class DetectLabelsResultData extends Data
{
public function __construct(
/*
Expand All @@ -30,7 +30,7 @@ public function __construct(
*
* @param string|null
*/
public ?string $LabelModelVersion = null,
public ?string $labelModelVersion = null,

/*
* The value of orientationCorrection is always null.
Expand Down
Loading

0 comments on commit 7c23495

Please sign in to comment.