Skip to content

Commit

Permalink
Release version 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Team Mobile Schorsch committed Apr 19, 2023
1 parent 5a8ba33 commit 6b7a512
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Documentation/sections/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Further documentation with information about how install and integrate it can be

## Requirements

- iOS 12+
- iOS 11+
- Xcode 12+

## Author
Expand Down
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.0.0"))
.package(url: "https://github.com/gini/bank-api-library-ios.git", .exact("1.6.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.0.0"))
.package(url: "https://github.com/gini/bank-api-library-pinning-ios.git", .exact("1.6.0"))
]
```

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "GiniBankAPILibrary",
platforms: [.iOS(.v12)],
platforms: [.iOS(.v11)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Further documentation with information about how install and integrate it can be

## Requirements

- iOS 12+
- iOS 11+
- Xcode 12+

## Author
Expand Down
18 changes: 15 additions & 3 deletions Sources/GiniBankAPILibrary/Documents/APIResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ public enum APIDomain {
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?)
/// A custom domain with optional path and custom token source
case custom(domain: String, path: String? = nil, tokenSource: AlternativeTokenSource?)

var domainString: String {

switch self {
case .default: return "pay-api.gini.net"
case .gym: return "gym.gini.net"
case .custom(let domain, _): return domain
case .custom(let domain, _, _): return domain
}
}

var path: String {
switch self {
case .default: return ""
case .gym: return ""
case .custom(_, let path, _): return path ?? ""
}
}
}
Expand Down Expand Up @@ -70,6 +78,10 @@ struct APIResource<T: Decodable>: Resource {
}

var path: String {
return "\(domain.path)\(methodPath)"
}

private var methodPath: String {
switch method {
case .composite:
return "/documents/composite"
Expand Down
17 changes: 14 additions & 3 deletions Sources/GiniBankAPILibrary/Documents/Core/Auth/UserResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ import Foundation
public enum UserDomain {
/// The default one, which points to https://user.gini.net
case `default`
/// A custom domain
case custom(domain: String)
/// A custom domain with optional path
case custom(domain: String, path: String? = nil)

var domainString: String {

switch self {
case .default: return "user.gini.net"
case .custom(let domain): return domain
case .custom(let domain, _): return domain
}
}

var path: String {
switch self {
case .default: return ""
case .custom(_, let path): return path ?? ""
}
}
}
Expand All @@ -37,6 +44,10 @@ struct UserResource<T: Decodable>: Resource {
}

var path: String {
return "\(domain.path)\(methodPath)"
}

private var methodPath: String {
switch method {
case .token:
return "/oauth/token"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ extension GiniBankAPI {
case .default:
let sessionManager = SessionManager(userDomain: userApi, sessionDelegate: self.sessionDelegate)
return GiniBankAPI(documentService: DefaultDocumentService(sessionManager: sessionManager), paymentService: PaymentService(sessionManager: sessionManager, apiDomain: .default))
case .custom(_, let tokenSource):
case .custom(_, _, let tokenSource):
var sessionManager : SessionManager
if let tokenSource = tokenSource {
sessionManager = SessionManager(alternativeTokenSource: tokenSource, sessionDelegate: self.sessionDelegate)
Expand Down
29 changes: 6 additions & 23 deletions Sources/GiniBankAPILibrary/Documents/Core/GiniError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,16 @@

import Foundation

/**
Protocol representing errors that can occur while interacting with the Gini API.

The protocol defines three properties:
- message: A message describing the error.
- response: The HTTPURLResponse received in the error, if any.
- data: The data received in the error, if any.
*/

public protocol GiniErrorProtocol {
var message: String { get }
var response: HTTPURLResponse? { get }
var data: Data? { get }
}

/**
Enum representing different types of errors that can occur while interacting with the Gini API.

- badRequest: Error indicating that the request was invalid.
- notAcceptable: Error indicating that the request was not acceptable.
- notFound: Error indicating that the requested resource was not found.
- noResponse: Error indicating that no response was received.
- parseError: Error indicating that there was an error parsing the response.
- requestCancelled: Error indicating that the request was cancelled.
- tooManyRequests: Error indicating that too many requests have been made.
- unauthorized: Error indicating that the request was unauthorized.
- unknown: An unknown error occurred.
*/

public enum GiniError: Error, GiniErrorProtocol, Equatable {
case badRequest(response: HTTPURLResponse? = nil, data: Data? = nil)
case invalidCredentials
case keychainError
case notAcceptable(response: HTTPURLResponse? = nil, data: Data? = nil)
case notFound(response: HTTPURLResponse? = nil, data: Data? = nil)
case noResponse
Expand All @@ -51,6 +30,10 @@ public enum GiniError: Error, GiniErrorProtocol, Equatable {
switch self {
case .badRequest:
return "Bad request"
case .invalidCredentials:
return "Invalid credentials"
case .keychainError:
return "Keychain error"
case .notAcceptable:
return "Not acceptable"
case .notFound:
Expand Down
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 @@
// Created by Nadya Karaban on 28.10.21.
//

public let GiniBankAPILibraryVersion = "3.0.0"
public let GiniBankAPILibraryVersion = "1.6.0"
9 changes: 9 additions & 0 deletions Tests/GiniBankAPILibraryTests/APIResourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,13 @@ final class APIResourceTests: XCTestCase {
XCTAssertEqual(urlString, "https://custom.domain.com/documents/", "path should match")
}

func testCustomApiDomainWithPath() {
let resource = APIResource<[Document]>(method: .documents(limit: nil, offset: nil),
apiDomain: .custom(domain: "custom.domain.com", path:"/custom/path", tokenSource: nil),
httpMethod: .get)

let urlString = resource.url.absoluteString
XCTAssertEqual(urlString, "https://custom.domain.com/custom/path/documents/", "path should match")
}

}
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.0.0",
apiLibVersion: "1.6.0",
description: "Error logging test",
documentId: "1234",
originalRequestId: "5678")
Expand Down
8 changes: 8 additions & 0 deletions Tests/GiniBankAPILibraryTests/UserResourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ class UserResourceTests: XCTestCase {
XCTAssertEqual(urlString, "https://custom.domain.com/api/users")
}

func testCustomUserDomainWithPath() {
let resource = UserResource<Token>(method: .users,
userDomain: .custom(domain: "custom.domain.com", path:"/custom/path"),
httpMethod: .post)
let urlString = resource.url.absoluteString
XCTAssertEqual(urlString, "https://custom.domain.com/custom/path/api/users")
}

}

0 comments on commit 6b7a512

Please sign in to comment.