Skip to content

Commit feda1d4

Browse files
Merge pull request #18 from veryfi/LP-1230-add-missing-apis
LP-1230: Add categorization, splits and checks apis
2 parents 54574bc + ae6cdef commit feda1d4

File tree

91 files changed

+855
-52
lines changed

Some content is hidden

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

91 files changed

+855
-52
lines changed

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ let package = Package(
3131
.copy("Resources/driver_license.png"),
3232
.copy("Resources/bankstatement.pdf"),
3333
.copy("Resources/w2.png"),
34+
.copy("Resources/split.pdf"),
35+
.copy("Resources/check.pdf"),
3436
.copy("Resources/deleteDocument.json"),
3537
.copy("Resources/getDocument.json"),
3638
.copy("Resources/getDocuments.json"),
@@ -53,7 +55,15 @@ let package = Package(
5355
.copy("Resources/deleteLineItem.json"),
5456
.copy("Resources/getDocumentLineItems.json"),
5557
.copy("Resources/getLineItem.json"),
56-
.copy("Resources/updateLineItem.json")
58+
.copy("Resources/updateLineItem.json"),
59+
.copy("Resources/classify.json"),
60+
.copy("Resources/split.json"),
61+
.copy("Resources/getSplit.json"),
62+
.copy("Resources/getSplits.json"),
63+
.copy("Resources/processCheck.json"),
64+
.copy("Resources/getCheck.json"),
65+
.copy("Resources/getChecks.json"),
66+
.copy("Resources/deleteCheck.json")
5767
]
5868
)
5969
]

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ import VeryfiSDK
2727
class ViewController: UIViewController {
2828

2929
let clientId = "your_client_id"
30-
let clientSecret = "your_client_secret"
3130
let username = "your_username"
3231
let apiKey = "your_password"
3332

3433
override func viewDidLoad() {
3534
super.viewDidLoad()
36-
let client = Client(clientId: clientId, clientSecret: clientSecret, username: username, apiKey: apiKey)
35+
let client = Client(clientId: clientId, username: username, apiKey: apiKey)
3736
let file = "receipt"
3837
let url = Bundle(for: Self.self).url(forResource: file, withExtension: "jpeg")!
3938
let fileData = try? Data(contentsOf: url)
@@ -57,13 +56,12 @@ import VeryfiSDK
5756
class ViewController: UIViewController {
5857

5958
let clientId = "your_client_id"
60-
let clientSecret = "your_client_secret"
6159
let username = "your_username"
6260
let apiKey = "your_password"
6361

6462
override func viewDidLoad() {
6563
super.viewDidLoad()
66-
let client = Client(clientId: clientId, clientSecret: clientSecret, username: username, apiKey: apiKey)
64+
let client = Client(clientId: clientId, username: username, apiKey: apiKey)
6765
let documentId = "your_document_id"
6866
var parameters = [String : Any]()
6967
parameters["category"] = "Meals & Entertainment"

Sources/VeryfiSDK/Client/AddLineItem.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Foundation
88

99
extension Client {
1010
/// Create line item for document in Veryfi inbox.
11+
/// https://docs.veryfi.com/api/receipts-invoices/create-a-line-item/
1112
/// - Parameters:
1213
/// - documentId: ID of document to modify.
1314
/// - params: Line item data.

Sources/VeryfiSDK/Client/AddTag.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Foundation
88

99
extension Client {
1010
/// Add tag to document.
11+
/// https://docs.veryfi.com/api/receipts-invoices/add-a-tag-to-a-document/
1112
/// - Parameters:
1213
/// - documentId: ID of document to add tag.
1314
/// - params: Tag data.

Sources/VeryfiSDK/Client/AddTags.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Foundation
88

99
extension Client {
1010
/// Add multiple tags in document.
11+
/// https://docs.veryfi.com/api/receipts-invoices/add-tags-to-a-document/
1112
/// - Parameters:
1213
/// - documentId: ID of document to replace tags.
1314
/// - params: Tags data.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// ClassifyDocument.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Classify a document and extract all the fields from it.
11+
/// https://docs.veryfi.com/api/classify/classify-a-document/
12+
/// - Parameters:
13+
/// - fileName: Name of the file to upload to the Veryfi API.
14+
/// - fileData: UTF8 encoded file data
15+
/// - params: Additional parameters.
16+
/// - completion: Function called after request completes.
17+
/// - detail: Response from server.
18+
/// - error: Error from server.
19+
public func classifyDocument(fileName: String,
20+
fileData: Data,
21+
params: [String: Any]? = nil,
22+
withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
23+
var requestParams = params ?? [String: Any]()
24+
requestParams["file_data"] = fileData.base64EncodedString()
25+
requestParams["file_name"] = fileName
26+
27+
guard let jsonData = try? JSONSerialization.data(withJSONObject: requestParams, options: .prettyPrinted) else {
28+
completion(.failure(.parsingError))
29+
return
30+
}
31+
32+
self.request(method: .POST, route: .classify, uploadData: jsonData, completion: completion)
33+
}
34+
35+
/// Classify a document from URL and extract all the fields from it.
36+
/// - Parameters:
37+
/// - fileUrl: Publicly available URL.
38+
/// - fileUrls: List of publicly available URLs.
39+
/// - params: Additional parameters.
40+
/// - completion: Function called after request completes.
41+
/// - detail: Response from server.
42+
/// - error: Error from server.
43+
public func classifyDocumentURL(fileUrl: String? = nil,
44+
fileUrls: [String]? = nil,
45+
params: [String: Any]? = nil,
46+
withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
47+
var requestParams = params ?? [String: Any]()
48+
requestParams["file_url"] = fileUrl as Any
49+
requestParams["file_urls"] = fileUrls as Any
50+
51+
guard let jsonData = try? JSONSerialization.data(withJSONObject: requestParams, options: .prettyPrinted) else {
52+
completion(.failure(.parsingError))
53+
return
54+
}
55+
56+
self.request(method: .POST, route: .classify, body: jsonData, completion: completion)
57+
}
58+
}

Sources/VeryfiSDK/Client/Client.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import FoundationNetworking
55

66
struct VeryfiCredentials {
77
let clientId: String
8-
let clientSecret: String
98
let username: String
109
let apiKey: String
1110
}
@@ -15,12 +14,11 @@ public class Client: NetworkManager {
1514
/// Init Client.
1615
/// - Parameters:
1716
/// - clientId: Your client id from veryfi-hub.
18-
/// - clientSecret: Your client secret from veryfi-hub.
1917
/// - username: Your username from veryfi-hub.
2018
/// - apiKey: Your api key from veryfi-hub.
2119
/// - 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)
20+
public init(clientId: String, username: String, apiKey: String, apiVersion: String = "v8") {
21+
let credentials = VeryfiCredentials(clientId: clientId, username: username, apiKey: apiKey)
2422
super.init(credentials: credentials, apiVersion: apiVersion)
2523
}
2624
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// DeleteCheck.swift
3+
// VeryfiSDK
4+
//
5+
// Created by Veryfi on 25/10/24.
6+
//
7+
import Foundation
8+
9+
extension Client {
10+
/// Delete a check by ID.
11+
/// https://docs.veryfi.com/api/checks/delete-a-check/
12+
/// - Parameters:
13+
/// - checkId: The ID of the check to delete.
14+
/// - completion: Block executed after request.
15+
/// - detail: Response from server.
16+
/// - error: Error from server.
17+
public func deleteCheck(checkId: Int, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) {
18+
self.request(method: .DELETE, route: .checks, queryItem: String(checkId), completion: completion)
19+
}
20+
}

Sources/VeryfiSDK/Client/DeleteDocument.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Foundation
88

99
extension Client {
1010
/// Delete document from Veryfi inbox.
11+
/// https://docs.veryfi.com/api/receipts-invoices/delete-a-document/
1112
/// - Parameters:
1213
/// - documentId: ID of document to delete.
1314
/// - completion: completion description

Sources/VeryfiSDK/Client/DeleteLineItem.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Foundation
88

99
extension Client {
1010
/// Delete line item from document from Veryfi inbox.
11+
/// https://docs.veryfi.com/api/receipts-invoices/delete-a-line-item/
1112
/// - Parameters:
1213
/// - documentId: ID of document
1314
/// - lineItemId: ID of line item to delete.

0 commit comments

Comments
 (0)