Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.2.0"
".": "0.3.0"
}
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 0.3.0 (2025-12-10)

Full Changelog: [v0.2.0...v0.3.0](https://github.com/moderation-api/sdk-php/compare/v0.2.0...v0.3.0)

### ⚠ BREAKING CHANGES

* use camel casing for all class properties

### Features

* add `BaseResponse` class for accessing raw responses ([b70b4c9](https://github.com/moderation-api/sdk-php/commit/b70b4c941e71381dffd8332bbf3331e6e4482ee1))
* split out services into normal & raw types ([a7e26e6](https://github.com/moderation-api/sdk-php/commit/a7e26e6953f26a9b72075bee096f32fc8ddc1ba5))
* use camel casing for all class properties ([fc81f4b](https://github.com/moderation-api/sdk-php/commit/fc81f4b7f1afde496947d52394e3c2b50be9478f))


### Chores

* ensure constant values are marked as optional in array types ([50679be](https://github.com/moderation-api/sdk-php/commit/50679be728b3629ebc80582aa18deb111280927a))
* switch from `#[Api(optional: true|false)]` to `#[Required]|#[Optional]` for annotations ([0b40eda](https://github.com/moderation-api/sdk-php/commit/0b40edaeadad1f12f6066b520829c057a05927f3))
* use `$self = clone $this;` instead of `$obj = clone $this;` ([a8db5b6](https://github.com/moderation-api/sdk-php/commit/a8db5b63c804ddb837662907da5ed6efa0f921fd))

## 0.2.0 (2025-12-06)

Full Changelog: [v0.1.1...v0.2.0](https://github.com/moderation-api/sdk-php/compare/v0.1.1...v0.2.0)
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The REST API documentation can be found on [docs.moderationapi.com](https://docs
<!-- x-release-please-start-version -->

```
composer require "moderation-api/sdk-php 0.2.0"
composer require "moderation-api/sdk-php 0.3.0"
```

<!-- x-release-please-end -->
Expand All @@ -35,9 +35,9 @@ use ModerationAPI\Client;

$client = new Client(secretKey: getenv('MODAPI_SECRET_KEY') ?: 'My Secret Key');

$response = $client->content->submit([
'content' => ['text' => 'x', 'type' => 'text']
]);
$response = $client->content->submit(
content: ['text' => 'x', 'type' => 'text']
);

var_dump($response->recommendation);
```
Expand All @@ -59,13 +59,13 @@ When the library is unable to connect to the API, or if the API returns a non-su
use ModerationAPI\Core\Exceptions\APIConnectionException;

try {
$response = $client->content->submit([
'content' => ['text' => 'x', 'type' => 'text']
]);
$response = $client->content->submit(
content: ['text' => 'x', 'type' => 'text']
);
} catch (APIConnectionException $e) {
echo "The server could not be reached", PHP_EOL;
var_dump($e->getPrevious());
} catch (RateLimitError $_) {
} catch (RateLimitError $e) {
echo "A 429 status code was received; we should back off a bit.", PHP_EOL;
} catch (APIStatusError $e) {
echo "Another non-200-range status code was received", PHP_EOL;
Expand Down Expand Up @@ -108,8 +108,8 @@ $client = new Client(maxRetries: 0);

// Or, configure per-request:
$result = $client->content->submit(
['content' => ['text' => 'x', 'type' => 'text']],
RequestOptions::with(maxRetries: 5),
content: ['text' => 'x', 'type' => 'text'],
requestOptions: RequestOptions::with(maxRetries: 5),
);
```

Expand All @@ -129,8 +129,8 @@ Note: the `extra*` parameters of the same name overrides the documented paramete
use ModerationAPI\RequestOptions;

$response = $client->content->submit(
['content' => ['text' => 'x', 'type' => 'text']],
RequestOptions::with(
content: ['text' => 'x', 'type' => 'text'],
requestOptions: RequestOptions::with(
extraQueryParams: ['my_query_parameter' => 'value'],
extraBodyParams: ['my_body_parameter' => 'value'],
extraHeaders: ['my-header' => 'value'],
Expand Down
91 changes: 44 additions & 47 deletions src/Account/AccountListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,59 @@
namespace ModerationAPI\Account;

use ModerationAPI\Account\AccountListResponse\CurrentProject;
use ModerationAPI\Core\Attributes\Api;
use ModerationAPI\Core\Attributes\Optional;
use ModerationAPI\Core\Attributes\Required;
use ModerationAPI\Core\Concerns\SdkModel;
use ModerationAPI\Core\Concerns\SdkResponse;
use ModerationAPI\Core\Contracts\BaseModel;
use ModerationAPI\Core\Conversion\Contracts\ResponseConverter;

/**
* @phpstan-type AccountListResponseShape = array{
* id: string,
* paid_plan_name: string,
* remaining_quota: float,
* text_api_quota: float,
* current_project?: CurrentProject|null,
* paidPlanName: string,
* remainingQuota: float,
* textAPIQuota: float,
* currentProject?: CurrentProject|null,
* }
*/
final class AccountListResponse implements BaseModel, ResponseConverter
final class AccountListResponse implements BaseModel
{
/** @use SdkModel<AccountListResponseShape> */
use SdkModel;

use SdkResponse;

/**
* ID of the account.
*/
#[Api]
#[Required]
public string $id;

/**
* Name of the paid plan.
*/
#[Api]
public string $paid_plan_name;
#[Required('paid_plan_name')]
public string $paidPlanName;

/**
* Remaining quota.
*/
#[Api]
public float $remaining_quota;
#[Required('remaining_quota')]
public float $remainingQuota;

/**
* Text API quota.
*/
#[Api]
public float $text_api_quota;
#[Required('text_api_quota')]
public float $textAPIQuota;

#[Api(optional: true)]
public ?CurrentProject $current_project;
#[Optional('current_project')]
public ?CurrentProject $currentProject;

/**
* `new AccountListResponse()` is missing required properties by the API.
*
* To enforce required parameters use
* ```
* AccountListResponse::with(
* id: ..., paid_plan_name: ..., remaining_quota: ..., text_api_quota: ...
* id: ..., paidPlanName: ..., remainingQuota: ..., textAPIQuota: ...
* )
* ```
*
Expand All @@ -84,69 +81,69 @@ public function __construct()
*
* You must use named parameters to construct any parameters with a default value.
*
* @param CurrentProject|array{id: string, name: string} $current_project
* @param CurrentProject|array{id: string, name: string} $currentProject
*/
public static function with(
string $id,
string $paid_plan_name,
float $remaining_quota,
float $text_api_quota,
CurrentProject|array|null $current_project = null,
string $paidPlanName,
float $remainingQuota,
float $textAPIQuota,
CurrentProject|array|null $currentProject = null,
): self {
$obj = new self;
$self = new self;

$obj['id'] = $id;
$obj['paid_plan_name'] = $paid_plan_name;
$obj['remaining_quota'] = $remaining_quota;
$obj['text_api_quota'] = $text_api_quota;
$self['id'] = $id;
$self['paidPlanName'] = $paidPlanName;
$self['remainingQuota'] = $remainingQuota;
$self['textAPIQuota'] = $textAPIQuota;

null !== $current_project && $obj['current_project'] = $current_project;
null !== $currentProject && $self['currentProject'] = $currentProject;

return $obj;
return $self;
}

/**
* ID of the account.
*/
public function withID(string $id): self
{
$obj = clone $this;
$obj['id'] = $id;
$self = clone $this;
$self['id'] = $id;

return $obj;
return $self;
}

/**
* Name of the paid plan.
*/
public function withPaidPlanName(string $paidPlanName): self
{
$obj = clone $this;
$obj['paid_plan_name'] = $paidPlanName;
$self = clone $this;
$self['paidPlanName'] = $paidPlanName;

return $obj;
return $self;
}

/**
* Remaining quota.
*/
public function withRemainingQuota(float $remainingQuota): self
{
$obj = clone $this;
$obj['remaining_quota'] = $remainingQuota;
$self = clone $this;
$self['remainingQuota'] = $remainingQuota;

return $obj;
return $self;
}

/**
* Text API quota.
*/
public function withTextAPIQuota(float $textAPIQuota): self
{
$obj = clone $this;
$obj['text_api_quota'] = $textAPIQuota;
$self = clone $this;
$self['textAPIQuota'] = $textAPIQuota;

return $obj;
return $self;
}

/**
Expand All @@ -155,9 +152,9 @@ public function withTextAPIQuota(float $textAPIQuota): self
public function withCurrentProject(
CurrentProject|array $currentProject
): self {
$obj = clone $this;
$obj['current_project'] = $currentProject;
$self = clone $this;
$self['currentProject'] = $currentProject;

return $obj;
return $self;
}
}
26 changes: 13 additions & 13 deletions src/Account/AccountListResponse/CurrentProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ModerationAPI\Account\AccountListResponse;

use ModerationAPI\Core\Attributes\Api;
use ModerationAPI\Core\Attributes\Required;
use ModerationAPI\Core\Concerns\SdkModel;
use ModerationAPI\Core\Contracts\BaseModel;

Expand All @@ -19,13 +19,13 @@ final class CurrentProject implements BaseModel
/**
* ID of the current project.
*/
#[Api]
#[Required]
public string $id;

/**
* Name of the current project.
*/
#[Api]
#[Required]
public string $name;

/**
Expand Down Expand Up @@ -54,33 +54,33 @@ public function __construct()
*/
public static function with(string $id, string $name): self
{
$obj = new self;
$self = new self;

$obj['id'] = $id;
$obj['name'] = $name;
$self['id'] = $id;
$self['name'] = $name;

return $obj;
return $self;
}

/**
* ID of the current project.
*/
public function withID(string $id): self
{
$obj = clone $this;
$obj['id'] = $id;
$self = clone $this;
$self['id'] = $id;

return $obj;
return $self;
}

/**
* Name of the current project.
*/
public function withName(string $name): self
{
$obj = clone $this;
$obj['name'] = $name;
$self = clone $this;
$self['name'] = $name;

return $obj;
return $self;
}
}
Loading