1Fetch Client API

<back to all web services

CalculateDistance

The following routes are available for this service:
POST/calculatedistanceCalculate the distance between a list of coordinates
<?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 ApiServiceRequest implements IServiceRequest, IHasApiKey, JsonSerializable
{
    public function __construct(
        /** @description The API Key required for authentication */
        // @ApiMember(DataType="string", Description="The API Key required for authentication", IsRequired=true)
        /** @var string */
        public string $ApiKey=''
    ) {
    }

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

class ApiServiceResponse implements IServiceResponse, JsonSerializable
{
    public function __construct(
        /** @description Information about the response. */
        // @ApiMember(Description="Information about the response.", IsRequired=true)
        /** @var string */
        public string $Description='',

        /** @description Heading or summary of the response. */
        // @ApiMember(Description="Heading or summary of the response.", IsRequired=true)
        /** @var string */
        public string $Heading='',

        /** @description Did the intended operation for this response complete successfully? */
        // @ApiMember(DataType="boolean", Description="Did the intended operation for this response complete successfully?", IsRequired=true)
        /** @var bool|null */
        public ?bool $WasSuccessful=null
    ) {
    }

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

class CalculateDistanceResponse extends ApiServiceResponse implements JsonSerializable
{
    /**
     * @param string $Description
     * @param string $Heading
     * @param bool|null $WasSuccessful
     */
    public function __construct(
        string $Description='',
        string $Heading='',
        ?bool $WasSuccessful=null,
        /** @description A list of the distances between each point, returned in order that the points were provided */
        // @ApiMember(Description="A list of the distances between each point, returned in order that the points were provided")
        /** @var array<float>|null */
        public ?array $PointDistances=null,

        /** @description The total distance between all points */
        // @ApiMember(Description="The total distance between all points")
        /** @var float */
        public float $TotalDistance=0.0
    ) {
        parent::__construct($Description,$Heading,$WasSuccessful);
    }

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

class Coordinate implements JsonSerializable
{
    public function __construct(
        /** @description The Latitude */
        // @ApiMember(Description="The Latitude", IsRequired=true)
        /** @var float */
        public float $Latitude=0.0,

        /** @description The Longitude */
        // @ApiMember(Description="The Longitude", IsRequired=true)
        /** @var float */
        public float $Longitude=0.0
    ) {
    }

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

class CalculateDistance extends ApiServiceRequest implements ILogRequest, JsonSerializable
{
    /**
     * @param string $ApiKey
     */
    public function __construct(
        string $ApiKey='',
        /** @description Array of coordinates */
        // @ApiMember(Description="Array of coordinates", IsRequired=true)
        /** @var array<Coordinate>|null */
        public ?array $Coordinates=null
    ) {
        parent::__construct($ApiKey);
    }

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

PHP CalculateDistance 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 /calculatedistance HTTP/1.1 
Host: api.1fetch.co.za 
Accept: application/xml
Content-Type: application/xml
Content-Length: length

<CalculateDistance xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WebService.ClientServiceModel">
  <ApiKey xmlns="http://schemas.datacontract.org/2004/07/WebService.ClientServiceModel.Base">String</ApiKey>
  <Coordinates>
    <Coordinate>
      <Latitude>0</Latitude>
      <Longitude>0</Longitude>
    </Coordinate>
  </Coordinates>
</CalculateDistance>
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: length

<CalculateDistanceResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WebService.ClientServiceModel">
  <Description xmlns="http://schemas.datacontract.org/2004/07/WebService.ClientServiceModel.Base">String</Description>
  <Heading xmlns="http://schemas.datacontract.org/2004/07/WebService.ClientServiceModel.Base">String</Heading>
  <WasSuccessful xmlns="http://schemas.datacontract.org/2004/07/WebService.ClientServiceModel.Base">false</WasSuccessful>
  <PointDistances xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <d2p1:decimal>0</d2p1:decimal>
  </PointDistances>
  <TotalDistance>0</TotalDistance>
</CalculateDistanceResponse>