#Script Pages

<back to all web services

QueryGitHubRepos

<?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};


// @DataContract
class QueryBase implements JsonSerializable
{
    public function __construct(
        // @DataMember(Order=1)
        /** @var int|null */
        public ?int $skip=null,

        // @DataMember(Order=2)
        /** @var int|null */
        public ?int $take=null,

        // @DataMember(Order=3)
        /** @var string|null */
        public ?string $orderBy=null,

        // @DataMember(Order=4)
        /** @var string|null */
        public ?string $orderByDesc=null,

        // @DataMember(Order=5)
        /** @var string|null */
        public ?string $include=null,

        // @DataMember(Order=6)
        /** @var string|null */
        public ?string $fields=null,

        // @DataMember(Order=7)
        /** @var array<string,string>|null */
        public ?array $meta=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['skip'])) $this->skip = $o['skip'];
        if (isset($o['take'])) $this->take = $o['take'];
        if (isset($o['orderBy'])) $this->orderBy = $o['orderBy'];
        if (isset($o['orderByDesc'])) $this->orderByDesc = $o['orderByDesc'];
        if (isset($o['include'])) $this->include = $o['include'];
        if (isset($o['fields'])) $this->fields = $o['fields'];
        if (isset($o['meta'])) $this->meta = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','string']), $o['meta']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->skip)) $o['skip'] = $this->skip;
        if (isset($this->take)) $o['take'] = $this->take;
        if (isset($this->orderBy)) $o['orderBy'] = $this->orderBy;
        if (isset($this->orderByDesc)) $o['orderByDesc'] = $this->orderByDesc;
        if (isset($this->include)) $o['include'] = $this->include;
        if (isset($this->fields)) $o['fields'] = $this->fields;
        if (isset($this->meta)) $o['meta'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','string']), $this->meta);
        return empty($o) ? new class(){} : $o;
    }
}

/**
 * @template T
 */
class QueryData extends QueryBase implements JsonSerializable
{
    public array $genericArgs = [];
    public static function create(array $genericArgs=[]): QueryData {
        $to = new QueryData();
        $to->genericArgs = $genericArgs;
        return $to;
    }

    /**
     * @param int|null $skip
     * @param int|null $take
     * @param string|null $orderBy
     * @param string|null $orderByDesc
     * @param string|null $include
     * @param string|null $fields
     * @param array<string,string>|null $meta
     */
    public function __construct(
        mixed $skip=null,
        mixed $take=null,
        mixed $orderBy=null,
        mixed $orderByDesc=null,
        mixed $include=null,
        mixed $fields=null,
        mixed $meta=null
    ) {
        parent::__construct($skip,$take,$orderBy,$orderByDesc,$include,$fields,$meta);
    }

    /** @throws Exception */
    public function fromMap($o): void {
        parent::fromMap($o);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = parent::jsonSerialize();
        return empty($o) ? new class(){} : $o;
    }
}

