Skip to content

Commit

Permalink
Release version 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Team Mobile Schorsch committed Jun 14, 2024
1 parent afa94da commit f5a7ceb
Show file tree
Hide file tree
Showing 31 changed files with 680 additions and 169 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 `GiniHealthAPILibrary` as a depe

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

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

Expand Down
4 changes: 3 additions & 1 deletion Sources/GiniHealthAPILibrary/Documents/APIMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// APIMethod.swift
// GiniHealthAPI
//
// Created by Enrique del Pozo Gómez on 3/4/19.
// Copyright © 2024 Gini GmbH. All rights reserved.
//

import Foundation
Expand Down Expand Up @@ -31,4 +31,6 @@ enum APIMethod: ResourceMethod {
case paymentRequest(id: String)
case paymentRequests(limit: Int?, offset: Int?)
case file(urlString: String)
case payment(id: String)
case pdfWithQRCode(paymentRequestId: String)
}
17 changes: 10 additions & 7 deletions Sources/GiniHealthAPILibrary/Documents/APIResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@
// APIResource.swift
// GiniHealthAPI
//
// Created by Enrique del Pozo Gómez on 1/18/18.
// Copyright © 2024 Gini GmbH. All rights reserved.
//

import Foundation

public enum APIDomain {
/// The default one, which points to https://health-api.gini.net
case `default`
/// The GYM API, which points to https://gym.gini.net/
case gym(tokenSource: AlternativeTokenSource)
/// A custom domain with optional custom token source
case custom(domain: String, tokenSource: AlternativeTokenSource?)

var domainString: String {

switch self {
case .default: return "health-api.gini.net"
case .gym: return "gym.gini.net"
case .custom(let domain, _): return domain
}
}
Expand All @@ -46,9 +43,7 @@ struct APIResource<T: Decodable>: Resource {

var apiVersion: Int {
switch domain {
case .default: return 3
case .gym: return 2
case .custom: return 3
case .default, .custom: return 4
}
}

Expand Down Expand Up @@ -108,6 +103,10 @@ struct APIResource<T: Decodable>: Resource {
return "/paymentRequests"
case .file(urlString: let urlString):
return urlString
case .payment(let id):
return "/paymentRequests/\(id)/payment"
case .pdfWithQRCode(paymentRequestId: let paymentRequestId):
return "/paymentRequests/\(paymentRequestId)"
}
}

Expand All @@ -127,6 +126,10 @@ struct APIResource<T: Decodable>: Resource {
return ["Accept": ContentType.content(version: apiVersion,
subtype: nil,
mimeSubtype: "json").value]
case .pdfWithQRCode(_):
return ["Accept": ContentType.content(version: apiVersion,
subtype: nil,
mimeSubtype: "qr+pdf").value]
default:
return ["Accept": ContentType.content(version: apiVersion,
subtype: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum ContentType {
case .json:
return "application/json"
case .content( _, let subtype, let mimeSubtype):
return "application/vnd.gini.v3" + (subtype == nil ? "" : ".\(subtype!)") + "+\(mimeSubtype)"
return "application/vnd.gini.v4" + (subtype == nil ? "" : ".\(subtype!)") + "+\(mimeSubtype)"
case .formUrlEncoded:
return "application/x-www-form-urlencoded"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Foundation
/// The Gini Health API Library
public final class GiniHealthAPI {

private let docService: DocumentService!
private let payService: PaymentService?
private var docService: DocumentService!
private var payService: PaymentService?
static var logLevel: LogLevel = .none
public var sessionDelegate: URLSessionDelegate? = nil

Expand Down Expand Up @@ -121,11 +121,6 @@ extension GiniHealthAPI {
}
return GiniHealthAPI(documentService: DefaultDocumentService(sessionManager: sessionManager, apiDomain: api),
paymentService: PaymentService(sessionManager: sessionManager, apiDomain: api))
case let .gym(tokenSource):
let sessionManager = SessionManager(alternativeTokenSource: tokenSource,
sessionDelegate: self.sessionDelegate)
return GiniHealthAPI(documentService: DefaultDocumentService(sessionManager: sessionManager),
paymentService: PaymentService(sessionManager: sessionManager))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private extension SessionManager {
completion(.failure(.badRequest(response: response, data: data)))
return
}
completion(.failure(.badRequest(response: response, data: data)))
completion(.failure(.unauthorized(response: response, data: data)))
case 401:
completion(.failure(.unauthorized(response: response, data: data)))
case 404:
Expand Down
33 changes: 24 additions & 9 deletions Sources/GiniHealthAPILibrary/Documents/Document.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// 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 @@ -32,7 +32,9 @@ public struct Document {
public let progress: Progress
/// The document's source classification.
public let sourceClassification: SourceClassification

/// The document's expiration date.
public let expirationDate: Date?

fileprivate enum Keys: String, CodingKey {
case compositeDocuments
case creationDate
Expand All @@ -45,6 +47,7 @@ public struct Document {
case partialDocuments
case progress
case sourceClassification
case expirationDate
}
}

Expand Down Expand Up @@ -221,7 +224,8 @@ extension Document: Decodable {
let progress = try container.decode(Progress.self, forKey: .progress)
let sourceClassification = try container.decode(SourceClassification.self,
forKey: .sourceClassification)

let expirationDate = try container.decodeIfPresent(Date.self, forKey: .expirationDate)

self.init(compositeDocuments: compositeDocuments,
creationDate: creationDate,
id: id,
Expand All @@ -232,7 +236,8 @@ extension Document: Decodable {
links: links,
partialDocuments: partialDocuments,
progress: progress,
sourceClassification: sourceClassification)
sourceClassification: sourceClassification,
expirationDate: expirationDate)
}

/**
Expand All @@ -243,24 +248,28 @@ extension Document: Decodable {
- parameter name: The document's file name.
- parameter links: Links to related resources, such as extractions, document, processed, layout or pages.
- parameter sourceClassification: The document's source classification. We recommend to use `scanned` or `composite`.
- parameter expirationDate: The document's expiration date.
- note: Custom networking only.
*/
public init(creationDate: Date,
id: String,
name: String,
links: Links,
sourceClassification: SourceClassification) {
sourceClassification: SourceClassification,
expirationDate: Date?) {
self.init(compositeDocuments: [],
creationDate: creationDate,
id: id, name: name,
id: id,
name: name,
origin: .upload,
pageCount: 1,
pages: [],
links: links,
partialDocuments: [],
progress: .completed,
sourceClassification: sourceClassification)
sourceClassification: sourceClassification,
expirationDate: expirationDate)
}
}

Expand All @@ -271,3 +280,9 @@ extension Document.Links: Decodable {
extension Document.Layout: Decodable {

}

extension Document: Equatable {
public static func == (lhs: Document, rhs: Document) -> Bool {
lhs.id == rhs.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ extension DocumentService {
func file(urlString: String,
resourceHandler: ResourceDataHandler<APIResource<Data>>,
completion: @escaping CompletionResult<Data>) {
var resource = APIResource<Data>(method: .file(urlString: urlString), apiDomain: .default, httpMethod: .get)
var resource = APIResource<Data>(method: .file(urlString: urlString), apiDomain: apiDomain, httpMethod: .get)
resource.fullUrlString = urlString
resourceHandler(resource) { result in
switch result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

struct ExtractionsContainer {
public struct ExtractionsContainer {
let extractions: [Extraction]
let compoundExtractions: [String : [[Extraction]]]?
let candidates: [Extraction.Candidate]
Expand All @@ -23,7 +23,7 @@ struct ExtractionsContainer {

extension ExtractionsContainer: Decodable {

init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

let decodedExtractions = try container.decode([String : Extraction].self,
Expand Down
84 changes: 84 additions & 0 deletions Sources/GiniHealthAPILibrary/Documents/Payments/Payment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// Payment.swift
//
// Copyright © 2024 Gini GmbH. All rights reserved.
//


import Foundation
/**
Struct for payment response
*/
public struct Payment {
/**
An initializer for a `Payment` structure
- parameter paidAt: ISO 8601 date string defining point in time when the payment request was resolved.
- parameter recipient: the recipient of the payment.
- parameter iban: the iban (international bank account number) of the payment recipient.
- parameter bic: the bic (bank identifier code) for the payment.
- parameter purpose: the purpose of the payment, e.g. the invoice or customer identifier.
- parameter links: object with links to other resources e.g. document and paymentRequest.
*/

public init(paidAt: String,
recipient: String,
iban: String,
bic: String? = nil,
amount: String,
purpose: String,
links: PaymentLinks? = nil) {
self.paidAt = paidAt
self.recipient = recipient
self.iban = iban
self.bic = bic
self.amount = amount
self.purpose = purpose
self.links = links
}

public var paidAt, recipient, iban: String
public var bic: String?
public var amount, purpose: String
var links: PaymentLinks?

enum CodingKeys: String, CodingKey {
case paidAt, recipient, iban, bic, amount, purpose
case links = "_links"
}

}

/**
Struct for links in payment response
*/
public struct PaymentLinks: Codable {
var paymentRequest, sourceDocumentLocation, linksSelf: String?

enum CodingKeys: String, CodingKey {
case paymentRequest, sourceDocumentLocation
case linksSelf = "self"
}
}

// MARK: - Decodable

extension Payment: Decodable {

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.paidAt = try container.decode(String.self, forKey: .paidAt)
self.recipient = try container.decode(String.self, forKey: .recipient)
self.iban = try container.decode(String.self, forKey: .iban)

if container.contains(.bic) {
self.bic = try container.decodeIfPresent(String.self, forKey: .bic)
} else {
self.bic = nil
}

self.amount = try container.decode(String.self, forKey: .amount)
self.purpose = try container.decode(String.self, forKey: .purpose)
self.links = try container.decode(PaymentLinks.self, forKey: .links)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ public struct PaymentProvider: Codable {
public var name: String
public var appSchemeIOS: String
public var colors: ProviderColors
var minAppVersion: MinAppVersions?
public var minAppVersion: MinAppVersions?
public var iconData: Data
public var appStoreUrlIOS: String?
public var universalLinkIOS: String
public var index: Int?
public var gpcSupportedPlatforms: [PlatformSupported]
public var openWithSupportedPlatforms: [PlatformSupported]

public init(id: String, name: String, appSchemeIOS: String, minAppVersion: MinAppVersions?, colors: ProviderColors, iconData: Data, appStoreUrlIOS: String?, universalLinkIOS: String) {
public init(id: String, name: String, appSchemeIOS: String, minAppVersion: MinAppVersions?, colors: ProviderColors, iconData: Data, appStoreUrlIOS: String?, universalLinkIOS: String, index: Int?, gpcSupportedPlatforms: [PlatformSupported], openWithSupportedPlatforms: [PlatformSupported]) {
self.id = id
self.name = name
self.appSchemeIOS = appSchemeIOS
Expand All @@ -28,6 +31,15 @@ public struct PaymentProvider: Codable {
self.iconData = iconData
self.appStoreUrlIOS = appStoreUrlIOS
self.universalLinkIOS = universalLinkIOS
self.index = index
self.gpcSupportedPlatforms = gpcSupportedPlatforms
self.openWithSupportedPlatforms = openWithSupportedPlatforms
}
}
public typealias PaymentProviders = [PaymentProvider]

extension PaymentProvider: Equatable {
public static func == (lhs: PaymentProvider, rhs: PaymentProvider) -> Bool {
lhs.id == rhs.id
}
}
Loading

0 comments on commit f5a7ceb

Please sign in to comment.