Skip to content

Commit 93f3fbc

Browse files
authored
Merge pull request #163 from ToshY/feature/162
Feature/162 - Library overhaul with public API models using BunnyHttpClient
2 parents 20d3e6f + 79909ba commit 93f3fbc

File tree

318 files changed

+8178
-9196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+8178
-9196
lines changed

.github/workflows/generator.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Generator
33
on:
44
workflow_dispatch:
55
schedule:
6-
- cron: '0 0 * * 0'
6+
- cron: '0 0 * * *'
77

88
permissions:
99
contents: write
@@ -45,8 +45,7 @@ jobs:
4545
4646
Checklist:
4747
- [x] Add/Update API models
48-
- [ ] Add/Update API public methods for corresponding models
49-
- [ ] Update documentation
48+
- [ ] Add/Update documentation examples (when needed)
5049
branch: patch/automated-models
5150
branch-suffix: short-commit-hash
5251
maintainer-can-modify: true

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ edge storage, video streaming, image optimizers and much more!
2727
## 🧰 Install
2828

2929
```bash
30-
composer require toshy/bunnynet-php:^6.0
30+
composer require toshy/bunnynet-php:^7.0
3131
```
3232

3333
## 📜 Documentation
@@ -63,12 +63,11 @@ task git:hooks
6363
This repository has a workflow run (see [generator](.github/workflows/generator.yml)) that creates or updates existing [models](src/Model/API) based on the latest OpenAPI specifications and subsequently
6464
creates a (draft) PR for these changes. You can identify these automated PRs with the labels `OpenAPI` and `automated`.
6565

66-
The automated PRs contain 3 tasks:
66+
The automated PRs contain two tasks:
6767
- [x] Add/Update API models
68-
- [ ] Add/Update API public methods for corresponding models
69-
- [ ] Update documentation
68+
- [ ] Add/Update documentation examples (when needed)
7069

71-
The first task is already done by the generator, but if you want to fix the other two tasks, please use the following way of working.
70+
The first task is already done by the generator, but if you want to fix the other task, please use the following way of working.
7271

7372
1. Fork the repository and make sure to copy all branches (not just `master`).
7473
2. Create a branch based on the automated PR branch.