class GithubUser implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $id=0,
        /** @var string|null */
        public ?string $login=null,
        /** @var string|null */
        public ?string $avatar_Url=null,
        /** @var string|null */
        public ?string $url=null,
        /** @var int|null */
        public ?int $followers=null,
        /** @var int|null */
        public ?int $following=null,
        /** @var string|null */
        public ?string $type=null,
        /** @var int|null */
        public ?int $public_Gists=null,
        /** @var string|null */
        public ?string $location=null,
        /** @var string|null */
        public ?string $company=null,
        /** @var string|null */
        public ?string $html_Url=null,
        /** @var int|null */
        public ?int $public_Repos=null,
        /** @var DateTime|null */
        public ?DateTime $created_At=null,
        /** @var string|null */
        public ?string $blog=null,
        /** @var string|null */
        public ?string $email=null,
        /** @var string|null */
        public ?string $name=null,
        /** @var bool|null */
        public ?bool $hireable=null,
        /** @var string|null */
        public ?string $gravatar_Id=null,
        /** @var string|null */
        public ?string $bio=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['login'])) $this->login = $o['login'];
        if (isset($o['avatar_Url'])) $this->avatar_Url = $o['avatar_Url'];
        if (isset($o['url'])) $this->url = $o['url'];
        if (isset($o['followers'])) $this->followers = $o['followers'];
        if (isset($o['following'])) $this->following = $o['following'];
        if (isset($o['type'])) $this->type = $o['type'];
        if (isset($o['public_Gists'])) $this->public_Gists = $o['public_Gists'];
        if (isset($o['location'])) $this->location = $o['location'];
        if (isset($o['company'])) $this->company = $o['company'];
        if (isset($o['html_Url'])) $this->html_Url = $o['html_Url'];
        if (isset($o['public_Repos'])) $this->public_Repos = $o['public_Repos'];
        if (isset($o['created_At'])) $this->created_At = JsonConverters::from('DateTime', $o['created_At']);
        if (isset($o['blog'])) $this->blog = $o['blog'];
        if (isset($o['email'])) $this->email = $o['email'];
        if (isset($o['name'])) $this->name = $o['name'];
        if (isset($o['hireable'])) $this->hireable = $o['hireable'];
        if (isset($o['gravatar_Id'])) $this->gravatar_Id = $o['gravatar_Id'];
        if (isset($o['bio'])) $this->bio = $o['bio'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->login)) $o['login'] = $this->login;
        if (isset($this->avatar_Url)) $o['avatar_Url'] = $this->avatar_Url;
        if (isset($this->url)) $o['url'] = $this->url;
        if (isset($this->followers)) $o['followers'] = $this->followers;
        if (isset($this->following)) $o['following'] = $this->following;
        if (isset($this->type)) $o['type'] = $this->type;
        if (isset($this->public_Gists)) $o['public_Gists'] = $this->public_Gists;
        if (isset($this->location)) $o['location'] = $this->location;
        if (isset($this->company)) $o['company'] = $this->company;
        if (isset($this->html_Url)) $o['html_Url'] = $this->html_Url;
        if (isset($this->public_Repos)) $o['public_Repos'] = $this->public_Repos;
        if (isset($this->created_At)) $o['created_At'] = JsonConverters::to('DateTime', $this->created_At);
        if (isset($this->blog)) $o['blog'] = $this->blog;
        if (isset($this->email)) $o['email'] = $this->email;
        if (isset($this->name)) $o['name'] = $this->name;
        if (isset($this->hireable)) $o['hireable'] = $this->hireable;
        if (isset($this->gravatar_Id)) $o['gravatar_Id'] = $this->gravatar_Id;
        if (isset($this->bio)) $o['bio'] = $this->bio;
        return empty($o) ? new class(){} : $o;
    }
}

