Skip to content

Commit

Permalink
Release version 3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Team Mobile Schorsch committed Sep 4, 2024
1 parent f1296a9 commit 3758f10
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 83 deletions.
4 changes: 2 additions & 2 deletions Documentation/source/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Once you have your Swift package set up, adding `GiniBankAPILibrary` as a depend

```swift
dependencies: [
.package(url: "https://github.com/gini/bank-api-library-ios.git", .exact("3.2.0"))
.package(url: "https://github.com/gini/bank-api-library-ios.git", .exact("3.3.0"))
]
```

In case that you want to use the certificate pinning in the library, add `GiniBankAPILibraryPinning`:
```swift
dependencies: [
.package(url: "https://github.com/gini/bank-api-library-pinning-ios.git", .exact("3.2.0"))
.package(url: "https://github.com/gini/bank-api-library-pinning-ios.git", .exact("3.3.0"))
]
```

Expand Down
4 changes: 2 additions & 2 deletions Documentation/source/License.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Always make sure to ship all license notices and permissions with your applicati

## The Gini Bank API Library for iOS is licensed under a Private License.

Copyright (c) 2014-2023, Gini GmbH
Copyright (c) 2014-2024, Gini GmbH
All rights reserved.

The Gini Bank API Library is licensed through Gini GmbH ("Gini") and may not be
Expand All @@ -20,7 +20,7 @@ Always make sure to ship all license notices and permissions with your applicati

## The Gini Bank API Library Pinning for iOS is licensed under a Private License.

Copyright (c) 2014-2023, Gini GmbH
Copyright (c) 2014-2024, Gini GmbH
All rights reserved.