UPGRADE.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,123 @@
1+
## 7.x
2+
3+
This release comes with breaking changes for the usability of the library.
4+
5+
Back in release [`6.0`](https://github.com/ToshY/BunnyNet-PHP/releases/tag/6.0.0) I introduced compatibility with OpenAPI specifications. After further research and consideration, I realised that the models that were generated should be enough for the end user to create a request with, making the existing API classes (`BaseAPI`, `EdgeScriptingAPI`, `EdgeStorageAPI`, `LoggingAPI`, `ShieldAPI` and `StreamAPI`) obsolete if the users have a single entrypoint that could be used instead, which eventually became the `BunnyHttpClient`.
6+
7+
> [!CAUTION]
8+
> Due to the nature of this release, I cannot guarantee this list of breaking changes is complete. Thank you for your understanding.
9+
10+
### ‼️ Breaking changes
11+
12+
#### `BunnyHttpClient`
13+
14+
All requests will now have to be made using the `ToshY\BunnyNet\BunnyHttpClient` (previously `ToshY\BunnyNet\Client\BunnyClient`), which now requires the `apiKey` and
15+
`baseUrl` to be set when constructing.
16+
17+
**Example**
18+
```php
19+
<?php
20+
21+
require 'vendor/autoload.php';
22+
23+
use ToshY\BunnyNet\BunnyHttpClient;
24+
use ToshY\BunnyNet\Enum\Endpoint;
25+
26+
$bunnyHttpClient = new BunnyHttpClient(
27+
client: new \Symfony\Component\HttpClient\Psr18Client(),
28+
// Provide the account API key.
29+
apiKey: '2cebf4f8-4bff-429f-86f6-bce2c2163d7e89fb0a86-a1b2-463c-a142-11eba8811989',
30+
baseUrl: Endpoint::BASE
31+
);
32+
```
33+
34+
| **6.x** | **7.x** | **7.x signature notes** |
35+
|-------------------------------------|----------------------------------|-------------------------------------------|
36+
| `ToshY\BunnyNet\Client\BunnyClient` | `ToshY\BunnyNet\BunnyHttpClient` | Requires `apiKey` and `baseUrl` to be set |
37+
38+
#### Models
39+
40+
The `BunnyHttpClient` now has a public `request` method that accepts any model implementing `ModelInterface`.
41+
42+
**Example**
43+
```php
44+
$bunnyHttpClient->request(
45+
new \ToshY\BunnyNet\Model\Api\Base\AbuseCase\ListAbuseCases(
46+
query: [
47+
'page' => 1,
48+
'perPage' => 1000,
49+
],
50+
)
51+
)
52+
```
53+
54+
All publicly usable models can be found under the [`\ToshY\BunnyNet\Model\Api`](https://github.com/ToshY/BunnyNet-PHP/blob/master/src/Model/Api) namespace.
55+
56+
> [!NOTE]
57+
> Examples have been updated in the [documentation](https://toshy.github.io/BunnyNet-PHP/).
58+
59+
#### `ImageProcessor` & `TokenAuthenitcation`
60+
61+
The `ImageProcessor` and `TokenAuthentication` have been renamed by prefixing it with `Bunny`.
62+
63+
| **6.x** | **7.x** | **7.x signature notes** |
64+
|--------------------------------------|--------------------------------------|-----------------------------|
65+
| `ToshY\BunnyNet\ImageProcessor` | `ToshY\BunnyNet\BunnyImageProcessor` | `generate` method is static |
66+
| `ToshY\BunnyNet\TokenAuthentication` | `ToshY\BunnyNet\BunnyTokenAuthentication` | |
67+
68+
#### `BunnyValidator`
69+
70+
The `BunnyValidator` was introduced in [`6.1`](https://github.com/ToshY/BunnyNet-PHP/releases/tag/6.1.0) as an initial way of making validation optional and/or more flexible. Up until now, the validator was always used by the API classes.
71+
72+
With this release, the `BunnyValidator` has become optional, no longer is used by default and separated from the formerly known API classes.
73+
74+
**Example**
75+
```php
76+
$bunnyValidator = new BunnyValidator();
77+
78+
// Construct the payload
79+
$payload = new TranscribeVideo(
80+
libraryId: 1,
81+
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
82+
query: [
83+
'language' => 'fi',
84+
'force' => true,
85+
],
86+
body: [
87+
'targetLanguages' => [
88+
'fi',
89+
'jp'
90+
],
91+
'generateTitle' => true,
92+
'generateDescription' => true,
93+
'sourceLanguage' => 'en',
94+
],
95+
);
96+
97+
// Perform validation and catch if necessary
98+
try {
99+
$bunnyValidator->query($payload);
100+
$bunnyValidator->body($payload);
101+
} catch (BunnyValidatorExceptionInterface) {
102+
// ...
103+
}
104+
```
105+
106+
| **6.x** | **7.x** |
107+
|--------------------------------------------|---------------------------------|
108+
| `ToshY\BunnyNet\Validation\BunnyValidator` | `ToshY\BunnyNet\BunnyValidator` |
109+
110+
111+
> [!NOTE]
112+
> Usage examples for the `BunnyValidator` have been added to the [documentation](https://toshy.github.io/BunnyNet-PHP/validation/).
113+
114+
#### Naming coding standards
115+
116+
All classes (and namespaces) have been updated according to the latest [coding standards](https://github.com/php/policies/blob/06ef24434942f3b09241ccbde124b83ca8a18042/coding-standards-and-naming.rst?plain=1#L26), where abbreviations/acronyms/initialisms have been renamed to be treated like regular words (camelcasing).
117+
118+
> [!IMPORTANT]
119+
> The `6.x` branch will now no longer be maintained.
120+
1121
## 6.x
2122

3123
This release comes with minor breaking changes for public methods that have been removed to ensure OpenAPI specifications compatibility.
@@ -48,6 +168,8 @@ The following bugs were discovered after the generator scripts recreated the mod
48168
| Stream API | UPDATE | [`getOEmbed`](https://toshy.github.io/BunnyNet-PHP/stream-api/#get-oembed) | Query parameter `url` not required |
49169

50170

171+
The `5.x` branch will now no longer be maintained.
172+
51173
### 🚀 Enhancements
52174

53175
| **Endpoint** | **Action** | **Method** | **Notes** |

0 commit comments

Comments
 (0)