Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
369 changes: 369 additions & 0 deletions src/Api/BillingApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,369 @@
<?php

namespace Upsun\Api;

use DateTime;
use Exception;
use GuzzleHttp\Psr7\MultipartStream;
use InvalidArgumentException;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Upsun\Api\Serializer\ObjectSerializer;
use Upsun\Core\OAuthProvider;
use Upsun\Model\DateTimeFilter;
use Upsun\Model\ListUserOrgs200Response;
use Upsun\Model\StringFilter;

/**
* Low level BillingApi (auto-generated)
*
* @license Apache-2.0
* @see https://docs.upsun.com
* @generated This file was generated by OpenAPI Generator. Do not edit manually.
*/
final class BillingApi extends AbstractApi
{
private readonly ApiHeaderSelector $headerSelector;

private APIConfiguration $config;

public function __construct(
OAuthProvider $oauthProvider,
?ClientInterface $httpClient = null,
?RequestFactoryInterface $requestFactory = null,
?APIConfiguration $config = null,
?StreamFactoryInterface $streamFactory = null,
?ApiHeaderSelector $selector = null,
) {
parent::__construct(
$oauthProvider,
$httpClient,
$requestFactory,
AbstractApi::BASE_PATH,
$streamFactory
);

$this->config = $config ?? (new APIConfiguration())->setHost(AbstractApi::BASE_PATH);

$this->headerSelector = $selector ?? new ApiHeaderSelector();
}

/**
* Billing profile organizations
*
* Retrieves organizations that belong to the specified billing profile.
*
* @param string $billingProfileId
* The ID of the billing profile. (required)
* @param \Upsun\Model\StringFilter|null $filterType (optional)
* @param \Upsun\Model\StringFilter|null $filterStatus (optional)
* @param \Upsun\Model\DateTimeFilter|null $filterUpdatedAt (optional)
* @param int|null $pageSize (optional)
* @param string|null $pageBefore (optional)
* @param string|null $pageAfter (optional)
* @param string|null $sort (optional)
*
* @throws ApiException on non-2xx response or if the response body is not in the expected format
* @throws ClientExceptionInterface
* @see https://docs.upsun.com/api/#tag/Billing/operation/list-billing-profile-orgs
*/
public function listBillingProfileOrgs(
string $billingProfileId,
?StringFilter $filterType = null,
?StringFilter $filterStatus = null,
?DateTimeFilter $filterUpdatedAt = null,
?int $pageSize = null,
?string $pageBefore = null,
?string $pageAfter = null,
?string $sort = null
): ListUserOrgs200Response {
return $this->listBillingProfileOrgsWithHttpInfo(
$billingProfileId,
$filterType,
$filterStatus,
$filterUpdatedAt,
$pageSize,
$pageBefore,
$pageAfter,
$sort
);
}

/**
* Billing profile organizations with HTTP Info
*
* @param string $billingProfileId
* The ID of the billing profile. (required)
* @param \Upsun\Model\StringFilter|null $filterType (optional)
* @param \Upsun\Model\StringFilter|null $filterStatus (optional)
* @param \Upsun\Model\DateTimeFilter|null $filterUpdatedAt (optional)
* @param int|null $pageSize (optional)
* @param string|null $pageBefore (optional)
* @param string|null $pageAfter (optional)
* @param string|null $sort (optional)
*
* @throws ApiException on non-2xx response or if the response body is not in the expected format
* @throws ClientExceptionInterface
*/
private function listBillingProfileOrgsWithHttpInfo(
string $billingProfileId,
?StringFilter $filterType = null,
?StringFilter $filterStatus = null,
?DateTimeFilter $filterUpdatedAt = null,
?int $pageSize = null,
?string $pageBefore = null,
?string $pageAfter = null,
?string $sort = null
): ListUserOrgs200Response {
$request = $this->listBillingProfileOrgsRequest(
$billingProfileId,
$filterType,
$filterStatus,
$filterUpdatedAt,
$pageSize,
$pageBefore,
$pageAfter,
$sort
);

try {
$response = $this->sendAuthenticatedRequest(
$request->getMethod(),
(string) $request->getUri(),
$request->getHeaders(),
$request->getBody()
);

return $this->handleResponseWithDataType(
'\Upsun\Model\ListUserOrgs200Response',
$request,
$response
);
} catch (Exception $exception) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$exception->getCode(),
'/billing/profiles/{billing_profile_id}/organizations'
),
$request,
$response ?? null,
$exception
);
}
}

