Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LP-958: Add apis for any document, bank statements and tags #17

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,25 @@ let package = Package(
dependencies: ["VeryfiSDK"],
resources: [
.copy("Resources/receipt.jpeg"),
.copy("Resources/driver_license.png"),
.copy("Resources/bankstatement.pdf"),
.copy("Resources/w2.png"),
.copy("Resources/deleteDocument.json"),
.copy("Resources/getDocument.json"),
.copy("Resources/getDocuments.json"),
.copy("Resources/processDocument.json"),
.copy("Resources/getAnyDocument.json"),
.copy("Resources/getAnyDocuments.json"),
.copy("Resources/processAnyDocument.json"),
.copy("Resources/getBankStatement.json"),
.copy("Resources/getBankStatements.json"),
.copy("Resources/processBankStatement.json"),
.copy("Resources/getW2.json"),
.copy("Resources/getW2s.json"),
.copy("Resources/processW2.json"),
.copy("Resources/addTag.json"),
.copy("Resources/addTags.json"),
.copy("Resources/replaceTags.json"),
.copy("Resources/updateDocument.json"),
.copy("Resources/addLineItem.json"),
.copy("Resources/deleteDocumentLineItems.json"),
Expand Down
191 changes: 0 additions & 191 deletions Sources/VeryfiSDK/Client.swift

This file was deleted.

21 changes: 21 additions & 0 deletions Sources/VeryfiSDK/Client/AddLineItem.swift
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)
}
}
21 changes: 21 additions & 0 deletions Sources/VeryfiSDK/Client/AddTag.swift
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)
}
}
21 changes: 21 additions & 0 deletions Sources/VeryfiSDK/Client/AddTags.swift
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)
}
}
26 changes: 26 additions & 0 deletions Sources/VeryfiSDK/Client/Client.swift
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)
}
}
17 changes: 17 additions & 0 deletions Sources/VeryfiSDK/Client/DeleteDocument.swift
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)
}
}
18 changes: 18 additions & 0 deletions Sources/VeryfiSDK/Client/DeleteLineItem.swift
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)
}
}
17 changes: 17 additions & 0 deletions Sources/VeryfiSDK/Client/DeleteLineItems.swift
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)
}
}
19 changes: 19 additions & 0 deletions Sources/VeryfiSDK/Client/GetAnyDocument.swift
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)
}
}
Loading
Loading