目录
目录README.md

VismaSign

Build_Status

Description

The library is intended to implement an interface for the API documented here and here It is written in Swift 4.2 on Fedora and is useable in both Linux and macOS.

Requirements

  • Swift >= 4.2
  • OpenSSL (libssl-dev package should be available on Linux)

Dependencies

Build && Test

cd path/to/project
swift build
swift test
swift run

Usage

The library introduces the following protocols for making API requests:

  • APIServiceGeneralRequest: If you have a request which doesn’t need any special headers, you can confrim to this protocol in your APIRequest struct
  • APIServiceOrganizationRequest: The protocol is designed for organizational request where authorization is applied as defined here
  • APIServicePartnerRequest: The protocol is designed for partner request where the Oath authorization is applied as defiend here

APIServiceOrganizationRequest example

You can easily create organizational request by conforming to the protocol. The headers will be applied automatically

struct OrganizationRequest: APIServiceOrganizationRequest {

    typealias BodyType = RequestBody
    typealias ReturnType = EmptyModel

    var host: String! = "your_host_here" // can be set on *APIServiceRequest* extension for global usages
    var path: String = "API_path_here"
    var httpMethod: HTTPMethod = .post
    var bodyData: BodyType?
    var secret: String!
    var clientID: String!
    
    init(clientID: String, secret: String) {
        self.clientID = clientID
        self.secret = secret
        
        bodyData = RequestBody(name: "name")
    }

    struct RequestBody: Encodable {
        let name: String
    }
}

APIServicePartnerRequest example

You can easily create partner request by conforming to the protocol. To initiate a new PartnerRequest you need to inject AccessTokenModel containing required information for Oath authentication.

struct PartnerRequest: APIServicePartnerRequest {
    typealias BodyType = EmptyModel
    typealias ReturnType = String

    var host: String! = "your_host_here" // can be set on *APIServiceRequest* extension for global usages
    var path: String = "API_path_here"
    var httpMethod: HTTPMethod = .post
    var bodyData: BodyType?
    var accessTokenModel: AccessTokenModel!

    init(accessTokenModel: AccessTokenModel) {
        self.accessTokenModel = accessTokenModel
    }
}
关于
64.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号