| POST | /calculatedistance | Calculate 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;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json
To embed the response in a jsonp callback, append ?callback=myCallback
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /calculatedistance HTTP/1.1
Host: 1fetch.api.client.prod.86degrees.com
Accept: application/json
Content-Type: application/json
Content-Length: length
{"Coordinates":[{"Latitude":0,"Longitude":0}],"ApiKey":"String"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length
{"PointDistances":[0],"TotalDistance":0,"Description":"String","Heading":"String","WasSuccessful":false}