class GithubRepo implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $id=0,
        /** @var string|null */
        public ?string $name=null,
        /** @var string|null */
        public ?string $description=null,
        /** @var string|null */
        public ?string $homepage=null,
        /** @var string|null */
        public ?string $language=null,
        /** @var int */
        public int $watchers_Count=0,
        /** @var int */
        public int $stargazes_Count=0,
        /** @var int */
        public int $forks_Count=0,
        /** @var int */
        public int $open_Issues_Count=0,
        /** @var int */
        public int $size=0,
        /** @var string|null */
        public ?string $full_Name=null,
        /** @var DateTime */
        public DateTime $created_at=new DateTime(),
        /** @var DateTime|null */
        public ?DateTime $pushed_At=null,
        /** @var DateTime|null */
        public ?DateTime $updated_At=null,
        /** @var bool|null */
        public ?bool $has_issues=null,
        /** @var bool|null */
        public ?bool $has_Downloads=null,
        /** @var bool|null */
        public ?bool $has_Wiki=null,
        /** @var bool|null */
        public ?bool $has_Pages=null,
        /** @var bool|null */
        public ?bool $fork=null,
        /** @var GithubUser|null */
        public ?GithubUser $owner=null,
        /** @var string|null */
        public ?string $svn_Url=null,
        /** @var string|null */
        public ?string $mirror_Url=null,
        /** @var string|null */
        public ?string $url=null,
        /** @var string|null */
        public ?string $ssh_Url=null,
        /** @var string|null */
        public ?string $html_Url=null,
        /** @var string|null */
        public ?string $clone_Url=null,
        /** @var string|null */
        public ?string $git_Url=null,
        /** @var bool|null */
        public ?bool $private=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['id'])) $this->id = $o['id'];
        if (isset($o['name'])) $this->name = $o['name'];
        if (isset($o['description'])) $this->description = $o['description'];
        if (isset($o['homepage'])) $this->homepage = $o['homepage'];
        if (isset($o['language'])) $this->language = $o['language'];
        if (isset($o['watchers_Count'])) $this->watchers_Count = $o['watchers_Count'];
        if (isset($o['stargazes_Count'])) $this->stargazes_Count = $o['stargazes_Count'];
        if (isset($o['forks_Count'])) $this->forks_Count = $o['forks_Count'];
        if (isset($o['open_Issues_Count'])) $this->open_Issues_Count = $o['open_Issues_Count'];
        if (isset($o['size'])) $this->size = $o['size'];
        if (isset($o['full_Name'])) $this->full_Name = $o['full_Name'];
        if (isset($o['created_at'])) $this->created_at = JsonConverters::from('DateTime', $o['created_at']);
        if (isset($o['pushed_At'])) $this->pushed_At = JsonConverters::from('DateTime', $o['pushed_At']);
        if (isset($o['updated_At'])) $this->updated_At = JsonConverters::from('DateTime', $o['updated_At']);
        if (isset($o['has_issues'])) $this->has_issues = $o['has_issues'];
        if (isset($o['has_Downloads'])) $this->has_Downloads = $o['has_Downloads'];
        if (isset($o['has_Wiki'])) $this->has_Wiki = $o['has_Wiki'];
        if (isset($o['has_Pages'])) $this->has_Pages = $o['has_Pages'];
        if (isset($o['fork'])) $this->fork = $o['fork'];
        if (isset($o['owner'])) $this->owner = JsonConverters::from('GithubUser', $o['owner']);
        if (isset($o['svn_Url'])) $this->svn_Url = $o['svn_Url'];
        if (isset($o['mirror_Url'])) $this->mirror_Url = $o['mirror_Url'];
        if (isset($o['url'])) $this->url = $o['url'];
        if (isset($o['ssh_Url'])) $this->ssh_Url = $o['ssh_Url'];
        if (isset($o['html_Url'])) $this->html_Url = $o['html_Url'];
        if (isset($o['clone_Url'])) $this->clone_Url = $o['clone_Url'];
        if (isset($o['git_Url'])) $this->git_Url = $o['git_Url'];
        if (isset($o['private'])) $this->private = $o['private'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->id)) $o['id'] = $this->id;
        if (isset($this->name)) $o['name'] = $this->name;
        if (isset($this->description)) $o['description'] = $this->description;
        if (isset($this->homepage)) $o['homepage'] = $this->homepage;
        if (isset($this->language)) $o['language'] = $this->language;
        if (isset($this->watchers_Count)) $o['watchers_Count'] = $this->watchers_Count;
        if (isset($this->stargazes_Count)) $o['stargazes_Count'] = $this->stargazes_Count;
        if (isset($this->forks_Count)) $o['forks_Count'] = $this->forks_Count;
        if (isset($this->open_Issues_Count)) $o['open_Issues_Count'] = $this->open_Issues_Count;
        if (isset($this->size)) $o['size'] = $this->size;
        if (isset($this->full_Name)) $o['full_Name'] = $this->full_Name;
        if (isset($this->created_at)) $o['created_at'] = JsonConverters::to('DateTime', $this->created_at);
        if (isset($this->pushed_At)) $o['pushed_At'] = JsonConverters::to('DateTime', $this->pushed_At);
        if (isset($this->updated_At)) $o['updated_At'] = JsonConverters::to('DateTime', $this->updated_At);
        if (isset($this->has_issues)) $o['has_issues'] = $this->has_issues;
        if (isset($this->has_Downloads)) $o['has_Downloads'] = $this->has_Downloads;
        if (isset($this->has_Wiki)) $o['has_Wiki'] = $this->has_Wiki;
        if (isset($this->has_Pages)) $o['has_Pages'] = $this->has_Pages;
        if (isset($this->fork)) $o['fork'] = $this->fork;
        if (isset($this->owner)) $o['owner'] = JsonConverters::to('GithubUser', $this->owner);
        if (isset($this->svn_Url)) $o['svn_Url'] = $this->svn_Url;
        if (isset($this->mirror_Url)) $o['mirror_Url'] = $this->mirror_Url;
        if (isset($this->url)) $o['url'] = $this->url;
        if (isset($this->ssh_Url)) $o['ssh_Url'] = $this->ssh_Url;
        if (isset($this->html_Url)) $o['html_Url'] = $this->html_Url;
        if (isset($this->clone_Url)) $o['clone_Url'] = $this->clone_Url;
        if (isset($this->git_Url)) $o['git_Url'] = $this->git_Url;
        if (isset($this->private)) $o['private'] = $this->private;
        return empty($o) ? new class(){} : $o;
    }
}