/**
* Create request for operation 'listBillingProfileOrgs'
*
* @param string $billingProfileId
* The ID of the billing profile. (required)
* @param \Upsun\Model\StringFilter|null $filterType (optional)
* @param \Upsun\Model\StringFilter|null $filterStatus (optional)
* @param \Upsun\Model\DateTimeFilter|null $filterUpdatedAt (optional)
* @param int|null $pageSize (optional)
* @param string|null $pageBefore (optional)
* @param string|null $pageAfter (optional)
* @param string|null $sort (optional)
*
* @throws InvalidArgumentException
*/
private function listBillingProfileOrgsRequest(
string $billingProfileId,
?StringFilter $filterType = null,
?StringFilter $filterStatus = null,
?DateTimeFilter $filterUpdatedAt = null,
?int $pageSize = null,
?string $pageBefore = null,
?string $pageAfter = null,
?string $sort = null
): RequestInterface {
// verify the required parameter 'billingProfileId' is set
if (empty($billingProfileId)) {
throw new InvalidArgumentException(
'Missing the required parameter $billingProfileId
when calling listBillingProfileOrgs'
);
}

if ($pageSize !== null && $pageSize > 100) {
throw new InvalidArgumentException(
'invalid value for "$pageSize" when calling BillingApi.listBillingProfileOrgs,
must be smaller than or equal to 100.'
);
}

if ($pageSize !== null && $pageSize < 1) {
throw new InvalidArgumentException(
'invalid value for "$pageSize" when calling BillingApi.listBillingProfileOrgs,
must be bigger than or equal to 1.'
);
}

$resourcePath = '/billing/profiles/{billing_profile_id}/organizations';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = null;
$multipart = false;

// query params
if ($filterType !== null) {
if ('form' === 'deepObject' && is_array($filterType)) {
foreach ($filterType as $key => $value) {
$queryParams[$key] = $value;
}
} else {
$queryParams['filter[type]'] = $filterType instanceof DateTime
? $filterType->format(DATE_ATOM)
: ($filterType->getEq());
}
}

// query params
if ($filterStatus !== null) {
if ('form' === 'deepObject' && is_array($filterStatus)) {
foreach ($filterStatus as $key => $value) {
$queryParams[$key] = $value;
}
} else {
$queryParams['filter[status]'] = $filterStatus instanceof DateTime
? $filterStatus->format(DATE_ATOM)
: ($filterStatus->getEq());
}
}

// query params
if ($filterUpdatedAt !== null) {
if ('form' === 'deepObject' && is_array($filterUpdatedAt)) {
foreach ($filterUpdatedAt as $key => $value) {
$queryParams[$key] = $value;
}
} else {
$queryParams['filter[updated_at]'] = $filterUpdatedAt instanceof DateTime
? $filterUpdatedAt->format(DATE_ATOM)
: ($filterUpdatedAt->getEq());
}
}

// query params
if ($pageSize !== null) {
if ('form' === 'form' && is_array($pageSize)) {
foreach ($pageSize as $key => $value) {
$queryParams[$key] = $value;
}
} else {
$queryParams['page[size]'] = $pageSize instanceof DateTime
? $pageSize->format(DATE_ATOM)
: ($pageSize);
}
}

// query params
if ($pageBefore !== null) {
if ('form' === 'form' && is_array($pageBefore)) {
foreach ($pageBefore as $key => $value) {
$queryParams[$key] = $value;
}
} else {
$queryParams['page[before]'] = $pageBefore instanceof DateTime
? $pageBefore->format(DATE_ATOM)
: ($pageBefore);
}
}

// query params
if ($pageAfter !== null) {
if ('form' === 'form' && is_array($pageAfter)) {
foreach ($pageAfter as $key => $value) {
$queryParams[$key] = $value;
}
} else {
$queryParams['page[after]'] = $pageAfter instanceof DateTime
? $pageAfter->format(DATE_ATOM)
: ($pageAfter);
}
}

// query params
if ($sort !== null) {
if ('form' === 'form' && is_array($sort)) {
foreach ($sort as $key => $value) {
$queryParams[$key] = $value;
}
} else {
$queryParams['sort'] = $sort instanceof DateTime
? $sort->format(DATE_ATOM)
: ($sort);
}
}

// path params

if ($billingProfileId !== null) {
$resourcePath = str_replace(
'{' . 'billing_profile_id' . '}',
ObjectSerializer::toPathValue($billingProfileId),
$resourcePath
);
}

$headers = $this->headerSelector->selectHeaders(
['application/json', 'application/problem+json'],
'',
$multipart
);

// for model (json/xml)
if ($formParams !== []) {
if ($multipart) {
$multipartContents = [];
foreach ($formParams as $formParamName => $formParamValue) {
$formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
foreach ($formParamValueItems as $formParamValueItem) {
$multipartContents[] = [
'name' => $formParamName,
'contents' => $formParamValueItem
];
}
}

// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);
} elseif ($this->headerSelector->isJsonMime($headers['Content-Type'])) {
$httpBody = json_encode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
}
}

// this endpoint requires Bearer authentication (access token)
if ($this->config->getAccessToken() !== null) {
$headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
}

$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}
if ($this->config->getUpsunClientHeader()) {
$defaultHeaders['X-Upsun-Client'] = $this->config->getUpsunClientHeader();
}

$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);

$operationHost = $this->config->getHost();

$uri = $this->createUri($operationHost, $resourcePath, $queryParams);

return $this->createRequest('GET', $uri, $headers, $httpBody);
}
}
Loading
Loading