The Gini Bank API Library Pinning is licensed through Gini GmbH ("Gini") and may not be
Expand Down
1 change: 1 addition & 0 deletions Sources/GiniBankAPILibrary/Documents/APIMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum APIMethod: ResourceMethod {
case pages(forDocumentId: String)
case page(forDocumentId: String, number: Int, size: Document.Page.Size?)
case pagePreview(forDocumentId: String, number: Int)
case documentPage(forDocumentId: String, number: Int, size: Document.Page.Size)
case processedDocument(withId: String)
case paymentRequest(id: String)
case paymentRequests(limit: Int?, offset: Int?)
Expand Down
6 changes: 4 additions & 2 deletions Sources/GiniBankAPILibrary/Documents/APIResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ struct APIResource<T: Decodable>: Resource {
}
case .pagePreview(let id, let number):
return "/documents/\(id)/pages/\(number)/large"
case .documentPage(let id, let number, let sizeType):
return "/documents/\(id)/pages/\(number)/\(sizeType)"
case .partial:
return "/documents/partial"
case .processedDocument(let id):
Expand Down Expand Up @@ -134,9 +136,9 @@ struct APIResource<T: Decodable>: Resource {
subtype: documentType?.name,
mimeSubtype: mimeSubType).value
]
case .page, .pagePreview(_, _):
case .page, .pagePreview, .documentPage:
return [:]
case .paymentRequests(_, _) :
case .paymentRequests:
return ["Accept": ContentType.content(version: apiVersion,
subtype: nil,
mimeSubtype: "json").value]
Expand Down
59 changes: 39 additions & 20 deletions Sources/GiniBankAPILibrary/Documents/DefaultDocumentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public final class DefaultDocumentService: DefaultDocumentServiceProtocol {
/**
* Retrieves the layout of a given document
*
* - Parameter id: The document's unique identifier
* - Parameter document: The document from which to retrieve the layout
* - Parameter completion: A completion callback, returning the requested document layout on success
*/
public func layout(for document: Document, completion: @escaping CompletionResult<Document.Layout>) {
Expand All @@ -165,7 +165,7 @@ public final class DefaultDocumentService: DefaultDocumentServiceProtocol {
/**
* Retrieves the pages of a given document
*
* - Parameter id: The document's unique identifier
* - Parameter document: The document from which to retrieve the pages
* - Parameter completion: A completion callback, returning the requested document layout on success
*/
public func pages(in document: Document, completion: @escaping CompletionResult<[Document.Page]>) {
Expand All @@ -190,7 +190,43 @@ public final class DefaultDocumentService: DefaultDocumentServiceProtocol {
size: size,
completion: completion)
}


/**
* Retrieves the page preview of a document for a given page
*
* - Parameter documentId: Document id to get the preview for
* - Parameter pageNumber: The document's page number starting from 1
* - Parameter completion: A completion callback, returning the requested page preview as Data on success
*/
public func preview(for documentId: String,
pageNumber: Int,
completion: @escaping CompletionResult<Data>) {

preview(resourceHandler: sessionManager.download,
with: documentId,
pageNumber: pageNumber,
completion: completion)
}

/**
* Retrieves the page data of a document for a given page number and size
*
* - Parameter document: The document from which to retrieve the page data
* - Parameter pageNumber: The document's page number
* - Parameter size: The size of the page to retrieve (e.g., large, medium)
* - Parameter completion: A completion callback, returning the requested page preview on success, or an error on failure
*/
public func documentPage(for document: Document,
pageNumber: Int,
size: Document.Page.Size,
completion: @escaping CompletionResult<Data>) {
documentPage(resourceHandler: sessionManager.download,
in: document,
pageNumber: pageNumber,
size: size,
completion: completion)
}

/**
* Submits the analysis feedback for a given document.
*
Expand Down Expand Up @@ -218,24 +254,7 @@ public final class DefaultDocumentService: DefaultDocumentServiceProtocol {
completion: @escaping CompletionResult<Void>) {
submitFeedback(resourceHandler: sessionManager.data, for: document, with: extractions, and: compoundExtractions, completion: completion)
}

/**
* Retrieves the page preview of a document for a given page
*
* - Parameter documentId: Document id to get the preview for
* - Parameter pageNumber: The document's page number starting from 1
* - Parameter completion: A completion callback, returning the requested page preview as Data on success
*/
public func preview(for documentId: String,
pageNumber: Int,
completion: @escaping CompletionResult<Data>) {

preview(resourceHandler: sessionManager.download,
with: documentId,
pageNumber: pageNumber,
completion: completion)
}

/**
* Logs an error event.
*
Expand Down
2 changes: 1 addition & 1 deletion Sources/GiniBankAPILibrary/Documents/Document+Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Document+Layout.swift
// GiniBankAPI
//
// Created by Enrique del Pozo Gómez on 3/21/19.
// Copyright © 2024 Gini GmbH. All rights reserved.
//

import Foundation
Expand Down
8 changes: 5 additions & 3 deletions Sources/GiniBankAPILibrary/Documents/Document+Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ extension Document.Page: Decodable {
let container = try decoder.container(keyedBy: CodingKeys.self)
let pageNumber = try container.decode(Int.self, forKey: .number)
let images = try container.decode([String: String].self, forKey: .images)

let imagesFormatted: [(size: Size, url: URL)] = images.compactMap { image in
guard let imageSize = Size(rawValue: image.key) else {
guard let imageSize = Size(rawValue: image.key),
let url = URL(string: image.value) else {
return nil
}
return (imageSize, URL(string: image.value)!)

return (imageSize, url)
}

self.init(number: pageNumber, images: imagesFormatted)
Expand Down
9 changes: 5 additions & 4 deletions Sources/GiniBankAPILibrary/Documents/Document.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//
// Document.swift
// Pods-GiniExample
//
// Created by Enrique del Pozo Gómez on 1/14/18.
// Copyright © 2024 Gini GmbH. All rights reserved.
//

import Foundation
Expand Down Expand Up @@ -193,7 +192,7 @@ extension Document {
public let number: Int
/// Page image urls array, along with their sizes
public let images: [(size: Size, url: URL)]

//swiftlint:disable nesting
enum CodingKeys: String, CodingKey {
case number = "pageNumber"
Expand All @@ -207,8 +206,10 @@ extension Document {

/// 1280x1810
case big = "1280x1810"

case large
case medium
}

}

/// The V2 document's type. Used when creating documents in multipage mode.
Expand Down
133 changes: 86 additions & 47 deletions Sources/GiniBankAPILibrary/Documents/DocumentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,20 @@ public protocol DocumentService: AnyObject {
pageNumber: Int,
size: Document.Page.Size,
completion: @escaping CompletionResult<Data>)


/**
* Retrieves the page data of a document for a given page number and size
*
* - Parameter document: The document from which to retrieve the page data
* - Parameter pageNumber: The document's page number
* - Parameter size: The size of the page to retrieve (e.g., large, medium)
* - Parameter completion: A completion callback, returning the requested page preview on success, or an error on failure
*/
func documentPage(for document: Document,
pageNumber: Int,
size: Document.Page.Size,
completion: @escaping CompletionResult<Data>)

/**
* Submits the analysis feedback for a given document.
*
Expand Down Expand Up @@ -217,8 +230,8 @@ extension DocumentService {

resourceHandler(resource, { result in
switch result {
case .success(let document):
completion(.success(document))
case .success(let documentLayout):
completion(.success(documentLayout))
case .failure(let error):
completion(.failure(error))
}
Expand All @@ -234,8 +247,8 @@ extension DocumentService {

resourceHandler(resource, { result in
switch result {
case .success(let document):
completion(.success(document))
case .success(let pages):
completion(.success(pages))
case .failure(let error):
completion(.failure(error))
}
Expand Down Expand Up @@ -285,33 +298,59 @@ extension DocumentService {
}

func preview(resourceHandler: @escaping ResourceDataHandler<APIResource<Data>>,
with documentId: String,
pageNumber: Int,
completion: @escaping CompletionResult<Data>) {
let resource = APIResource<Data>(method: .pagePreview(forDocumentId: documentId,
number: pageNumber),
apiDomain: self.apiDomain,
httpMethod: .get)
resourceHandler(resource) { result in
switch result {
case let .success(data):
completion(.success(data))
case let .failure(error):
if case .notFound = error {
print("Document \(documentId) page not found")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.preview(resourceHandler: resourceHandler,
with: documentId,
pageNumber: pageNumber,
completion: completion)
}
} else {
completion(.failure(error))
}
}
}
}

with documentId: String,
pageNumber: Int,
completion: @escaping CompletionResult<Data>) {
let resource = APIResource<Data>(method: .pagePreview(forDocumentId: documentId,
number: pageNumber),
apiDomain: self.apiDomain,
httpMethod: .get)
resourceHandler(resource) { result in
switch result {
case let .success(data):
completion(.success(data))
case let .failure(error):
if case .notFound = error {
print("Document \(documentId) page not found")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.preview(resourceHandler: resourceHandler,
with: documentId,
pageNumber: pageNumber,
completion: completion)
}
} else {
completion(.failure(error))
}
}
}
}

func documentPage(resourceHandler: @escaping ResourceDataHandler<APIResource<Data>>,
in document: Document,
pageNumber: Int,
size: Document.Page.Size,
completion: @escaping CompletionResult<Data>) {
guard pageNumber > 0 else {
preconditionFailure("The page number starts at 1")
}

let resource = APIResource<Data>(method: .documentPage(forDocumentId: document.id,
number: pageNumber,
size: .medium),
apiDomain: apiDomain,
httpMethod: .get)

resourceHandler(resource) { result in
switch result {
case .success(let data):
completion(.success(data))
case .failure(let error):
completion(.failure(error))
}
}
}


func submitFeedback(resourceHandler: ResourceDataHandler<APIResource<String>>,
for document: Document,
with extractions: [Extraction],
Expand Down Expand Up @@ -401,22 +440,22 @@ fileprivate extension DocumentService {
fetchDocument(resourceHandler: resourceHandler,
with: document.id,
cancellationToken: cancellationToken) { [weak self] result in
guard let self = self else { return }
switch result {
case .success(let document):
if document.progress != .pending {
completion(.success(()))
} else {
DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
self.poll(resourceHandler: resourceHandler,
document: document,
cancellationToken: cancellationToken,
completion: completion)
}
}
case .failure(let error):
completion(.failure(error))
guard let self = self else { return }
switch result {
case .success(let document):
if document.progress != .pending {
completion(.success(()))
} else {
DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
self.poll(resourceHandler: resourceHandler,
document: document,
cancellationToken: cancellationToken,
completion: completion)
}
}
case .failure(let error):
completion(.failure(error))
}
}
}
}
2 changes: 1 addition & 1 deletion Sources/GiniBankAPILibrary/GiniBankAPILibraryVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Copyright © 2024 Gini GmbH. All rights reserved.
//

public let GiniBankAPILibraryVersion = "3.2.0"
public let GiniBankAPILibraryVersion = "3.3.0"
2 changes: 1 addition & 1 deletion Tests/GiniBankAPILibraryTests/DocumentServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ final class DocumentServicesTests: XCTestCase {
osName: UIDevice.current.systemName,
osVersion: UIDevice.current.systemVersion,
captureSdkVersion: "Not available",
apiLibVersion: "3.2.0",
apiLibVersion: "3.3.0",
description: "Error logging test",
documentId: "1234",
originalRequestId: "5678")
Expand Down

0 comments on commit 3758f10

Please sign in to comment.