/**
 * @template QueryData of GithubRepo
 */
class QueryGitHubRepos extends QueryData implements JsonSerializable
{
    /**
     * @param int|null $skip
     * @param int|null $take
     * @param string|null $orderBy
     * @param string|null $orderByDesc
     * @param string|null $include
     * @param string|null $fields
     * @param array<string,string>|null $meta
     */
    public function __construct(
        ?int $skip=null,
        ?int $take=null,
        ?string $orderBy=null,
        ?string $orderByDesc=null,
        ?string $include=null,
        ?string $fields=null,
        ?array $meta=null,
        /** @var string|null */
        public ?string $userName=null
    ) {
        parent::__construct($skip,$take,$orderBy,$orderByDesc,$include,$fields,$meta);
    }

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

class Order implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $orderId=0,
        /** @var string|null */
        public ?string $customerId=null,
        /** @var DateTime */
        public DateTime $orderDate=new DateTime(),
        /** @var float */
        public float $total=0.0
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['orderId'])) $this->orderId = $o['orderId'];
        if (isset($o['customerId'])) $this->customerId = $o['customerId'];
        if (isset($o['orderDate'])) $this->orderDate = JsonConverters::from('DateTime', $o['orderDate']);
        if (isset($o['total'])) $this->total = $o['total'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->orderId)) $o['orderId'] = $this->orderId;
        if (isset($this->customerId)) $o['customerId'] = $this->customerId;
        if (isset($this->orderDate)) $o['orderDate'] = JsonConverters::to('DateTime', $this->orderDate);
        if (isset($this->total)) $o['total'] = $this->total;
        return empty($o) ? new class(){} : $o;
    }
}

class Customer implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $customerId=null,
        /** @var string|null */
        public ?string $companyName=null,
        /** @var string|null */
        public ?string $address=null,
        /** @var string|null */
        public ?string $city=null,
        /** @var string|null */
        public ?string $region=null,
        /** @var string|null */
        public ?string $postalCode=null,
        /** @var string|null */
        public ?string $country=null,
        /** @var string|null */
        public ?string $phone=null,
        /** @var string|null */
        public ?string $fax=null,
        /** @var array<Order>|null */
        public ?array $orders=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['customerId'])) $this->customerId = $o['customerId'];
        if (isset($o['companyName'])) $this->companyName = $o['companyName'];
        if (isset($o['address'])) $this->address = $o['address'];
        if (isset($o['city'])) $this->city = $o['city'];
        if (isset($o['region'])) $this->region = $o['region'];
        if (isset($o['postalCode'])) $this->postalCode = $o['postalCode'];
        if (isset($o['country'])) $this->country = $o['country'];
        if (isset($o['phone'])) $this->phone = $o['phone'];
        if (isset($o['fax'])) $this->fax = $o['fax'];
        if (isset($o['orders'])) $this->orders = JsonConverters::fromArray('Order', $o['orders']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->customerId)) $o['customerId'] = $this->customerId;
        if (isset($this->companyName)) $o['companyName'] = $this->companyName;
        if (isset($this->address)) $o['address'] = $this->address;
        if (isset($this->city)) $o['city'] = $this->city;
        if (isset($this->region)) $o['region'] = $this->region;
        if (isset($this->postalCode)) $o['postalCode'] = $this->postalCode;
        if (isset($this->country)) $o['country'] = $this->country;
        if (isset($this->phone)) $o['phone'] = $this->phone;
        if (isset($this->fax)) $o['fax'] = $this->fax;
        if (isset($this->orders)) $o['orders'] = JsonConverters::toArray('Order', $this->orders);
        return empty($o) ? new class(){} : $o;
    }
}

