Skip to content

Commit 54574bc

Browse files
Merge pull request #17 from veryfi/feature/LP-958-add-new-apis
LP-958: Add apis for any document, bank statements and tags
2 parents 18bada5 + 5c7e0f7 commit 54574bc

File tree

90 files changed

+3941
-722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3941
-722
lines changed

Package.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,25 @@ let package = Package(
2828
dependencies: ["VeryfiSDK"],
2929
resources: [
3030
.copy("Resources/receipt.jpeg"),
31+
.copy("Resources/driver_license.png"),
32+
.copy("Resources/bankstatement.pdf"),
33+
.copy("Resources/w2.png"),
3134
.copy("Resources/deleteDocument.json"),
3235
.copy("Resources/getDocument.json"),
3336
.copy("Resources/getDocuments.json"),
3437
.copy("Resources/processDocument.json"),
38+
.copy("Resources/getAnyDocument.json"),
39+
.copy("Resources/getAnyDocuments.json"),
40+
.copy("Resources/processAnyDocument.json"),
41+
.copy("Resources/getBankStatement.json"),
42+
.copy("Resources/getBankStatements.json"),
43+
.copy("Resources/processBankStatement.json"),
44+
.copy("Resources/getW2.json"),
45+
.copy("Resources/getW2s.json"),
46+
.copy("Resources/processW2.json"),
47+
.copy("Resources/addTag.json"),
48+
.copy("Resources/addTags.json"),
49+
.copy("Resources/replaceTags.json"),
3550
.copy("Resources/updateDocument.json"),
3651
.copy("Resources/addLineItem.json"),
3752
.copy("Resources/deleteDocumentLineItems.json"),

Sources/VeryfiSDK/Client.swift

Lines changed: 0 additions & 191 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// AddLineItem.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Create line item for document in Veryfi inbox.
11+
/// - Parameters:
12+
/// - documentId: ID of document to modify.
13+
/// - params: Line item data.
14+
/// - completion: A block to execute
15+
/// - detail: Response from server.
16+
/// - error: Error from server.
17+
public func addLineItem(documentId: String, params: AddLineItem, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
18+
let jsonData = try? JSONSerialization.data(withJSONObject: params.dictionary)
19+
self.request(method: .POST, route: .documents, body: jsonData, queryItem: String(format: "%@/line-items", documentId), completion: completion)
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// AddTag.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Add tag to document.
11+
/// - Parameters:
12+
/// - documentId: ID of document to add tag.
13+
/// - params: Tag data.
14+
/// - completion: Block executed after request.
15+
/// - detail: Response from server.
16+
/// - error: Error from server.
17+
public func addTag(documentId: String, params: AddTag, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
18+
let jsonData = try? JSONSerialization.data(withJSONObject: params.dictionary)
19+
self.request(method: .PUT, route: .documents, body: jsonData, queryItem: String(format: "%@/tags", documentId), completion: completion)
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// AddTags.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Add multiple tags in document.
11+
/// - Parameters:
12+
/// - documentId: ID of document to replace tags.
13+
/// - params: Tags data.
14+
/// - completion: Block executed after request.
15+
/// - detail: Response from server.
16+
/// - error: Error from server.
17+
public func addTags(documentId: String, params: AddTags, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
18+
let jsonData = try? JSONSerialization.data(withJSONObject: params.dictionary)
19+
self.request(method: .POST, route: .documents, body: jsonData, queryItem: String(format: "%@/tags", documentId), completion: completion)
20+
}
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Foundation
2+
#if canImport(FoundationNetworking)
3+
import FoundationNetworking
4+
#endif
5+
6+
struct VeryfiCredentials {
7+
let clientId: String
8+
let clientSecret: String
9+
let username: String
10+
let apiKey: String
11+
}
12+
13+
public class Client: NetworkManager {
14+
15+
/// Init Client.
16+
/// - Parameters:
17+
/// - clientId: Your client id from veryfi-hub.
18+
/// - clientSecret: Your client secret from veryfi-hub.
19+
/// - username: Your username from veryfi-hub.
20+
/// - apiKey: Your api key from veryfi-hub.
21+
/// - apiVersion: Api version to use, by default "v8".
22+
public init(clientId: String, clientSecret: String, username: String, apiKey: String, apiVersion: String = "v8") {
23+
let credentials = VeryfiCredentials(clientId: clientId, clientSecret: clientSecret, username: username, apiKey: apiKey)
24+
super.init(credentials: credentials, apiVersion: apiVersion)
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// DeleteDocument.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Delete document from Veryfi inbox.
11+
/// - Parameters:
12+
/// - documentId: ID of document to delete.
13+
/// - completion: completion description
14+
public func deleteDocument(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
15+
self.request(method: .DELETE, route: .documents, queryItem: documentId, completion: completion)
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// DeleteLineItem.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Delete line item from document from Veryfi inbox.
11+
/// - Parameters:
12+
/// - documentId: ID of document
13+
/// - lineItemId: ID of line item to delete.
14+
/// - completion: completion description
15+
public func deleteLineItem(documentId: String, lineItemId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
16+
self.request(method: .DELETE, route: .documents, queryItem: String(format: "%@/line-items/%@", documentId, lineItemId), completion: completion)
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// DeleteLineItems.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Delete all line items from document from Veryfi inbox.
11+
/// - Parameters:
12+
/// - documentId: ID of document
13+
/// - completion: completion description
14+
public func deleteDocumentLineItems(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
15+
self.request(method: .DELETE, route: .documents, queryItem: String(format: "%@/line-items", documentId), completion: completion)
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// GetAnyDocument.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Get single any document by ID from Veryfi inbox.
11+
/// - Parameters:
12+
/// - documentId: ID of document to retreive
13+
/// - completion: Block executed after request.
14+
/// - detail: Response from server.
15+
/// - error: Error from server.
16+
public func getAnyDocument(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
17+
self.request(method: .GET, route: .anyDocuments, queryItem: documentId, completion: completion)
18+
}
19+
}

0 commit comments

Comments
 (0)