| POST | /quote/validatewaypoints | Validate the waypoints for a client. |
|---|
import Foundation
import ServiceStack
public class ValidateWaypoints : ApiServiceRequest, ILogRequest
{
/**
* Array of waypoints
*/
// @ApiMember(Description="Array of waypoints", IsRequired=true)
public var waypoints:[RequestQuoteWaypoint] = []
/**
* Set this to true to prevent while testing the API.
*/
// @ApiMember(Description="Set this to true to prevent while testing the API.", IsRequired=true)
public var test:Bool
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case waypoints
case test
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
waypoints = try container.decodeIfPresent([RequestQuoteWaypoint].self, forKey: .waypoints) ?? []
test = try container.decodeIfPresent(Bool.self, forKey: .test)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if waypoints.count > 0 { try container.encode(waypoints, forKey: .waypoints) }
if test != nil { try container.encode(test, forKey: .test) }
}
}
public class ApiServiceRequest : IServiceRequest, IHasApiKey, Codable
{
/**
* The API Key required for authentication
*/
// @ApiMember(DataType="string", Description="The API Key required for authentication", IsRequired=true)
public var apiKey:String
required public init(){}
}
public class RequestQuoteWaypoint : IRequestWaypoint, Codable
{
/**
* Number of waypoint for ordering
*/
// @ApiMember(Description="Number of waypoint for ordering", IsRequired=true)
public var waypointNumber:Int
/**
* Waypoint Latitude
*/
// @ApiMember(Description="Waypoint Latitude", IsRequired=true)
public var latitude:Double
/**
* Waypoint Longitude
*/
// @ApiMember(Description="Waypoint Longitude", IsRequired=true)
public var longitude:Double
/**
* Name of contact person at waypoint
*/
// @ApiMember(Description="Name of contact person at waypoint", IsRequired=true)
public var contactName:String
/**
* Telephone number of contact person at waypoint
*/
// @ApiMember(Description="Telephone number of contact person at waypoint", IsRequired=true)
public var contactNumber:String
/**
* Instructions for driver to follow at waypoint
*/
// @ApiMember(Description="Instructions for driver to follow at waypoint", IsRequired=true)
public var deliveryInstructions:String
/**
* Waypoint address
*/
// @ApiMember(Description="Waypoint address", IsRequired=true)
public var address:String
required public init(){}
}
public class ValidateWaypointsResponse : ApiServiceResponse
{
/**
* List with validation information for each waypoint
*/
// @ApiMember(Description="List with validation information for each waypoint")
public var waypointValidations:[WaypointValidationInformation] = []
/**
* The total distance for the order
*/
// @ApiMember(Description="The total distance for the order")
public var totalDistance:Double
/**
* The total distance for the order, formatted as a string
*/
// @ApiMember(Description="The total distance for the order, formatted as a string")
public var totalDistanceValue:String
/**
* List of information for pricing etc between each waypoint
*/
// @ApiMember(Description="List of information for pricing etc between each waypoint")
public var waypoints:[WaypointQuoteInformation] = []
/**
* Is there an issue for the waypoints details specified?
*/
// @ApiMember(Description="Is there an issue for the waypoints details specified?")
public var waypointIssue:Bool
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case waypointValidations
case totalDistance
case totalDistanceValue
case waypoints
case waypointIssue
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
waypointValidations = try container.decodeIfPresent([WaypointValidationInformation].self, forKey: .waypointValidations) ?? []
totalDistance = try container.decodeIfPresent(Double.self, forKey: .totalDistance)
totalDistanceValue = try container.decodeIfPresent(String.self, forKey: .totalDistanceValue)
waypoints = try container.decodeIfPresent([WaypointQuoteInformation].self, forKey: .waypoints) ?? []
waypointIssue = try container.decodeIfPresent(Bool.self, forKey: .waypointIssue)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if waypointValidations.count > 0 { try container.encode(waypointValidations, forKey: .waypointValidations) }
if totalDistance != nil { try container.encode(totalDistance, forKey: .totalDistance) }
if totalDistanceValue != nil { try container.encode(totalDistanceValue, forKey: .totalDistanceValue) }
if waypoints.count > 0 { try container.encode(waypoints, forKey: .waypoints) }
if waypointIssue != nil { try container.encode(waypointIssue, forKey: .waypointIssue) }
}
}
public class ApiServiceResponse : IServiceResponse, Codable
{
/**
* Information about the response.
*/
// @ApiMember(Description="Information about the response.", IsRequired=true)
public var Description:String
/**
* Heading or summary of the response.
*/
// @ApiMember(Description="Heading or summary of the response.", IsRequired=true)
public var heading:String
/**
* Did the intended operation for this response complete successfully?
*/
// @ApiMember(DataType="boolean", Description="Did the intended operation for this response complete successfully?", IsRequired=true)
public var wasSuccessful:Bool
required public init(){}
}
public class WaypointValidationInformation : Codable
{
public var waypointNumber:Int
public var isValid:Bool
public var errorMessages:[String] = []
required public init(){}
}
public class WaypointQuoteInformation : LinkedWaypoint
{
/**
* Distance between waypoints as a number
*/
// @ApiMember(Description="Distance between waypoints as a number")
public var distance:Double
/**
* String formatted distance
*/
// @ApiMember(Description="String formatted distance")
public var distanceValue:String
public var waypointValid:Bool
public var message:String
public var errorDetails:[String] = []
/**
* Caculated price between waypoints excluding vat
*/
// @ApiMember(Description="Caculated price between waypoints excluding vat")
public var price:Double
/**
* Price excluding vat formatted as a string rand value
*/
// @ApiMember(Description="Price excluding vat formatted as a string rand value")
public var priceValue:String
/**
* The price between waypoints including vat
*/
// @ApiMember(Description="The price between waypoints including vat")
public var priceWithVAT:Double
/**
* The price including vat formatted as a rand value string
*/
// @ApiMember(Description="The price including vat formatted as a rand value string")
public var priceValueWithVAT:String
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case distance
case distanceValue
case waypointValid
case message
case errorDetails
case price
case priceValue
case priceWithVAT
case priceValueWithVAT
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
distance = try container.decodeIfPresent(Double.self, forKey: .distance)
distanceValue = try container.decodeIfPresent(String.self, forKey: .distanceValue)
waypointValid = try container.decodeIfPresent(Bool.self, forKey: .waypointValid)
message = try container.decodeIfPresent(String.self, forKey: .message)
errorDetails = try container.decodeIfPresent([String].self, forKey: .errorDetails) ?? []
price = try container.decodeIfPresent(Double.self, forKey: .price)
priceValue = try container.decodeIfPresent(String.self, forKey: .priceValue)
priceWithVAT = try container.decodeIfPresent(Double.self, forKey: .priceWithVAT)
priceValueWithVAT = try container.decodeIfPresent(String.self, forKey: .priceValueWithVAT)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if distance != nil { try container.encode(distance, forKey: .distance) }
if distanceValue != nil { try container.encode(distanceValue, forKey: .distanceValue) }
if waypointValid != nil { try container.encode(waypointValid, forKey: .waypointValid) }
if message != nil { try container.encode(message, forKey: .message) }
if errorDetails.count > 0 { try container.encode(errorDetails, forKey: .errorDetails) }
if price != nil { try container.encode(price, forKey: .price) }
if priceValue != nil { try container.encode(priceValue, forKey: .priceValue) }
if priceWithVAT != nil { try container.encode(priceWithVAT, forKey: .priceWithVAT) }
if priceValueWithVAT != nil { try container.encode(priceValueWithVAT, forKey: .priceValueWithVAT) }
}
}
public class LinkedWaypoint : Codable
{
public var fromWaypointNumber:Int
public var toWaypointNumber:Int
public var fromLatitude:Double
public var fromLongitude:Double
public var toLatitude:Double
public var toLongitude:Double
required public init(){}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .csv suffix or ?format=csv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /quote/validatewaypoints HTTP/1.1
Host: api.1fetch.co.za
Accept: text/csv
Content-Type: text/csv
Content-Length: length
{"Waypoints":[{"WaypointNumber":0,"Latitude":0,"Longitude":0,"ContactName":"String","ContactNumber":"String","DeliveryInstructions":"String","Address":"String"}],"Test":false,"ApiKey":"String"}
HTTP/1.1 200 OK
Content-Type: text/csv
Content-Length: length
{Unable to show example output for type 'ValidateWaypointsResponse' using the custom 'csv' filter}One or more errors occurred. (Object reference not set to an instance of an object.)