// @DataContract
/**
 * @template Customer
 */
class QueryResponse implements JsonSerializable
{
    public array $genericArgs = [];
    public static function create(array $genericArgs=[]): QueryResponse {
        $to = new QueryResponse();
        $to->genericArgs = $genericArgs;
        return $to;
    }

    public function __construct(
        // @DataMember(Order=1)
        /** @var int */
        public mixed $offset=0,

        // @DataMember(Order=2)
        /** @var int */
        public mixed $total=0,

        // @DataMember(Order=3)
        /** @var array<Customer>|null */
        public mixed $results=null,

        // @DataMember(Order=4)
        /** @var array<string,string>|null */
        public mixed $meta=null,

        // @DataMember(Order=5)
        /** @var ResponseStatus|null */
        public mixed $responseStatus=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['offset'])) $this->offset = $o['offset'];
        if (isset($o['total'])) $this->total = $o['total'];
        if (isset($o['results'])) $this->results = JsonConverters::fromArray($this->genericArgs[0], $o['results']);
        if (isset($o['meta'])) $this->meta = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','string']), $o['meta']);
        if (isset($o['responseStatus'])) $this->responseStatus = JsonConverters::from('ResponseStatus', $o['responseStatus']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->offset)) $o['offset'] = $this->offset;
        if (isset($this->total)) $o['total'] = $this->total;
        if (isset($this->results)) $o['results'] = JsonConverters::toArray($this->genericArgs[0], $this->results);
        if (isset($this->meta)) $o['meta'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','string']), $this->meta);
        if (isset($this->responseStatus)) $o['responseStatus'] = JsonConverters::to('ResponseStatus', $this->responseStatus);
        return empty($o) ? new class(){} : $o;
    }
}

PHP QueryGitHubRepos DTOs

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

HTTP + OTHER

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

POST /jsonl/reply/QueryGitHubRepos HTTP/1.1 
Host: sharpscript.net 
Accept: text/jsonl
Content-Type: text/jsonl
Content-Length: length

{"userName":"String","skip":0,"take":0,"orderBy":"String","orderByDesc":"String","include":"String","fields":"String","meta":{"String":"String"}}
HTTP/1.1 200 OK
Content-Type: text/jsonl
Content-Length: length

{"offset":0,"total":0,"results":[{"id":0,"name":"String","description":"String","homepage":"String","language":"String","watchers_Count":0,"stargazes_Count":0,"forks_Count":0,"open_Issues_Count":0,"size":0,"full_Name":"String","created_at":"\/Date(-62135596800000-0000)\/","pushed_At":"\/Date(-62135596800000-0000)\/","updated_At":"\/Date(-62135596800000-0000)\/","has_issues":false,"has_Downloads":false,"has_Wiki":false,"has_Pages":false,"fork":false,"owner":{"id":0,"login":"String","avatar_Url":"String","url":"String","followers":0,"following":0,"type":"String","public_Gists":0,"location":"String","company":"String","html_Url":"String","public_Repos":0,"created_At":"\/Date(-62135596800000-0000)\/","blog":"String","email":"String","name":"String","hireable":false,"gravatar_Id":"String","bio":"String"},"svn_Url":"String","mirror_Url":"String","url":"String","ssh_Url":"String","html_Url":"String","clone_Url":"String","git_Url":"String","private":false}],"meta":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}