veryfi 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ # Any Document (a-doc) endpoints (`/partner/any-documents/`).
6
+ #
7
+ # An A-Doc is a custom document type, defined by a *blueprint* you
8
+ # configure in Veryfi. Every "process" call must therefore include a
9
+ # `:blueprint_name`.
10
+ #
11
+ # @see https://docs.veryfi.com/api/anydocs/
12
+ class AnyDocument
13
+ include FilePayload
14
+ include TagOperations
15
+
16
+ ENDPOINT = "/partner/any-documents/"
17
+ ASYNC_ENDPOINT = "/partner/any-documents/async"
18
+
19
+ attr_reader :request
20
+
21
+ def initialize(request)
22
+ @request = request
23
+ end
24
+
25
+ # List previously processed A-Docs.
26
+ #
27
+ # @param params [Hash] optional query-string parameters
28
+ # @option params [String] :created_date__gt "YYYY-MM-DD HH:MM:SS" — strictly after
29
+ # @option params [String] :created_date__gte after or equal
30
+ # @option params [String] :created_date__lt strictly before
31
+ # @option params [String] :created_date__lte before or equal
32
+ # @option params [Integer] :page (1)
33
+ # @option params [Integer] :page_size (50)
34
+ # @return [Veryfi::Resource] `{ "documents" => [...] }`
35
+ def all(params = {})
36
+ request.get(ENDPOINT, params)
37
+ end
38
+
39
+ # Fetch a single A-Doc by id.
40
+ #
41
+ # @param id [Integer]
42
+ # @param params [Hash] optional query-string parameters
43
+ # @return [Veryfi::Resource]
44
+ def get(id, params = {})
45
+ request.get("#{ENDPOINT}#{id}/", params)
46
+ end
47
+
48
+ # Upload a file and extract its fields using the given blueprint.
49
+ #
50
+ # @param raw_params [Hash]
51
+ # @option raw_params [String] :blueprint_name **required.** Blueprint id to apply.
52
+ # @option raw_params [String] :file_path **required.** Local path to the file.
53
+ # @option raw_params [String] :file_name (basename of `:file_path`)
54
+ # @return [Veryfi::Resource]
55
+ def process(raw_params)
56
+ params = raw_params.transform_keys(&:to_sym)
57
+ blueprint_name = params.delete(:blueprint_name)
58
+ file_path = params.delete(:file_path)
59
+ file_name = params.delete(:file_name)
60
+
61
+ payload = file_payload(file_path, file_name).merge(blueprint_name: blueprint_name).merge(params)
62
+
63
+ request.post(ENDPOINT, payload)
64
+ end
65
+
66
+ # Process an A-Doc from a public URL.
67
+ #
68
+ # @param raw_params [Hash]
69
+ # @option raw_params [String] :blueprint_name **required.**
70
+ # @option raw_params [String] :file_url **required** (single URL).
71
+ # @option raw_params [String] :file_name (basename of `:file_url`)
72
+ # @return [Veryfi::Resource]
73
+ def process_url(raw_params)
74
+ params = raw_params.transform_keys(&:to_sym)
75
+ params[:file_name] ||= File.basename(params[:file_url]) if params[:file_url]
76
+
77
+ request.post(ENDPOINT, params)
78
+ end
79
+
80
+ # Same as {#process} but asynchronous — returns immediately with a
81
+ # `"status": "processing"` payload while Veryfi runs the extraction
82
+ # in the background. Use a webhook (or poll {#get}) to learn when the
83
+ # final result is ready.
84
+ #
85
+ # @see https://docs.veryfi.com/api/anydocs/process-a-doc-async/
86
+ def process_async(raw_params)
87
+ params = raw_params.transform_keys(&:to_sym)
88
+ blueprint_name = params.delete(:blueprint_name)
89
+ file_path = params.delete(:file_path)
90
+ file_name = params.delete(:file_name)
91
+
92
+ payload = file_payload(file_path, file_name).merge(blueprint_name: blueprint_name).merge(params)
93
+
94
+ request.post(ASYNC_ENDPOINT, payload)
95
+ end
96
+
97
+ # URL variant of {#process_async}.
98
+ def process_url_async(raw_params)
99
+ params = raw_params.transform_keys(&:to_sym)
100
+ params[:file_name] ||= File.basename(params[:file_url]) if params[:file_url]
101
+
102
+ request.post(ASYNC_ENDPOINT, params)
103
+ end
104
+
105
+ # Update writable fields on a processed A-Doc.
106
+ #
107
+ # @param id [Integer]
108
+ # @param params [Hash] writable fields
109
+ # @return [Veryfi::Resource]
110
+ def update(id, params)
111
+ request.put("#{ENDPOINT}#{id}/", params)
112
+ end
113
+
114
+ # Delete an A-Doc.
115
+ #
116
+ # @param id [Integer]
117
+ # @return [Veryfi::Resource]
118
+ def delete(id)
119
+ request.delete("#{ENDPOINT}#{id}/")
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ # Bank Statements endpoints (`/partner/bank-statements/`).
6
+ #
7
+ # @see https://docs.veryfi.com/api/bank-statements/
8
+ class BankStatement
9
+ include FilePayload
10
+ include TagOperations
11
+
12
+ ENDPOINT = "/partner/bank-statements/"
13
+ ASYNC_ENDPOINT = "/partner/bank-statements/async"
14
+
15
+ attr_reader :request
16
+
17
+ def initialize(request)
18
+ @request = request
19
+ end
20
+
21
+ # List previously processed bank statements.
22
+ #
23
+ # @param params [Hash] optional query-string parameters
24
+ # @option params [String] :created_date__gt "YYYY-MM-DD HH:MM:SS" — strictly after
25
+ # @option params [String] :created_date__gte after or equal
26
+ # @option params [String] :created_date__lt strictly before
27
+ # @option params [String] :created_date__lte before or equal
28
+ # @option params [Integer] :page (1)
29
+ # @option params [Integer] :page_size (50)
30
+ # @return [Veryfi::Resource] `{ "documents" => [...] }`
31
+ def all(params = {})
32
+ request.get(ENDPOINT, params)
33
+ end
34
+
35
+ # Fetch a single bank statement by id.
36
+ #
37
+ # @param id [Integer]
38
+ # @param params [Hash] optional query-string parameters
39
+ # @return [Veryfi::Resource]
40
+ def get(id, params = {})
41
+ request.get("#{ENDPOINT}#{id}/", params)
42
+ end
43
+
44
+ # Upload a file and extract bank-statement data.
45
+ #
46
+ # @param raw_params [Hash]
47
+ # @option raw_params [String] :file_path **required.** Local path.
48
+ # @option raw_params [String] :file_name (basename of `:file_path`)
49
+ # @option raw_params [Array<String>] :categories (`nil`) Optional categories used to classify
50
+ # transactions, e.g. `["Transfer", "Credit Card Payments"]`.
51
+ # @return [Veryfi::Resource]
52
+ def process(raw_params)
53
+ params = raw_params.transform_keys(&:to_sym)
54
+ file_path = params.delete(:file_path)
55
+ file_name = params.delete(:file_name)
56
+
57
+ payload = file_payload(file_path, file_name).merge(params)
58
+
59
+ request.post(ENDPOINT, payload)
60
+ end
61
+
62
+ # URL variant of {#process}.
63
+ #
64
+ # @param raw_params [Hash]
65
+ # @option raw_params [String] :file_url **required.** Publicly accessible URL.
66
+ # @option raw_params [String] :file_name (basename of `:file_url`)
67
+ # @option raw_params [Array<String>] :categories (`nil`)
68
+ # @return [Veryfi::Resource]
69
+ def process_url(raw_params)
70
+ params = raw_params.transform_keys(&:to_sym)
71
+ params[:file_name] ||= File.basename(params[:file_url]) if params[:file_url]
72
+
73
+ request.post(ENDPOINT, params)
74
+ end
75
+
76
+ # Async variant of {#process} — returns immediately while Veryfi
77
+ # extracts the data in the background.
78
+ def process_async(raw_params)
79
+ params = raw_params.transform_keys(&:to_sym)
80
+ file_path = params.delete(:file_path)
81
+ file_name = params.delete(:file_name)
82
+
83
+ payload = file_payload(file_path, file_name).merge(params)
84
+
85
+ request.post(ASYNC_ENDPOINT, payload)
86
+ end
87
+
88
+ # Async variant of {#process_url}.
89
+ def process_url_async(raw_params)
90
+ params = raw_params.transform_keys(&:to_sym)
91
+ params[:file_name] ||= File.basename(params[:file_url]) if params[:file_url]
92
+
93
+ request.post(ASYNC_ENDPOINT, params)
94
+ end
95
+
96
+ # Update writable fields on a processed bank statement.
97
+ #
98
+ # @param id [Integer]
99
+ # @param params [Hash]
100
+ # @return [Veryfi::Resource]
101
+ def update(id, params)
102
+ request.put("#{ENDPOINT}#{id}/", params)
103
+ end
104
+
105
+ # Delete a bank statement.
106
+ #
107
+ # @param id [Integer]
108
+ # @return [Veryfi::Resource]
109
+ def delete(id)
110
+ request.delete("#{ENDPOINT}#{id}/")
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ # Bank-statement splitting endpoints (`/partner/bank-statements-set/`).
6
+ #
7
+ # Use these when you have a single file containing multiple bank
8
+ # statements (e.g. an annual archive PDF). Veryfi will split the file
9
+ # and process each statement separately; you receive a collection that
10
+ # references the individual {BankStatement} ids it produced.
11
+ class BankStatementSplit
12
+ include FilePayload
13
+
14
+ ENDPOINT = "/partner/bank-statements-set/"
15
+
16
+ attr_reader :request
17
+
18
+ def initialize(request)
19
+ @request = request
20
+ end
21
+
22
+ # List previously processed bank-statement sets.
23
+ #
24
+ # @param params [Hash] optional query-string parameters
25
+ # @return [Veryfi::Resource]
26
+ def all(params = {})
27
+ request.get(ENDPOINT, params)
28
+ end
29
+
30
+ # Fetch a single bank-statement set by id.
31
+ #
32
+ # @param id [Integer]
33
+ # @param params [Hash] optional query-string parameters
34
+ # @return [Veryfi::Resource]
35
+ def get(id, params = {})
36
+ request.get("#{ENDPOINT}#{id}", params)
37
+ end
38
+
39
+ # Upload a multi-statement file and split-and-process it.
40
+ #
41
+ # @param raw_params [Hash]
42
+ # @option raw_params [String] :file_path **required.** Local path.
43
+ # @option raw_params [String] :file_name (basename of `:file_path`)
44
+ # @return [Veryfi::Resource]
45
+ def process(raw_params)
46
+ params = raw_params.transform_keys(&:to_sym)
47
+ file_path = params.delete(:file_path)
48
+ file_name = params.delete(:file_name)
49
+
50
+ payload = file_payload(file_path, file_name).merge(params)
51
+
52
+ request.post(ENDPOINT, payload)
53
+ end
54
+
55
+ # URL variant of {#process}.
56
+ #
57
+ # @param raw_params [Hash]
58
+ # @option raw_params [String] :file_url single URL
59
+ # @option raw_params [Array<String>] :file_urls list of URLs (alternative to `:file_url`)
60
+ # @return [Veryfi::Resource]
61
+ def process_url(raw_params)
62
+ request.post(ENDPOINT, raw_params.transform_keys(&:to_sym))
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ # Business Cards endpoints (`/partner/business-cards/`).
6
+ #
7
+ # @see https://docs.veryfi.com/api/business-cards/
8
+ class BusinessCard
9
+ include FilePayload
10
+ include TagOperations
11
+
12
+ ENDPOINT = "/partner/business-cards/"
13
+
14
+ attr_reader :request
15
+
16
+ def initialize(request)
17
+ @request = request
18
+ end
19
+
20
+ # List previously processed business cards.
21
+ #
22
+ # @param params [Hash] optional query-string parameters
23
+ # @return [Veryfi::Resource] `{ "documents" => [...] }`
24
+ def all(params = {})
25
+ request.get(ENDPOINT, params)
26
+ end
27
+
28
+ # Fetch a single business card by id.
29
+ #
30
+ # @param id [Integer]
31
+ # @param params [Hash] optional query-string parameters
32
+ # @return [Veryfi::Resource]
33
+ def get(id, params = {})
34
+ request.get("#{ENDPOINT}#{id}/", params)
35
+ end
36
+
37
+ # Upload an image of a business card and extract its contact fields.
38
+ #
39
+ # @param raw_params [Hash]
40
+ # @option raw_params [String] :file_path **required.** Local path.
41
+ # @option raw_params [String] :file_name (basename of `:file_path`)
42
+ # @return [Veryfi::Resource]
43
+ def process(raw_params)
44
+ params = raw_params.transform_keys(&:to_sym)
45
+ file_path = params.delete(:file_path)
46
+ file_name = params.delete(:file_name)
47
+
48
+ payload = file_payload(file_path, file_name).merge(params)
49
+
50
+ request.post(ENDPOINT, payload)
51
+ end
52
+
53
+ # URL variant of {#process}.
54
+ #
55
+ # @param raw_params [Hash]
56
+ # @option raw_params [String] :file_url **required.**
57
+ # @option raw_params [String] :file_name (basename of `:file_url`)
58
+ # @return [Veryfi::Resource]
59
+ def process_url(raw_params)
60
+ params = raw_params.transform_keys(&:to_sym)
61
+ params[:file_name] ||= File.basename(params[:file_url]) if params[:file_url]
62
+
63
+ request.post(ENDPOINT, params)
64
+ end
65
+
66
+ # Update writable fields on a processed business card.
67
+ #
68
+ # @param id [Integer]
69
+ # @param params [Hash] writable fields
70
+ # @return [Veryfi::Resource]
71
+ def update(id, params)
72
+ request.put("#{ENDPOINT}#{id}/", params)
73
+ end
74
+
75
+ # Delete a business card.
76
+ #
77
+ # @param id [Integer]
78
+ # @return [Veryfi::Resource]
79
+ def delete(id)
80
+ request.delete("#{ENDPOINT}#{id}/")
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ # Checks endpoints (`/partner/checks/` and
6
+ # `/partner/check-with-document/` for combined check + remittance
7
+ # extraction).
8
+ #
9
+ # @see https://docs.veryfi.com/api/checks/
10
+ class Check
11
+ include FilePayload
12
+ include TagOperations
13
+
14
+ ENDPOINT = "/partner/checks/"
15
+ REMITTANCE_ENDPOINT = "/partner/check-with-document/"
16
+ ASYNC_ENDPOINT = "/partner/checks/async"
17
+
18
+ attr_reader :request
19
+
20
+ def initialize(request)
21
+ @request = request
22
+ end
23
+
24
+ # List previously processed checks.
25
+ #
26
+ # @param params [Hash] optional query-string parameters
27
+ # @option params [String] :created_date__gt "YYYY-MM-DD HH:MM:SS" — strictly after
28
+ # @option params [String] :created_date__gte after or equal
29
+ # @option params [String] :created_date__lt strictly before
30
+ # @option params [String] :created_date__lte before or equal
31
+ # @option params [Integer] :page (1)
32
+ # @option params [Integer] :page_size (50)
33
+ # @return [Veryfi::Resource] `{ "documents" => [...] }`
34
+ def all(params = {})
35
+ request.get(ENDPOINT, params)
36
+ end
37
+
38
+ # Fetch a single check by id.
39
+ #
40
+ # @param id [Integer]
41
+ # @param params [Hash] optional query-string parameters
42
+ # @return [Veryfi::Resource]
43
+ def get(id, params = {})
44
+ request.get("#{ENDPOINT}#{id}/", params)
45
+ end
46
+
47
+ # Upload a check image and extract its fields.
48
+ #
49
+ # @param raw_params [Hash]
50
+ # @option raw_params [String] :file_path **required.** Local path.
51
+ # @option raw_params [String] :file_name (basename of `:file_path`)
52
+ # @return [Veryfi::Resource]
53
+ def process(raw_params)
54
+ request.post(ENDPOINT, build_file_payload(raw_params))
55
+ end
56
+
57
+ # URL variant of {#process}.
58
+ #
59
+ # @param raw_params [Hash]
60
+ # @option raw_params [String] :file_url single URL
61
+ # @option raw_params [Array<String>] :file_urls list of URLs (alternative to `:file_url`)
62
+ # @return [Veryfi::Resource]
63
+ def process_url(raw_params)
64
+ request.post(ENDPOINT, raw_params.transform_keys(&:to_sym))
65
+ end
66
+
67
+ # Process a check together with its remittance/stub document.
68
+ # Veryfi will OCR both halves and return a single combined response.
69
+ #
70
+ # @see https://docs.veryfi.com/api/checks/process-a-check-with-remittance/
71
+ #
72
+ # @param raw_params [Hash]
73
+ # @option raw_params [String] :file_path **required.**
74
+ # @option raw_params [String] :file_name (basename of `:file_path`)
75
+ # @return [Veryfi::Resource]
76
+ def process_with_remittance(raw_params)
77
+ request.post(REMITTANCE_ENDPOINT, build_file_payload(raw_params))
78
+ end
79
+
80
+ # URL variant of {#process_with_remittance}.
81
+ def process_with_remittance_url(raw_params)
82
+ request.post(REMITTANCE_ENDPOINT, raw_params.transform_keys(&:to_sym))
83
+ end
84
+
85
+ # Async variant of {#process} — returns immediately while Veryfi
86
+ # processes the check in the background.
87
+ def process_async(raw_params)
88
+ request.post(ASYNC_ENDPOINT, build_file_payload(raw_params))
89
+ end
90
+
91
+ # Async variant of {#process_url}.
92
+ def process_url_async(raw_params)
93
+ request.post(ASYNC_ENDPOINT, raw_params.transform_keys(&:to_sym))
94
+ end
95
+
96
+ # Update writable fields on a processed check.
97
+ #
98
+ # @example
99
+ # client.check.update(check_id, notes: "needs review")
100
+ #
101
+ # @param id [Integer]
102
+ # @param params [Hash]
103
+ # @return [Veryfi::Resource]
104
+ def update(id, params)
105
+ request.put("#{ENDPOINT}#{id}/", params)
106
+ end
107
+
108
+ # Delete a check.
109
+ #
110
+ # @param id [Integer]
111
+ # @return [Veryfi::Resource]
112
+ def delete(id)
113
+ request.delete("#{ENDPOINT}#{id}/")
114
+ end
115
+
116
+ private
117
+
118
+ def build_file_payload(raw_params)
119
+ params = raw_params.transform_keys(&:to_sym)
120
+ file_path = params.delete(:file_path)
121
+ file_name = params.delete(:file_name)
122
+
123
+ file_payload(file_path, file_name).merge(params)
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Veryfi
4
+ module Api
5
+ # Document classification endpoint (`/partner/classify/`).
6
+ #
7
+ # Given a file and an optional set of candidate document types,
8
+ # returns Veryfi's best guess at what kind of document it is (invoice,
9
+ # receipt, w-2, …) along with confidence scores.
10
+ #
11
+ # @see https://docs.veryfi.com/api/classify/classify-a-document/
12
+ class Classify
13
+ include FilePayload
14
+
15
+ ENDPOINT = "/partner/classify/"
16
+
17
+ attr_reader :request
18
+
19
+ def initialize(request)
20
+ @request = request
21
+ end
22
+
23
+ # Upload a local file for classification.
24
+ #
25
+ # @param raw_params [Hash]
26
+ # @option raw_params [String] :file_path **required.** Local path.
27
+ # @option raw_params [String] :file_name (basename of `:file_path`)
28
+ # @option raw_params [Array<String>] :document_types (`nil` = use Veryfi's full default set)
29
+ # Restrict the classifier to these document types.
30
+ # @return [Veryfi::Resource] e.g. `{ "document_type" => "invoice", "score" => 0.98, ... }`
31
+ def process(raw_params)
32
+ params = raw_params.transform_keys(&:to_sym)
33
+ file_path = params.delete(:file_path)
34
+ file_name = params.delete(:file_name)
35
+
36
+ payload = file_payload(file_path, file_name).merge(params)
37
+
38
+ request.post(ENDPOINT, payload)
39
+ end
40
+
41
+ # URL variant of {#process}.
42
+ #
43
+ # @param raw_params [Hash]
44
+ # @option raw_params [String] :file_url single URL
45
+ # @option raw_params [Array<String>] :file_urls list of URLs (alternative)
46
+ # @option raw_params [Array<String>] :document_types (`nil`)
47
+ # @return [Veryfi::Resource]
48
+ def process_url(raw_params)
49
+ request.post(ENDPOINT, raw_params.transform_keys(&:to_sym))
50
+ end
51
+ end
52
+ end
53
+ end