1+ //
2+ // ProcessContractUrl.swift
3+ // VeryfiSDK
4+ //
5+ // Created by Veryfi on 25/10/24.
6+ //
7+ import Foundation
8+
9+ extension Client {
10+ /// Upload a contract from URL for the Veryfi API to process.
11+ /// https://docs.veryfi.com/api/contracts/process-a-contract/
12+ /// - Parameters:
13+ /// - fileUrl: URL of the file to upload to the Veryfi API.
14+ /// - fileUrls: Array of URLs to publicly accessible documents.
15+ /// - deleteAfterProcessing: Do not store file in Veryfi's inbox.
16+ /// - maxPagesToProcess: Limit processing to number of pages (1-50, default 50).
17+ /// - externalId: External ID to associate with the document.
18+ /// - params: Additional parameters.
19+ /// - completion: Function called after request completes.
20+ /// - detail: Response from server.
21+ /// - error: Error from server.
22+ public func processContractURL( fileUrl: String ? = nil ,
23+ fileUrls: [ String ] ? = nil ,
24+ deleteAfterProcessing: Bool = false ,
25+ maxPagesToProcess: Int = 50 ,
26+ externalId: String ? = nil ,
27+ params: [ String : Any ] ? = nil ,
28+ withCompletion completion: @escaping ( Result < Data , APIError > ) -> Void ) {
29+ var requestParams = params ?? [ String: Any] ( )
30+ requestParams [ " auto_delete " ] = deleteAfterProcessing
31+ requestParams [ " max_pages_to_process " ] = maxPagesToProcess
32+
33+ if let fileUrl = fileUrl {
34+ requestParams [ " file_url " ] = fileUrl
35+ }
36+
37+ if let fileUrls = fileUrls {
38+ requestParams [ " file_urls " ] = fileUrls
39+ }
40+
41+ if let externalId = externalId {
42+ requestParams [ " external_id " ] = externalId
43+ }
44+
45+ guard let jsonData = try ? JSONSerialization . data ( withJSONObject: requestParams, options: . prettyPrinted) else {
46+ completion ( . failure( . parsingError) )
47+ return
48+ }
49+
50+ self . request ( method: . POST, route: . contracts, uploadData: jsonData, completion: completion)
51+ }
52+ }
0 commit comments