Getting started

The Gini library provides ways to interact with the Gini API and therefore, adds the possiblity to scan documents and retrieve the extractions from them.

Initializing the library

To initialize the library, you just need to provide the API credentials:

    let sdk = GiniSDK
        .Builder(client: Client(id: "your-id",
                                secret: "your-secret",
                                domain: "your-domain"))
        .build()

Optionally if you want to use Certificate pinning, or use the Accounting API, you can pass both your public key pinning configuration (see TrustKit repo for more information) and the API type (the Gini API is used by default) as follows:

    let yourPublicPinningConfig = [
      kTSKPinnedDomains: [
        "api.gini.net": [
          kTSKPublicKeyHashes: [
            // old *.gini.net public key
            "cNzbGowA+LNeQ681yMm8ulHxXiGojHE8qAjI+M7bIxU=",
            // new *.gini.net public key, active from around June 2020
            "zEVdOCzXU8euGVuMJYPr3DUU/d1CaKevtr0dW0XzZNo="
        ]],
        "user.gini.net": [
          kTSKPublicKeyHashes: [
            // old *.gini.net public key
            "cNzbGowA+LNeQ681yMm8ulHxXiGojHE8qAjI+M7bIxU=",
            // new *.gini.net public key, active from around June 2020
            "zEVdOCzXU8euGVuMJYPr3DUU/d1CaKevtr0dW0XzZNo="
        ]],
    ]] as [String: Any]

    let sdk = GiniSDK
        .Builder(client: Client(id: "your-id",
                                secret: "your-secret",
                                domain: "your-domain"),
                 api: .accounting,
                 pinningConfig: yourPublicPinningConfig)
        .build()

The current Gini API public key SHA256 hash digest in Base64 encoding can be extracted with the following openssl commands:

$ openssl s_client -servername gini.net -connect gini.net:443 | openssl x509 -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

If you want to use a transparent proxy with your own authentication you can specify your own domain and an AlternativeTokenSource implementation:

    let sdk = GiniSDK
        .Builder(customApiDomain: "api.custom.net", 
                 alternativeTokenSource: MyAlternativeTokenSource)
        .build()

The token your provide will be added as a bearer token to all api.custom.net requests.

Using the library

Now that the GiniSDK has been initialized, you can start using it. To do so, just get the Document service from it.

On one hand, if you choose to continue with the default Document service, you should use the DefaultDocumentService:

let documentService: DefaultDocumentService = sdk.documentService()

On the other hand, if you prefer to use the accounting Document service, just use the AccountingDocumentService as follows:

let documentService: AccountingDocumentService = sdk.documentService()

You are all set 🚀! You can start using the Gini API through the documentService.