Blazor Diffusion

<back to all web services

CheckQuota

User
Requires Authentication
<?php namespace dtos;

use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};


class CheckQuotaResponse implements JsonSerializable
{
    public function __construct(
        /** @var DateInterval|null */
        public ?DateInterval $timeRemaining=null,
        /** @var int */
        public int $creditsUsed=0,
        /** @var int */
        public int $creditsRequested=0,
        /** @var int */
        public int $creditsRemaining=0,
        /** @var int */
        public int $dailyQuota=0,
        /** @var string */
        public string $requestedDetails=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['timeRemaining'])) $this->timeRemaining = JsonConverters::from('DateInterval', $o['timeRemaining']);
        if (isset($o['creditsUsed'])) $this->creditsUsed = $o['creditsUsed'];
        if (isset($o['creditsRequested'])) $this->creditsRequested = $o['creditsRequested'];
        if (isset($o['creditsRemaining'])) $this->creditsRemaining = $o['creditsRemaining'];
        if (isset($o['dailyQuota'])) $this->dailyQuota = $o['dailyQuota'];
        if (isset($o['requestedDetails'])) $this->requestedDetails = $o['requestedDetails'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->timeRemaining)) $o['timeRemaining'] = JsonConverters::to('DateInterval', $this->timeRemaining);
        if (isset($this->creditsUsed)) $o['creditsUsed'] = $this->creditsUsed;
        if (isset($this->creditsRequested)) $o['creditsRequested'] = $this->creditsRequested;
        if (isset($this->creditsRemaining)) $o['creditsRemaining'] = $this->creditsRemaining;
        if (isset($this->dailyQuota)) $o['dailyQuota'] = $this->dailyQuota;
        if (isset($this->requestedDetails)) $o['requestedDetails'] = $this->requestedDetails;
        return empty($o) ? new class(){} : $o;
    }
}

// @ValidateRequest(Validator="IsAuthenticated")
class CheckQuota implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $images=0,
        /** @var int */
        public int $width=0,
        /** @var int */
        public int $height=0
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['images'])) $this->images = $o['images'];
        if (isset($o['width'])) $this->width = $o['width'];
        if (isset($o['height'])) $this->height = $o['height'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->images)) $o['images'] = $this->images;
        if (isset($this->width)) $o['width'] = $this->width;
        if (isset($this->height)) $o['height'] = $this->height;
        return empty($o) ? new class(){} : $o;
    }
}

PHP CheckQuota DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .xml suffix or ?format=xml

HTTP + XML

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /xml/reply/CheckQuota HTTP/1.1 
Host: blazordiffusion.com 
Accept: application/xml
Content-Type: application/xml
Content-Length: length

<CheckQuota xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/BlazorDiffusion.ServiceModel">
  <Height>0</Height>
  <Images>0</Images>
  <Width>0</Width>
</CheckQuota>
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: length

<CheckQuotaResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/BlazorDiffusion.ServiceModel">
  <CreditsRemaining>0</CreditsRemaining>
  <CreditsRequested>0</CreditsRequested>
  <CreditsUsed>0</CreditsUsed>
  <DailyQuota>0</DailyQuota>
  <RequestedDetails>String</RequestedDetails>
  <TimeRemaining>PT0S</TimeRemaining>
</CheckQuotaResponse>