-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LP-958: Refactor functions and tests to multiple files
- Loading branch information
Douglas Poveda
committed
Oct 25, 2024
1 parent
0e90e27
commit 444ea8a
Showing
59 changed files
with
1,622 additions
and
1,216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AddLineItem.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Create line item for document in Veryfi inbox. | ||
/// - Parameters: | ||
/// - documentId: ID of document to modify. | ||
/// - params: Line item data. | ||
/// - completion: A block to execute | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func addLineItem(documentId: String, params: AddLineItem, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
let jsonData = try? JSONSerialization.data(withJSONObject: params.dictionary) | ||
self.request(method: .POST, route: .documents, body: jsonData, queryItem: String(format: "%@/line-items", documentId), completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AddTag.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Add tag to document. | ||
/// - Parameters: | ||
/// - documentId: ID of document to add tag. | ||
/// - params: Tag data. | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func addTag(documentId: String, params: AddTag, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
let jsonData = try? JSONSerialization.data(withJSONObject: params.dictionary) | ||
self.request(method: .PUT, route: .documents, body: jsonData, queryItem: String(format: "%@/tags", documentId), completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AddTags.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Add multiple tags in document. | ||
/// - Parameters: | ||
/// - documentId: ID of document to replace tags. | ||
/// - params: Tags data. | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func addTags(documentId: String, params: AddTags, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
let jsonData = try? JSONSerialization.data(withJSONObject: params.dictionary) | ||
self.request(method: .POST, route: .documents, body: jsonData, queryItem: String(format: "%@/tags", documentId), completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
struct VeryfiCredentials { | ||
let clientId: String | ||
let clientSecret: String | ||
let username: String | ||
let apiKey: String | ||
} | ||
|
||
public class Client: NetworkManager { | ||
|
||
/// Init Client. | ||
/// - Parameters: | ||
/// - clientId: Your client id from veryfi-hub. | ||
/// - clientSecret: Your client secret from veryfi-hub. | ||
/// - username: Your username from veryfi-hub. | ||
/// - apiKey: Your api key from veryfi-hub. | ||
/// - apiVersion: Api version to use, by default "v8". | ||
public init(clientId: String, clientSecret: String, username: String, apiKey: String, apiVersion: String = "v8") { | ||
let credentials = VeryfiCredentials(clientId: clientId, clientSecret: clientSecret, username: username, apiKey: apiKey) | ||
super.init(credentials: credentials, apiVersion: apiVersion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// DeleteDocument.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Delete document from Veryfi inbox. | ||
/// - Parameters: | ||
/// - documentId: ID of document to delete. | ||
/// - completion: completion description | ||
public func deleteDocument(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .DELETE, route: .documents, queryItem: documentId, completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// DeleteLineItem.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Delete line item from document from Veryfi inbox. | ||
/// - Parameters: | ||
/// - documentId: ID of document | ||
/// - lineItemId: ID of line item to delete. | ||
/// - completion: completion description | ||
public func deleteLineItem(documentId: String, lineItemId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .DELETE, route: .documents, queryItem: String(format: "%@/line-items/%@", documentId, lineItemId), completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// DeleteLineItems.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Delete all line items from document from Veryfi inbox. | ||
/// - Parameters: | ||
/// - documentId: ID of document | ||
/// - completion: completion description | ||
public func deleteDocumentLineItems(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .DELETE, route: .documents, queryItem: String(format: "%@/line-items", documentId), completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// GetAnyDocument.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Get single any document by ID from Veryfi inbox. | ||
/// - Parameters: | ||
/// - documentId: ID of document to retreive | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func getAnyDocument(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .GET, route: .anyDocuments, queryItem: documentId, completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// GetAnyDocuments.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Get all any documents from Veryfi inbox. | ||
/// - Parameters: | ||
/// - queryItems: Query items to apply to the get request. | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func getAnyDocuments(queryItems: [URLQueryItem]? = nil, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .GET, route: .anyDocuments, queryItems: queryItems, completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// GetBankStatement.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Get single bank statements by ID from Veryfi inbox. | ||
/// - Parameters: | ||
/// - documentId: ID of document to retreive | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func getBankStatement(id: String, queryItems: [URLQueryItem]? = nil, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .GET, route: .bankStatements, queryItems: queryItems, queryItem: id, completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// GetBankStatements.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Get all bank statements from Veryfi inbox. | ||
/// - Parameters: | ||
/// - queryItems: Query items to apply to the get request. | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func getBankStatements(queryItems: [URLQueryItem]? = nil, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .GET, route: .bankStatements, queryItems: queryItems, completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// GetDocument.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Get single document by ID from Veryfi inbox. | ||
/// - Parameters: | ||
/// - documentId: ID of document to retreive | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func getDocument(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .GET, route: .documents, queryItem: documentId, completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// GetDocuments.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Get all documents from Veryfi inbox. | ||
/// - Parameters: | ||
/// - queryItems: Query items to apply to the get request. | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func getDocuments(queryItems: [URLQueryItem]? = nil, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .GET, route: .documents, queryItems: queryItems, completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// GetLineItem.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Get single line item by document from Veryfi inbox. | ||
/// - Parameters: | ||
/// - documentId: ID of document. | ||
/// - lineItemId: ID of line item. | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func getLineItem(documentId: String, lineItemId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .GET, route: .documents, queryItem: String(format: "%@/line-items/%@", documentId, lineItemId), completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// GetLineItems.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Get all line items from document. | ||
/// - Parameters: | ||
/// - documentId: ID of document to get line items. | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func getDocumentLineItems(documentId: String, withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
self.request(method: .GET, route: .documents, queryItem: String(format: "%@/line-items", documentId), completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// ProcessAnyDocument.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Upload any document for the Veryfi API to process. | ||
/// - Parameters: | ||
/// - fileName: Name of the file to upload to the Veryfi API. | ||
/// - fileData: UTF8 encoded file data | ||
/// - categories: List of document categories. | ||
/// - deleteAfterProcessing: Do not store file in Veryfi's inbox. | ||
/// - params: Additional parameters. | ||
/// - completion: Function called after request completes. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func processAnyDocument(fileName: String, | ||
fileData: Data, | ||
params: [String: Any]? = nil, | ||
templateName: String, | ||
withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
var requestParams = params ?? [String: Any]() | ||
requestParams["file_data"] = fileData.base64EncodedString() | ||
requestParams["file_name"] = fileName | ||
requestParams["template_name"] = templateName | ||
|
||
guard let jsonData = try? JSONSerialization.data(withJSONObject: requestParams, options: .prettyPrinted) else { | ||
completion(.failure(.parsingError)) | ||
return | ||
} | ||
|
||
self.request(method: .POST, route: .anyDocuments, uploadData: jsonData, completion: completion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// ProcessAnyDocumentUrl.swift | ||
// VeryfiSDK | ||
// | ||
// Created by Veryfi on 25/10/24. | ||
// | ||
import Foundation | ||
|
||
extension Client { | ||
/// Upload any document to Veryfi API with URL. | ||
/// - Parameters: | ||
/// - fileUrl: Publicly available URL. | ||
/// - fileUrls: List of publicly available URLs. | ||
/// - categories: List of document categories. | ||
/// - deleteAfterProcessing: Do not store file in Veryfi's inbox. | ||
/// - boostMode: Skip data enrichment but process document faster. | ||
/// - externalId: Existing ID to assign to document. | ||
/// - maxPagesToProcess: Number of pages to process. | ||
/// - completion: Block executed after request. | ||
/// - detail: Response from server. | ||
/// - error: Error from server. | ||
public func processAnyDocumentURL(fileUrl: String? = nil, | ||
fileUrls: [String]? = nil, | ||
categories: [String]? = nil, | ||
deleteAfterProcessing: Bool = false, | ||
boostMode: Int = 0, | ||
externalId: String? = nil, | ||
maxPagesToProcess: Int? = 1, | ||
templateName: String, | ||
withCompletion completion: @escaping (Result<Data, APIError>) -> Void) { | ||
let params: [String: Any] = ["file_url": fileUrl as Any, //implicit coerce | ||
"file_urls": fileUrls as Any, //implicit coerce | ||
"template_name": templateName, | ||
"max_pages_to_process": maxPagesToProcess as Any] //implicit coerce | ||
let jsonData = try? JSONSerialization.data(withJSONObject: params) | ||
self.request(method: .POST, route: .anyDocuments, body: jsonData, completion: completion) | ||
} | ||
} |
Oops, something went wrong.