|
| 1 | +# Aternos/php-blob-build-api |
| 2 | +An API client for the [blob.build](https://blob.build) API written in PHP. This client is a combination of |
| 3 | +code generated by OpenAPI Generator and some wrappers around it to improve the usability. |
| 4 | + |
| 5 | +The generated code can be found in `src/Api` and `src/Model`. It is recommended |
| 6 | +to use the Wrappers in `src/Client` instead of the generated code. |
| 7 | + |
| 8 | +## Installation |
| 9 | +Install the package via composer: |
| 10 | +```bash |
| 11 | +composer require aternos/blob-build-api |
| 12 | +``` |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +The main entry point for the API is the `BlobBuildAPIClient` class. |
| 17 | +```php |
| 18 | +<?php |
| 19 | +use Aternos\BlobBuild\Client\BlobBuildAPIClient; |
| 20 | + |
| 21 | +// create an API client. This is the main entry point for the API |
| 22 | +$client = new BlobBuildAPIClient(); |
| 23 | + |
| 24 | +// set a user agent (recommended) |
| 25 | +$client->setUserAgent('aternos/php-blob-build-api-example'); |
| 26 | +``` |
| 27 | + |
| 28 | +## Projects |
| 29 | + |
| 30 | +### Listing all projects |
| 31 | +You can list all projects using the `listProjects` method. |
| 32 | +```php |
| 33 | +$projects = $client->listProjects(); |
| 34 | + |
| 35 | +foreach ($projects as $project) { |
| 36 | + echo "Project " . $project->getData()->getName() . " by " . $project->getData()->getOwner() . PHP_EOL; |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### Searching for projects |
| 41 | +To search for projects, you can use the `searchProjects` method with a search query. |
| 42 | +```php |
| 43 | +$projects = $client->searchProjects("sound"); |
| 44 | + |
| 45 | +foreach ($projects as $project) { |
| 46 | + echo "Project " . $project->getData()->getName() . " by " . $project->getData()->getOwner() . PHP_EOL; |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +### Fetching a specific project |
| 51 | +To fetch a specific project, you can use the `getProject` method with the project's name. |
| 52 | +```php |
| 53 | +$project = $client->getProject("SoundMuffler"); |
| 54 | +echo "Project " . $project->getData()->getName() . PHP_EOL; |
| 55 | +``` |
| 56 | +Unlike the projects retrieved from `listProjects` and `searchProjects`, this method does not contain the project owner. |
| 57 | + |
| 58 | +## Builds |
| 59 | + |
| 60 | +### Listing all builds for a project |
| 61 | +You can list all builds for a project using the `getProjectBuilds` method with the project's name. This returns an array |
| 62 | +where the keys are the name of a release channel and the values are arrays of builds for that channel. |
| 63 | +```php |
| 64 | +$result = $client->getProjectBuilds("SoundMuffler"); |
| 65 | +foreach ($result as $channel => $builds) { |
| 66 | + echo "Channel: " . $channel . PHP_EOL; |
| 67 | + foreach ($builds as $build) { |
| 68 | + echo " - Build " . $build->getData()->getBuildId() . PHP_EOL; |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +// or with the project wrapper |
| 73 | +$project = $client->getProject("SoundMuffler"); |
| 74 | +$result = $project->getBuilds(); |
| 75 | +``` |
| 76 | + |
| 77 | +### Fetching the latest build for a project |
| 78 | +You can also fetch the latest build for a project in a specific channel. |
| 79 | +```php |
| 80 | +$build = $client->getLatestProjectBuildInChannel("SoundMuffler", "Dev"); |
| 81 | +echo "Build " . $build->getData()->getBuildId() . PHP_EOL; |
| 82 | + |
| 83 | +// Or with the project wrapper |
| 84 | +$project = $client->getProject("SoundMuffler"); |
| 85 | +// Either pick a channel |
| 86 | +$build = $project->getLatestBuildInChannel("Dev"); |
| 87 | +// Or use the default channel |
| 88 | +$build = $project->getLatestBuildInDefaultChannel() |
| 89 | +``` |
| 90 | + |
| 91 | +### Fetching a specific build |
| 92 | +```php |
| 93 | +$build = $client->getProjectBuild("SoundMuffler", "Dev", 1); |
| 94 | +echo "Build " . $build->getData()->getBuildId() . PHP_EOL; |
| 95 | + |
| 96 | +// Or with the project wrapper |
| 97 | +$project = $client->getProject("SoundMuffler"); |
| 98 | +$build = $project->getBuild("Dev", 1); |
| 99 | +``` |
| 100 | + |
| 101 | +## Updating the generated code |
| 102 | +The generated code can be updated by installing the [openapi generator](https://openapi-generator.tech/docs/installation) and running the following command: |
| 103 | +```bash |
| 104 | +openapi-generator-cli generate -c config.yaml |
| 105 | +``` |
0 commit comments