ScannerVision Web Server

<back to all web services

GetTemplate

Requires Authentication
The following routes are available for this service:
GET/{Brand}/templates/{TemplateGuid}
GET/{Brand}/templates/{TemplateGuid}/{RetainMetadata}
import Foundation
import ServiceStack

public class GetTemplate : RequestBase
{
    public var templateGuid:String
    public var retainMetadata:Bool

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case templateGuid
        case retainMetadata
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        templateGuid = try container.decodeIfPresent(String.self, forKey: .templateGuid)
        retainMetadata = try container.decodeIfPresent(Bool.self, forKey: .retainMetadata)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if templateGuid != nil { try container.encode(templateGuid, forKey: .templateGuid) }
        if retainMetadata != nil { try container.encode(retainMetadata, forKey: .retainMetadata) }
    }
}

public class RequestBase : DtoBase
{
    required public init(){ super.init() }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
    }
}

public class DtoBase : Codable
{
    public var brand:Brand

    required public init(){}
}

public enum Brand : String, Codable
{
    case Desktop
    case Hp
    case Kyocera
    case NeaScan
    case Samsung
    case FujiXerox
    case Ta
    case Utax
    case Epson
    case ScanFront400
    case Sharp
    case Ricoh
    case FujiFilm
}

public class GetTemplateResponse : ScanResponseBase
{
    public var serverAddress:String
    public var serverPort:Int

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case serverAddress
        case serverPort
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        serverAddress = try container.decodeIfPresent(String.self, forKey: .serverAddress)
        serverPort = try container.decodeIfPresent(Int.self, forKey: .serverPort)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if serverAddress != nil { try container.encode(serverAddress, forKey: .serverAddress) }
        if serverPort != nil { try container.encode(serverPort, forKey: .serverPort) }
    }
}

public class ScanResponseBase : ResponseBase
{
    //template:IClientTemplate ignored. Swift doesn't support interface properties
    public var globalQuestions:[IClientQuestion] = []
    public var canEnableScanButton:Bool

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case template
        case globalQuestions
        case canEnableScanButton
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        template = try container.decodeIfPresent(IClientTemplate.self, forKey: .template)
        globalQuestions = try container.decodeIfPresent([IClientQuestion].self, forKey: .globalQuestions) ?? []
        canEnableScanButton = try container.decodeIfPresent(Bool.self, forKey: .canEnableScanButton)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if template != nil { try container.encode(template, forKey: .template) }
        if globalQuestions.count > 0 { try container.encode(globalQuestions, forKey: .globalQuestions) }
        if canEnableScanButton != nil { try container.encode(canEnableScanButton, forKey: .canEnableScanButton) }
    }
}

public class ResponseBase : DtoBase
{
    public var selectedUiLanguage:String
    public var svSession:String
    public var title:String
    public var pageTip:String
    public var newBrowser:Bool
    public var scanFront400TA:Bool
    public var scanFront400UTAX:Bool

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case selectedUiLanguage
        case svSession
        case title
        case pageTip
        case newBrowser
        case scanFront400TA
        case scanFront400UTAX
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        selectedUiLanguage = try container.decodeIfPresent(String.self, forKey: .selectedUiLanguage)
        svSession = try container.decodeIfPresent(String.self, forKey: .svSession)
        title = try container.decodeIfPresent(String.self, forKey: .title)
        pageTip = try container.decodeIfPresent(String.self, forKey: .pageTip)
        newBrowser = try container.decodeIfPresent(Bool.self, forKey: .newBrowser)
        scanFront400TA = try container.decodeIfPresent(Bool.self, forKey: .scanFront400TA)
        scanFront400UTAX = try container.decodeIfPresent(Bool.self, forKey: .scanFront400UTAX)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if selectedUiLanguage != nil { try container.encode(selectedUiLanguage, forKey: .selectedUiLanguage) }
        if svSession != nil { try container.encode(svSession, forKey: .svSession) }
        if title != nil { try container.encode(title, forKey: .title) }
        if pageTip != nil { try container.encode(pageTip, forKey: .pageTip) }
        if newBrowser != nil { try container.encode(newBrowser, forKey: .newBrowser) }
        if scanFront400TA != nil { try container.encode(scanFront400TA, forKey: .scanFront400TA) }
        if scanFront400UTAX != nil { try container.encode(scanFront400UTAX, forKey: .scanFront400UTAX) }
    }
}

public protocol IClientTemplate
{
    var Description:String { get set }
    var icon:[UInt8] { get set }
    //modificationInfo:ITemplateModificationInfo ignored. Swift doesn't support interface properties
    var name:String { get set }
    var questions:[IClientQuestion] { get set }
    //template:ITemplate ignored. Swift doesn't support interface properties
    var templateGuid:String { get set }

}

