digitaluapi

<back to all web services

Files

Requires Authentication
Requires any of the roles:Client, Admin, Partner
The following routes are available for this service:
All Verbs/restfiles/files
All Verbs/restfiles/files/{Path*}
<?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 Files implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $Path=null,
        /** @var string|null */
        public ?string $TextContents=null,
        /** @var bool|null */
        public ?bool $ForDownload=null
    ) {
    }

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

class Folder implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $Name=null,
        /** @var DateTime */
        public DateTime $ModifiedDate=new DateTime(),
        /** @var int */
        public int $FileCount=0
    ) {
    }

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

class File implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $Name=null,
        /** @var string|null */
        public ?string $Extension=null,
        /** @var int */
        public int $FileSizeBytes=0,
        /** @var DateTime */
        public DateTime $ModifiedDate=new DateTime(),
        /** @var bool|null */
        public ?bool $IsTextFile=null
    ) {
    }

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

class FolderResult implements JsonSerializable
{
    public function __construct(
        /** @var array<Folder>|null */
        public ?array $Folders=null,
        /** @var array<File>|null */
        public ?array $Files=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Folders'])) $this->Folders = JsonConverters::fromArray('Folder', $o['Folders']);
        if (isset($o['Files'])) $this->Files = JsonConverters::fromArray('File', $o['Files']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Folders)) $o['Folders'] = JsonConverters::toArray('Folder', $this->Folders);
        if (isset($this->Files)) $o['Files'] = JsonConverters::toArray('File', $this->Files);
        return empty($o) ? new class(){} : $o;
    }
}

class FileResult implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $Name=null,
        /** @var string|null */
        public ?string $Extension=null,
        /** @var int */
        public int $FileSizeBytes=0,
        /** @var DateTime */
        public DateTime $ModifiedDate=new DateTime(),
        /** @var bool|null */
        public ?bool $IsTextFile=null,
        /** @var string|null */
        public ?string $Contents=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Name'])) $this->Name = $o['Name'];
        if (isset($o['Extension'])) $this->Extension = $o['Extension'];
        if (isset($o['FileSizeBytes'])) $this->FileSizeBytes = $o['FileSizeBytes'];
        if (isset($o['ModifiedDate'])) $this->ModifiedDate = JsonConverters::from('DateTime', $o['ModifiedDate']);
        if (isset($o['IsTextFile'])) $this->IsTextFile = $o['IsTextFile'];
        if (isset($o['Contents'])) $this->Contents = $o['Contents'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Name)) $o['Name'] = $this->Name;
        if (isset($this->Extension)) $o['Extension'] = $this->Extension;
        if (isset($this->FileSizeBytes)) $o['FileSizeBytes'] = $this->FileSizeBytes;
        if (isset($this->ModifiedDate)) $o['ModifiedDate'] = JsonConverters::to('DateTime', $this->ModifiedDate);
        if (isset($this->IsTextFile)) $o['IsTextFile'] = $this->IsTextFile;
        if (isset($this->Contents)) $o['Contents'] = $this->Contents;
        return empty($o) ? new class(){} : $o;
    }
}

class FilesResponse implements JsonSerializable
{
    public function __construct(
        /** @var FolderResult|null */
        public ?FolderResult $Directory=null,
        /** @var FileResult|null */
        public ?FileResult $File=null,
        /** @var ResponseStatus|null */
        public ?ResponseStatus $ResponseStatus=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Directory'])) $this->Directory = JsonConverters::from('FolderResult', $o['Directory']);
        if (isset($o['File'])) $this->File = JsonConverters::from('FileResult', $o['File']);
        if (isset($o['ResponseStatus'])) $this->ResponseStatus = JsonConverters::from('ResponseStatus', $o['ResponseStatus']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Directory)) $o['Directory'] = JsonConverters::to('FolderResult', $this->Directory);
        if (isset($this->File)) $o['File'] = JsonConverters::to('FileResult', $this->File);
        if (isset($this->ResponseStatus)) $o['ResponseStatus'] = JsonConverters::to('ResponseStatus', $this->ResponseStatus);
        return empty($o) ? new class(){} : $o;
    }
}

PHP Files DTOs

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

HTTP + JSV

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

POST /restfiles/files HTTP/1.1 
Host: duengageapi.uat.scadsoftware.com 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	Path: String,
	TextContents: String,
	ForDownload: False
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	Directory: 
	{
		Folders: 
		[
			{
				Name: String,
				ModifiedDate: 0001-01-01,
				FileCount: 0
			}
		],
		Files: 
		[
			{
				Name: String,
				Extension: String,
				FileSizeBytes: 0,
				ModifiedDate: 0001-01-01,
				IsTextFile: False
			}
		]
	},
	File: 
	{
		Name: String,
		Extension: String,
		FileSizeBytes: 0,
		ModifiedDate: 0001-01-01,
		IsTextFile: False,
		Contents: String
	},
	ResponseStatus: 
	{
		ErrorCode: String,
		Message: String,
		StackTrace: String,
		Errors: 
		[
			{
				ErrorCode: String,
				FieldName: String,
				Message: String,
				Meta: 
				{
					String: String
				}
			}
		],
		Meta: 
		{
			String: String
		}
	}
}