Skip to content

Commit

Permalink
feat(lib): generate PHP code from OpenAPI spec
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Aug 13, 2023
1 parent c8e6038 commit 558aefb
Show file tree
Hide file tree
Showing 690 changed files with 49,114 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/Authentication/BearerAuthAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file has been auto generated by Jane,
*
* Do no edit it directly.
*/

namespace Braze\Authentication;

class BearerAuthAuthentication implements \Jane\Component\OpenApiRuntime\Client\AuthenticationPlugin
{
private $token;

public function __construct(string $token)
{
$this->{'token'} = $token;
}

public function authentication(\Psr\Http\Message\RequestInterface $request): \Psr\Http\Message\RequestInterface
{
$header = sprintf('Bearer %s', $this->{'token'});
$request = $request->withHeader('Authorization', $header);

return $request;
}

public function getScope(): string
{
return 'BearerAuth';
}
}
37 changes: 37 additions & 0 deletions lib/Braze.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Braze;

use Http\Client\Common\Plugin\AddHostPlugin;
use Http\Client\Common\Plugin\AuthenticationPlugin;
use Http\Client\Common\PluginClient;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Http\Message\Authentication\Bearer;

class Braze
{
/** @var Client */
public $client;

/**
* Instantiates Braze client.
*
* @param string $apiUrl Braze REST endpoint (e.g., https://rest.iad-01.braze.com).
* @param string $apiKey Braze API key.
*/
public function __construct(string $apiUrl, string $apiKey)
{
$httpClient = Psr18ClientDiscovery::find();
$uri = Psr17FactoryDiscovery::findUriFactory()->createUri($apiUrl);
$bearer = new Bearer($apiKey);
$plugins = [
new AddHostPlugin($uri),
new AuthenticationPlugin($bearer),
];
$httpClient = new PluginClient($httpClient, $plugins);
$this->client = Client::create($httpClient);
}
}
8,588 changes: 8,588 additions & 0 deletions lib/Client.php

Large diffs are not rendered by default.

164 changes: 164 additions & 0 deletions lib/Endpoint/DeleteCatalogByCatalogName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

declare(strict_types=1);

/*
* This file has been auto generated by Jane,
*
* Do no edit it directly.
*/

namespace Braze\Endpoint;

class DeleteCatalogByCatalogName extends \Braze\Runtime\Client\BaseEndpoint implements \Braze\Runtime\Client\Endpoint
{
use \Braze\Runtime\Client\EndpointTrait;
protected $catalog_name;

/**
* > Use this endpoint to delete a catalog.
*
* To use this endpoint, you’ll need to generate an API key with the `catalogs.delete` permission.
*
* ## Rate limit
*
* This endpoint has a shared rate limit of 5 requests per minute between all synchronous catalog endpoints, as documented in [API rate limits](https://www.braze.com/docs/api/api_limits/).
*
* ## Path parameters
*
* | Parameter | Required | Data Type | Description |
* | --- | --- | --- | --- |
* | `catalog_name` | Required | String | Name of the catalog. |
*
* ## Response
*
* There are two status code responses for this endpoint: `200` and `404`.
*
* ### Example success response
*
* The status code `200` could return the following response body.
*
* ``` json
* {
* "message": "success"
* }
*
* ```
*
* ### Example error response
*
* The status code `404` could return the following response body. Refer to [Troubleshooting](https://www.braze.com/docs/api/endpoints/catalogs/catalog_management/synchronous/delete_catalog/#troubleshooting) for more information about errors you may encounter.
*
* ``` json
* {
* "errors": [
* {
* "id": "catalog-not-found",
* "message": "Could not find catalog",
* "parameters": [
* "catalog_name"
* ],
* "parameter_values": [
* "restaurants"
* ]
* }
* ],
* "message": "Invalid Request"
* }
*
* ```
*
* ## Troubleshooting
*
* The following table lists possible returned errors and their associated troubleshooting steps.
*
* | Error | Troubleshooting |
* | --- | --- |
* | `catalog-not-found` | Check that the catalog name is valid. |
*
* @param array $headerParameters {
*
* @var string $Content-Type
* @var string $Authorization
* }
*/
public function __construct(string $catalogName, array $headerParameters = [])
{
$this->catalog_name = $catalogName;
$this->headerParameters = $headerParameters;
}

public function getMethod(): string
{
return 'DELETE';
}

public function getUri(): string
{
return str_replace(['{catalog_name}'], [$this->catalog_name], '/catalogs/{catalog_name}');
}

public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array
{
return [[], null];
}

public function getExtraHeaders(): array
{
return ['Accept' => ['application/json']];
}

protected function getHeadersOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
{
$optionsResolver = parent::getHeadersOptionsResolver();
$optionsResolver->setDefined(['Content-Type', 'Authorization']);
$optionsResolver->setRequired([]);
$optionsResolver->setDefaults([]);
$optionsResolver->addAllowedTypes('Content-Type', ['string']);
$optionsResolver->addAllowedTypes('Authorization', ['string']);

return $optionsResolver;
}

/**
* @return null
*
* @throws \Braze\Exception\DeleteCatalogByCatalogNameBadRequestException
* @throws \Braze\Exception\DeleteCatalogByCatalogNameUnauthorizedException
* @throws \Braze\Exception\DeleteCatalogByCatalogNameForbiddenException
* @throws \Braze\Exception\DeleteCatalogByCatalogNameNotFoundException
* @throws \Braze\Exception\DeleteCatalogByCatalogNameTooManyRequestsException
* @throws \Braze\Exception\DeleteCatalogByCatalogNameInternalServerErrorException
*/
protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, string $contentType = null)
{
$status = $response->getStatusCode();
$body = (string) $response->getBody();
if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) {
return json_decode($body);
}
if (is_null($contentType) === false && (400 === $status && mb_strpos($contentType, 'application/json') !== false)) {
throw new \Braze\Exception\DeleteCatalogByCatalogNameBadRequestException($serializer->deserialize($body, 'Braze\\Model\\Error', 'json'), $response);
}
if (is_null($contentType) === false && (401 === $status && mb_strpos($contentType, 'application/json') !== false)) {
throw new \Braze\Exception\DeleteCatalogByCatalogNameUnauthorizedException($serializer->deserialize($body, 'Braze\\Model\\Error', 'json'), $response);
}
if (is_null($contentType) === false && (403 === $status && mb_strpos($contentType, 'application/json') !== false)) {
throw new \Braze\Exception\DeleteCatalogByCatalogNameForbiddenException($serializer->deserialize($body, 'Braze\\Model\\Error', 'json'), $response);
}
if (is_null($contentType) === false && (404 === $status && mb_strpos($contentType, 'application/json') !== false)) {
throw new \Braze\Exception\DeleteCatalogByCatalogNameNotFoundException($serializer->deserialize($body, 'Braze\\Model\\Error', 'json'), $response);
}
if (is_null($contentType) === false && (429 === $status && mb_strpos($contentType, 'application/json') !== false)) {
throw new \Braze\Exception\DeleteCatalogByCatalogNameTooManyRequestsException($serializer->deserialize($body, 'Braze\\Model\\Error', 'json'), $response);
}
if (is_null($contentType) === false && (500 === $status && mb_strpos($contentType, 'application/json') !== false)) {
throw new \Braze\Exception\DeleteCatalogByCatalogNameInternalServerErrorException($serializer->deserialize($body, 'Braze\\Model\\Error', 'json'), $response);
}
}

public function getAuthenticationScopes(): array
{
return ['BearerAuth'];
}
}
Loading

0 comments on commit 558aefb

Please sign in to comment.