public protocol ITemplateModificationInfo
{
    var guid:String { get set }
    var templateModificationDateTime:Date { get set }
    var iconModificationDateTime:Date { get set }

}

public protocol IClientQuestion : ITemplateQuestion
{
    var questionGuid:String { get set }
    var valueDisplayed:String { get set }
    var valueReturned:String { get set }
    var answered:Bool { get set }
    var regexMatches:Bool { get set }
    var regexHint:String { get set }

}

public protocol ITemplate : IStatus
{
    var templateVersion:String { get set }
    var scannerVisionVersion:String { get set }
    var guid:String { get set }
    var beginScript:String { get set }
    var endScript:String { get set }
    var templateType:TemplateType { get set }
    //general:IGeneral ignored. Swift doesn't support interface properties
    //capture:ICapture ignored. Swift doesn't support interface properties
    //xmlMetadataImport:IXmlMetadataImport ignored. Swift doesn't support interface properties
    //notifications:INotifications ignored. Swift doesn't support interface properties
    //validator:IValidator ignored. Swift doesn't support interface properties

}

public enum TemplateType : String, Codable
{
    case Workflow
    case FreeForm
}

public protocol IGeneral : IInterface
{
    var name:String { get set }
    var Description:String { get set }
    var icon:String { get set }
    //schedule:ITemplateSchedule ignored. Swift doesn't support interface properties
    //rejection:IRejection ignored. Swift doesn't support interface properties
    //badDocumentRejection:IBadDocumentRejection ignored. Swift doesn't support interface properties
    var pdfLoadResolution:PdfLoadResolution? { get set }

}

public protocol ITemplateSchedule : IInterface
{
    var time:TimeInterval? { get set }
    var endTime:TimeInterval? { get set }
    var noEndTime:Bool? { get set }
    var type:TemplateScheduleType? { get set }

}

public enum TemplateScheduleType : String, Codable
{
    case Interval
    case Fixed
}

public protocol IRejection
{
    var rejectAfter:Int? { get set }
    var rejectionPath:String { get set }
    //shareCredentials:ICredentials ignored. Swift doesn't support interface properties

}

public protocol ICredentials : IInterface
{
    var username:String { get set }
    var password:String { get set }

}

public protocol IBadDocumentRejection : IStatus
{
    var rejectionPath:String { get set }
    //shareCredentials:ICredentials ignored. Swift doesn't support interface properties

}

public enum PdfLoadResolution : String, Codable
{
    case Default
    case Dpi100
    case Dpi150
    case Dpi200
    case Dpi300
    case Dpi400
    case Dpi500
    case Dpi600
}

public protocol ICapture : IInterface
{
    var captureSources:ReadOnlyCollection<ICaptureSource> { get set }

}

public protocol ICaptureSource : IStatus
{
}

public protocol IXmlMetadataImport : IStatus
{
    var sampleDocumentName:String { get set }
    var tagMappings:ReadOnlyCollection<IXmlMetadataImportTagMapping> { get set }
    var namespaceMappings:ReadOnlyCollection<IXmlMetadataImportNamespaceMapping> { get set }

}

public protocol IXmlMetadataImportTagMapping : IInterface
{
    var xPathExpression:String { get set }
    //metadata:IStringMetadata ignored. Swift doesn't support interface properties

}

public protocol IStringMetadata : IMetadata
{
    var isSecure:Bool? { get set }
    var sampleValue:String { get set }
    var value:String { get set }

}

public protocol IXmlMetadataImportNamespaceMapping : IInterface
{
    var `prefix`:String { get set }
    var name:String { get set }

}

public protocol INotifications : IStatus
{
    var notifications:ReadOnlyCollection<INotification> { get set }

}

public protocol INotification : IStatus
{
    var Description:String { get set }
    var to:String { get set }
    var subject:String { get set }
    var body:String { get set }
    var cc:String { get set }
    var bcc:String { get set }
    var notificationType:NotificationType? { get set }

}

public enum NotificationType : String, Codable
{
    case FailureOnly
    case SuccessOnly
    case Always
}

public protocol IValidator
{
    //validationErrors:IValidationErrors ignored. Swift doesn't support interface properties
    var isValid:Bool { get set }

}

public protocol IValidationErrors
{
    var errors:ReadOnlyCollection<IValidationError> { get set }

}

public protocol IValidationError
{
    var property:String { get set }
    var errorMessage:String { get set }

}


Swift GetTemplate DTOs

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

HTTP + JSON

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

GET /{Brand}/templates/{TemplateGuid} HTTP/1.1 
Host: buildmax.org 
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"ServerAddress":"String","ServerPort":0,"CanEnableScanButton":true,"SelectedUiLanguage":"String","svSession":"String","Title":"String","PageTip":"String","NewBrowser":false,"ScanFront400TA":false,"ScanFront400UTAX":false,"Brand":"Desktop"}