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.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +1 -1
- data/.github/workflows/test.yml +1 -1
- data/.gitignore +4 -1
- data/.rubocop.yml +5 -1
- data/.ruby-version +1 -1
- data/.yardopts +10 -0
- data/Gemfile.lock +55 -56
- data/README.md +530 -2
- data/Rakefile +21 -0
- data/lib/veryfi/api/any_document.rb +123 -0
- data/lib/veryfi/api/bank_statement.rb +114 -0
- data/lib/veryfi/api/bank_statement_split.rb +66 -0
- data/lib/veryfi/api/business_card.rb +84 -0
- data/lib/veryfi/api/check.rb +127 -0
- data/lib/veryfi/api/classify.rb +53 -0
- data/lib/veryfi/api/document.rb +117 -0
- data/lib/veryfi/api/document_tag.rb +43 -0
- data/lib/veryfi/api/file_payload.rb +23 -0
- data/lib/veryfi/api/line_item.rb +55 -0
- data/lib/veryfi/api/pdf_split.rb +75 -0
- data/lib/veryfi/api/tag.rb +14 -0
- data/lib/veryfi/api/tag_operations.rb +63 -0
- data/lib/veryfi/api/tax_line.rb +71 -0
- data/lib/veryfi/api/w2.rb +90 -0
- data/lib/veryfi/api/w2_split.rb +68 -0
- data/lib/veryfi/api/w8.rb +90 -0
- data/lib/veryfi/api/w9.rb +92 -0
- data/lib/veryfi/client.rb +61 -17
- data/lib/veryfi/configuration.rb +28 -0
- data/lib/veryfi/error.rb +98 -12
- data/lib/veryfi/request.rb +22 -11
- data/lib/veryfi/resource.rb +102 -0
- data/lib/veryfi/version.rb +1 -1
- data/lib/veryfi.rb +64 -0
- data/veryfi.gemspec +24 -2
- metadata +40 -8
data/lib/veryfi/api/document.rb
CHANGED
|
@@ -4,7 +4,14 @@ require "base64"
|
|
|
4
4
|
|
|
5
5
|
module Veryfi
|
|
6
6
|
module Api
|
|
7
|
+
# Receipts & invoices endpoints (`/partner/documents/`).
|
|
8
|
+
#
|
|
9
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/
|
|
7
10
|
class Document
|
|
11
|
+
# Default categories sent with `process` / `process_url` when the
|
|
12
|
+
# caller does not supply their own `:categories` list. Veryfi will
|
|
13
|
+
# bucket the document into one of these values for the `category`
|
|
14
|
+
# field on the response.
|
|
8
15
|
CATEGORIES = [
|
|
9
16
|
"Advertising & Marketing",
|
|
10
17
|
"Automotive",
|
|
@@ -29,10 +36,63 @@ module Veryfi
|
|
|
29
36
|
@request = request
|
|
30
37
|
end
|
|
31
38
|
|
|
39
|
+
# List previously processed documents.
|
|
40
|
+
#
|
|
41
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/search-documents/
|
|
42
|
+
#
|
|
43
|
+
# @param params [Hash] query-string parameters (all optional)
|
|
44
|
+
# @option params [String] :q free-text search query
|
|
45
|
+
# @option params [String] :external_id filter by your own document id
|
|
46
|
+
# @option params [String] :tag filter by tag name
|
|
47
|
+
# @option params [String] :created__gt "YYYY-MM-DD HH:MM:SS" — strictly after
|
|
48
|
+
# @option params [String] :created__gte "YYYY-MM-DD HH:MM:SS" — after or equal
|
|
49
|
+
# @option params [String] :created__lt "YYYY-MM-DD HH:MM:SS" — strictly before
|
|
50
|
+
# @option params [String] :created__lte "YYYY-MM-DD HH:MM:SS" — before or equal
|
|
51
|
+
# @option params [Integer] :page 1-indexed page number (default 1)
|
|
52
|
+
# @option params [Integer] :page_size items per page (default 50)
|
|
53
|
+
#
|
|
54
|
+
# @return [Veryfi::Resource] `{ "documents" => [...] }`
|
|
32
55
|
def all(params = {})
|
|
33
56
|
request.get("/partner/documents/", params)
|
|
34
57
|
end
|
|
35
58
|
|
|
59
|
+
# Upload a local file and extract its data.
|
|
60
|
+
#
|
|
61
|
+
# Required:
|
|
62
|
+
# * `:file_path` — path on disk to the file to process.
|
|
63
|
+
#
|
|
64
|
+
# All other keys below are optional. **Omitting a key is equivalent to
|
|
65
|
+
# passing its default value** — both produce the same API call. Pass a
|
|
66
|
+
# key explicitly only when you want a non-default value or when you
|
|
67
|
+
# want to make the intent explicit in your code.
|
|
68
|
+
#
|
|
69
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/process-a-document/
|
|
70
|
+
#
|
|
71
|
+
# @param raw_params [Hash]
|
|
72
|
+
# @option raw_params [String] :file_path **required.** Local path to the file.
|
|
73
|
+
# @option raw_params [String] :file_name (basename of `:file_path`, extension stripped)
|
|
74
|
+
# Display name sent to Veryfi.
|
|
75
|
+
# @option raw_params [Array<String>] :categories ({CATEGORIES})
|
|
76
|
+
# Restrict Veryfi's categorization to this set.
|
|
77
|
+
# @option raw_params [Array<String>] :tags (`nil`)
|
|
78
|
+
# Tags to attach to the resulting document.
|
|
79
|
+
# @option raw_params [Boolean] :auto_delete (`false`)
|
|
80
|
+
# If true, delete from Veryfi storage right after extraction.
|
|
81
|
+
# @option raw_params [Boolean] :boost_mode (`false`)
|
|
82
|
+
# Skip data enrichment for faster, less-accurate processing.
|
|
83
|
+
# @option raw_params [Boolean] :async (`false`)
|
|
84
|
+
# Return immediately; the document keeps processing server-side.
|
|
85
|
+
# Prefer the dedicated async endpoint where available.
|
|
86
|
+
# @option raw_params [String] :external_id (`nil`)
|
|
87
|
+
# Your own identifier to associate with the document.
|
|
88
|
+
# @option raw_params [Integer] :max_pages_to_process (`nil` = all pages)
|
|
89
|
+
# Cap pages read, starting from page 1.
|
|
90
|
+
# @option raw_params [Hash] :bounding_boxes (`false`)
|
|
91
|
+
# Return bounding-box info for extracted fields.
|
|
92
|
+
# @option raw_params [Hash] :confidence_details (`false`)
|
|
93
|
+
# Return confidence score details.
|
|
94
|
+
#
|
|
95
|
+
# @return [Veryfi::Resource] Extracted document data.
|
|
36
96
|
def process(raw_params)
|
|
37
97
|
params = setup_create_params(raw_params)
|
|
38
98
|
|
|
@@ -48,20 +108,77 @@ module Veryfi
|
|
|
48
108
|
request.post("/partner/documents/", payload)
|
|
49
109
|
end
|
|
50
110
|
|
|
111
|
+
# Process a document from a public URL.
|
|
112
|
+
#
|
|
113
|
+
# Either `:file_url` (single) or `:file_urls` (multiple, processed as
|
|
114
|
+
# one logical document) must be present. All other params behave the
|
|
115
|
+
# same as in {#process}.
|
|
116
|
+
#
|
|
117
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/process-a-document/
|
|
118
|
+
#
|
|
119
|
+
# @param raw_params [Hash]
|
|
120
|
+
# @option raw_params [String] :file_url publicly accessible URL to a single file
|
|
121
|
+
# @option raw_params [Array<String>] :file_urls list of publicly accessible URLs
|
|
122
|
+
# @option raw_params [Array<String>] :categories ({CATEGORIES})
|
|
123
|
+
# @option raw_params [Array<String>] :tags (`nil`)
|
|
124
|
+
# @option raw_params [Boolean] :auto_delete (`false`)
|
|
125
|
+
# @option raw_params [Boolean] :boost_mode (`false`)
|
|
126
|
+
# @option raw_params [Boolean] :async (`false`)
|
|
127
|
+
# @option raw_params [String] :external_id (`nil`)
|
|
128
|
+
# @option raw_params [Integer] :max_pages_to_process (`nil` = all pages)
|
|
129
|
+
#
|
|
130
|
+
# @return [Veryfi::Resource]
|
|
51
131
|
def process_url(raw_params)
|
|
52
132
|
params = setup_create_params(raw_params)
|
|
53
133
|
|
|
54
134
|
request.post("/partner/documents/", params)
|
|
55
135
|
end
|
|
56
136
|
|
|
137
|
+
# Bulk-process many documents from URLs in a single call.
|
|
138
|
+
#
|
|
139
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/bulk-process-multiple-documents/
|
|
140
|
+
# @note This endpoint must be enabled for your account. Contact support@veryfi.com.
|
|
141
|
+
#
|
|
142
|
+
# @param file_urls [Array<String>] publicly accessible URLs
|
|
143
|
+
# @return [Veryfi::Resource] `{ "document_ids" => [...] }`
|
|
144
|
+
def process_bulk(file_urls)
|
|
145
|
+
request.post("/partner/documents/bulk/", file_urls: file_urls)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Fetch a single document by id.
|
|
149
|
+
#
|
|
150
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/get-a-document/
|
|
151
|
+
#
|
|
152
|
+
# @param id [Integer] document id
|
|
153
|
+
# @param params [Hash] query-string parameters (all optional)
|
|
154
|
+
# @option params [Boolean] :bounding_boxes (`false`) Include bounding boxes in the response.
|
|
155
|
+
# @option params [Boolean] :confidence_details (`false`) Include per-field confidence scores.
|
|
156
|
+
#
|
|
157
|
+
# @return [Veryfi::Resource]
|
|
57
158
|
def get(id, params = {})
|
|
58
159
|
request.get("/partner/documents/#{id}", params)
|
|
59
160
|
end
|
|
60
161
|
|
|
162
|
+
# Update writable fields on a previously processed document.
|
|
163
|
+
#
|
|
164
|
+
# @example
|
|
165
|
+
# client.document.update(44_691_518, date: "2021-01-01", notes: "look what I did")
|
|
166
|
+
#
|
|
167
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/update-a-document/
|
|
168
|
+
#
|
|
169
|
+
# @param id [Integer] document id
|
|
170
|
+
# @param params [Hash] any writable fields you want to change
|
|
171
|
+
# @return [Veryfi::Resource] the updated document
|
|
61
172
|
def update(id, params)
|
|
62
173
|
request.put("/partner/documents/#{id}", params)
|
|
63
174
|
end
|
|
64
175
|
|
|
176
|
+
# Delete a document.
|
|
177
|
+
#
|
|
178
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/delete-a-document/
|
|
179
|
+
#
|
|
180
|
+
# @param id [Integer]
|
|
181
|
+
# @return [Veryfi::Resource] `{ "status" => "ok", "message" => "..." }`
|
|
65
182
|
def delete(id)
|
|
66
183
|
request.delete("/partner/documents/#{id}")
|
|
67
184
|
end
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Veryfi
|
|
4
4
|
module Api
|
|
5
|
+
# Tags on a specific document (`/partner/documents/{id}/tags/`).
|
|
6
|
+
#
|
|
7
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/get-document-tags/
|
|
5
8
|
class DocumentTag
|
|
6
9
|
attr_reader :request
|
|
7
10
|
|
|
@@ -9,20 +12,60 @@ module Veryfi
|
|
|
9
12
|
@request = request
|
|
10
13
|
end
|
|
11
14
|
|
|
15
|
+
# List tags on a document.
|
|
16
|
+
#
|
|
17
|
+
# @param document_id [Integer]
|
|
18
|
+
# @param params [Hash] optional query-string parameters
|
|
19
|
+
# @return [Array<Veryfi::Resource>] the `"tags"` array from the response
|
|
12
20
|
def all(document_id, params = {})
|
|
13
21
|
response = request.get("/partner/documents/#{document_id}/tags/", params)
|
|
14
22
|
|
|
15
23
|
response["tags"]
|
|
16
24
|
end
|
|
17
25
|
|
|
26
|
+
# Add a single tag to a document. (PUT semantics — creates the tag if
|
|
27
|
+
# it does not exist, otherwise links the existing tag.)
|
|
28
|
+
#
|
|
29
|
+
# @param document_id [Integer]
|
|
30
|
+
# @param params [Hash]
|
|
31
|
+
# @option params [String] :name **required.** Tag name.
|
|
32
|
+
# @return [Veryfi::Resource] the linked tag
|
|
18
33
|
def add(document_id, params)
|
|
19
34
|
request.put("/partner/documents/#{document_id}/tags/", params)
|
|
20
35
|
end
|
|
21
36
|
|
|
37
|
+
# Add many tags to a document in a single call.
|
|
38
|
+
#
|
|
39
|
+
# @param document_id [Integer]
|
|
40
|
+
# @param tags [Array<String>] tag names
|
|
41
|
+
# @return [Veryfi::Resource] `{ "tags" => [...] }`
|
|
42
|
+
def add_multiple(document_id, tags)
|
|
43
|
+
request.post("/partner/documents/#{document_id}/tags/", tags: tags)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Replace the entire tag list on a document (PUT on the parent
|
|
47
|
+
# resource with a `tags:` array).
|
|
48
|
+
#
|
|
49
|
+
# @param document_id [Integer]
|
|
50
|
+
# @param tags [Array<String>] new full list of tag names
|
|
51
|
+
# @return [Veryfi::Resource] the updated document
|
|
52
|
+
def replace(document_id, tags)
|
|
53
|
+
request.put("/partner/documents/#{document_id}/", tags: tags)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Unlink every tag from a document.
|
|
57
|
+
#
|
|
58
|
+
# @param document_id [Integer]
|
|
59
|
+
# @return [Veryfi::Resource]
|
|
22
60
|
def delete_all(document_id)
|
|
23
61
|
request.delete("/partner/documents/#{document_id}/tags/")
|
|
24
62
|
end
|
|
25
63
|
|
|
64
|
+
# Unlink a single tag from a document.
|
|
65
|
+
#
|
|
66
|
+
# @param document_id [Integer]
|
|
67
|
+
# @param id [Integer] tag id
|
|
68
|
+
# @return [Veryfi::Resource]
|
|
26
69
|
def delete(document_id, id)
|
|
27
70
|
request.delete("/partner/documents/#{document_id}/tags/#{id}")
|
|
28
71
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "base64"
|
|
4
|
+
|
|
5
|
+
module Veryfi
|
|
6
|
+
module Api
|
|
7
|
+
# Mix-in providing a small helper to turn a local file path into the
|
|
8
|
+
# `{ file_name:, file_data: }` payload that all of Veryfi's "process"
|
|
9
|
+
# endpoints expect.
|
|
10
|
+
module FilePayload
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def file_payload(file_path, file_name = nil)
|
|
14
|
+
encoded = Base64.encode64(File.read(file_path)).gsub("\n", "")
|
|
15
|
+
|
|
16
|
+
{
|
|
17
|
+
file_name: file_name || File.basename(file_path),
|
|
18
|
+
file_data: encoded
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/veryfi/api/line_item.rb
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Veryfi
|
|
4
4
|
module Api
|
|
5
|
+
# Line items on a processed document (`/partner/documents/{id}/line-items/`).
|
|
6
|
+
#
|
|
7
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/get-document-line-items/
|
|
5
8
|
class LineItem
|
|
6
9
|
attr_reader :request
|
|
7
10
|
|
|
@@ -9,26 +12,78 @@ module Veryfi
|
|
|
9
12
|
@request = request
|
|
10
13
|
end
|
|
11
14
|
|
|
15
|
+
# List all line items on a document.
|
|
16
|
+
#
|
|
17
|
+
# @param document_id [Integer]
|
|
18
|
+
# @param params [Hash] optional query-string parameters
|
|
19
|
+
# @return [Array<Veryfi::Resource>] line items (the `"line_items"` array from the response)
|
|
12
20
|
def all(document_id, params = {})
|
|
13
21
|
response = request.get("/partner/documents/#{document_id}/line-items/", params)
|
|
14
22
|
response["line_items"]
|
|
15
23
|
end
|
|
16
24
|
|
|
25
|
+
# Add a line item to an existing document.
|
|
26
|
+
#
|
|
27
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/create-a-line-item/
|
|
28
|
+
#
|
|
29
|
+
# @param document_id [Integer]
|
|
30
|
+
# @param params [Hash] line-item body. Common fields:
|
|
31
|
+
# @option params [String] :description **required.** Free-text description.
|
|
32
|
+
# @option params [Numeric] :total **required.** Line total.
|
|
33
|
+
# @option params [Numeric] :quantity (`1`)
|
|
34
|
+
# @option params [Numeric] :price Unit price.
|
|
35
|
+
# @option params [Numeric] :tax Tax amount.
|
|
36
|
+
# @option params [Numeric] :tax_rate Tax rate (%).
|
|
37
|
+
# @option params [Numeric] :discount Discount amount.
|
|
38
|
+
# @option params [String] :sku SKU / product code.
|
|
39
|
+
# @option params [String] :type "product" / "service" / "fuel" / ...
|
|
40
|
+
# @option params [String] :unit_of_measure
|
|
41
|
+
# @option params [Integer] :order Display order (0-indexed).
|
|
42
|
+
# @return [Veryfi::Resource] the created line item
|
|
17
43
|
def create(document_id, params)
|
|
18
44
|
request.post("/partner/documents/#{document_id}/line-items/", params)
|
|
19
45
|
end
|
|
20
46
|
|
|
47
|
+
# Fetch a single line item.
|
|
48
|
+
#
|
|
49
|
+
# @param document_id [Integer]
|
|
50
|
+
# @param id [Integer] line item id
|
|
51
|
+
# @param params [Hash] optional query-string parameters
|
|
52
|
+
# @return [Veryfi::Resource]
|
|
21
53
|
def get(document_id, id, params = {})
|
|
22
54
|
request.get("/partner/documents/#{document_id}/line-items/#{id}", params)
|
|
23
55
|
end
|
|
24
56
|
|
|
57
|
+
# Update a line item.
|
|
58
|
+
#
|
|
59
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/update-a-line-item/
|
|
60
|
+
#
|
|
61
|
+
# @param document_id [Integer]
|
|
62
|
+
# @param id [Integer]
|
|
63
|
+
# @param params [Hash] writable fields you want to change
|
|
64
|
+
# @return [Veryfi::Resource] the updated line item
|
|
25
65
|
def update(document_id, id, params)
|
|
26
66
|
request.put("/partner/documents/#{document_id}/line-items/#{id}", params)
|
|
27
67
|
end
|
|
28
68
|
|
|
69
|
+
# Delete a single line item.
|
|
70
|
+
#
|
|
71
|
+
# @param document_id [Integer]
|
|
72
|
+
# @param id [Integer]
|
|
73
|
+
# @return [Veryfi::Resource] `{ "status" => "ok", "message" => "..." }`
|
|
29
74
|
def delete(document_id, id)
|
|
30
75
|
request.delete("/partner/documents/#{document_id}/line-items/#{id}")
|
|
31
76
|
end
|
|
77
|
+
|
|
78
|
+
# Delete every line item on a document.
|
|
79
|
+
#
|
|
80
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/delete-all-document-line-items/
|
|
81
|
+
#
|
|
82
|
+
# @param document_id [Integer]
|
|
83
|
+
# @return [Veryfi::Resource]
|
|
84
|
+
def delete_all(document_id)
|
|
85
|
+
request.delete("/partner/documents/#{document_id}/line-items")
|
|
86
|
+
end
|
|
32
87
|
end
|
|
33
88
|
end
|
|
34
89
|
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Veryfi
|
|
4
|
+
module Api
|
|
5
|
+
# PDF splitting endpoints (`/partner/documents-set/`).
|
|
6
|
+
#
|
|
7
|
+
# Use these when you have a single PDF containing multiple receipts /
|
|
8
|
+
# invoices. Veryfi will split it and process each page as its own
|
|
9
|
+
# {Document}; you receive a collection that references the individual
|
|
10
|
+
# document ids it produced.
|
|
11
|
+
#
|
|
12
|
+
# @see https://docs.veryfi.com/api/receipts-invoices/split-and-process-a-pdf/
|
|
13
|
+
class PdfSplit
|
|
14
|
+
include FilePayload
|
|
15
|
+
|
|
16
|
+
ENDPOINT = "/partner/documents-set/"
|
|
17
|
+
|
|
18
|
+
attr_reader :request
|
|
19
|
+
|
|
20
|
+
def initialize(request)
|
|
21
|
+
@request = request
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# List previously processed document sets.
|
|
25
|
+
#
|
|
26
|
+
# @param params [Hash] optional query-string parameters
|
|
27
|
+
# @return [Veryfi::Resource]
|
|
28
|
+
def all(params = {})
|
|
29
|
+
request.get(ENDPOINT, params)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Fetch a single document set by id.
|
|
33
|
+
#
|
|
34
|
+
# @param id [Integer]
|
|
35
|
+
# @param params [Hash] optional query-string parameters
|
|
36
|
+
# @return [Veryfi::Resource]
|
|
37
|
+
def get(id, params = {})
|
|
38
|
+
request.get("#{ENDPOINT}#{id}", params)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Upload a multi-document PDF and split-and-process it.
|
|
42
|
+
#
|
|
43
|
+
# @param raw_params [Hash]
|
|
44
|
+
# @option raw_params [String] :file_path **required.** Local path.
|
|
45
|
+
# @option raw_params [String] :file_name (basename of `:file_path`)
|
|
46
|
+
# @option raw_params [Array<String>] :categories (`[]`) Restrict categorization to these values.
|
|
47
|
+
# @return [Veryfi::Resource]
|
|
48
|
+
def process(raw_params)
|
|
49
|
+
params = raw_params.transform_keys(&:to_sym)
|
|
50
|
+
file_path = params.delete(:file_path)
|
|
51
|
+
file_name = params.delete(:file_name)
|
|
52
|
+
params[:categories] ||= []
|
|
53
|
+
|
|
54
|
+
payload = file_payload(file_path, file_name).merge(params)
|
|
55
|
+
|
|
56
|
+
request.post(ENDPOINT, payload)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# URL variant of {#process}.
|
|
60
|
+
#
|
|
61
|
+
# @param raw_params [Hash]
|
|
62
|
+
# @option raw_params [String] :file_url single URL
|
|
63
|
+
# @option raw_params [Array<String>] :file_urls list of URLs (alternative to `:file_url`)
|
|
64
|
+
# @option raw_params [Array<String>] :categories (`[]`)
|
|
65
|
+
# @option raw_params [Integer] :max_pages_to_process (`nil`)
|
|
66
|
+
# @return [Veryfi::Resource]
|
|
67
|
+
def process_url(raw_params)
|
|
68
|
+
params = raw_params.transform_keys(&:to_sym)
|
|
69
|
+
params[:categories] ||= []
|
|
70
|
+
|
|
71
|
+
request.post(ENDPOINT, params)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/veryfi/api/tag.rb
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module Veryfi
|
|
4
4
|
module Api
|
|
5
|
+
# Global tag catalog (`/partner/tags/`).
|
|
6
|
+
#
|
|
7
|
+
# Note: This endpoint is not present in every Veryfi API version. For
|
|
8
|
+
# managing tags on a specific document use {Veryfi::Api::DocumentTag}
|
|
9
|
+
# (or the `.tags` / `.add_tag` / `.add_tags` / `.delete_tag` methods
|
|
10
|
+
# on each processed-document resource — see {TagOperations}).
|
|
5
11
|
class Tag
|
|
6
12
|
attr_reader :request
|
|
7
13
|
|
|
@@ -9,12 +15,20 @@ module Veryfi
|
|
|
9
15
|
@request = request
|
|
10
16
|
end
|
|
11
17
|
|
|
18
|
+
# List every tag known to the account.
|
|
19
|
+
#
|
|
20
|
+
# @param params [Hash] optional query-string parameters
|
|
21
|
+
# @return [Array<Veryfi::Resource>] the `"tags"` array from the response
|
|
12
22
|
def all(params = {})
|
|
13
23
|
response = request.get("/partner/tags/", params)
|
|
14
24
|
|
|
15
25
|
response["tags"]
|
|
16
26
|
end
|
|
17
27
|
|
|
28
|
+
# Delete a tag by id.
|
|
29
|
+
#
|
|
30
|
+
# @param id [Integer]
|
|
31
|
+
# @return [Veryfi::Resource]
|
|
18
32
|
def delete(id)
|
|
19
33
|
request.delete("/partner/tags/#{id}")
|
|
20
34
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Veryfi
|
|
4
|
+
module Api
|
|
5
|
+
# Mix-in providing the standard per-resource tag endpoints used by
|
|
6
|
+
# processed-document resources (Any Document, Bank Statement, Business
|
|
7
|
+
# Card, Check, W-2, W-8, W-9). Each host must define an `ENDPOINT`
|
|
8
|
+
# constant pointing at the resource collection (e.g. `"/partner/checks/"`).
|
|
9
|
+
#
|
|
10
|
+
# When included, the host class exposes:
|
|
11
|
+
#
|
|
12
|
+
# - `#tags(id, params = {})` → GET `…/{id}/tags`
|
|
13
|
+
# - `#add_tag(id, params)` → PUT `…/{id}/tags` (single)
|
|
14
|
+
# - `#add_tags(id, tags)` → POST `…/{id}/tags` (multiple)
|
|
15
|
+
# - `#delete_tag(id, tag_id)` → DELETE `…/{id}/tags/{tag_id}`
|
|
16
|
+
# - `#delete_tags(id)` → DELETE `…/{id}/tags` (all)
|
|
17
|
+
module TagOperations
|
|
18
|
+
# List tags on the resource.
|
|
19
|
+
#
|
|
20
|
+
# @param id [Integer] resource id
|
|
21
|
+
# @param params [Hash] optional query-string parameters
|
|
22
|
+
# @return [Veryfi::Resource] `{ "tags" => [...] }`
|
|
23
|
+
def tags(id, params = {})
|
|
24
|
+
request.get("#{self.class::ENDPOINT}#{id}/tags", params)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Add (or link) a single tag.
|
|
28
|
+
#
|
|
29
|
+
# @param id [Integer] resource id
|
|
30
|
+
# @param params [Hash] e.g. `{ name: "priority" }`
|
|
31
|
+
# @return [Veryfi::Resource] the linked tag
|
|
32
|
+
def add_tag(id, params)
|
|
33
|
+
request.put("#{self.class::ENDPOINT}#{id}/tags", params)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Add many tags in a single call.
|
|
37
|
+
#
|
|
38
|
+
# @param id [Integer] resource id
|
|
39
|
+
# @param tags [Array<String>] tag names
|
|
40
|
+
# @return [Veryfi::Resource] `{ "tags" => [...] }`
|
|
41
|
+
def add_tags(id, tags)
|
|
42
|
+
request.post("#{self.class::ENDPOINT}#{id}/tags", tags: tags)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Unlink a single tag from the resource.
|
|
46
|
+
#
|
|
47
|
+
# @param id [Integer] resource id
|
|
48
|
+
# @param tag_id [Integer]
|
|
49
|
+
# @return [Veryfi::Resource]
|
|
50
|
+
def delete_tag(id, tag_id)
|
|
51
|
+
request.delete("#{self.class::ENDPOINT}#{id}/tags/#{tag_id}")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Unlink every tag from the resource.
|
|
55
|
+
#
|
|
56
|
+
# @param id [Integer] resource id
|
|
57
|
+
# @return [Veryfi::Resource]
|
|
58
|
+
def delete_tags(id)
|
|
59
|
+
request.delete("#{self.class::ENDPOINT}#{id}/tags")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Veryfi
|
|
4
|
+
module Api
|
|
5
|
+
# Tax lines on a processed document
|
|
6
|
+
# (`/partner/documents/{id}/tax-lines`).
|
|
7
|
+
#
|
|
8
|
+
# Most documents have at most a handful of tax lines (e.g. one for state
|
|
9
|
+
# sales tax, one for local). This namespace lets you list, add, edit
|
|
10
|
+
# and remove them on demand.
|
|
11
|
+
class TaxLine
|
|
12
|
+
attr_reader :request
|
|
13
|
+
|
|
14
|
+
def initialize(request)
|
|
15
|
+
@request = request
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# List the tax lines for a document.
|
|
19
|
+
#
|
|
20
|
+
# @param document_id [Integer]
|
|
21
|
+
# @param params [Hash] optional query-string parameters
|
|
22
|
+
# @return [Veryfi::Resource] `{ "tax_lines" => [...] }`
|
|
23
|
+
def all(document_id, params = {})
|
|
24
|
+
request.get("/partner/documents/#{document_id}/tax-lines", params)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Create a tax line on a document.
|
|
28
|
+
#
|
|
29
|
+
# @param document_id [Integer]
|
|
30
|
+
# @param params [Hash]
|
|
31
|
+
# @option params [String] :name **required.** e.g. "Sales Tax".
|
|
32
|
+
# @option params [Numeric] :rate Tax rate (%).
|
|
33
|
+
# @option params [Numeric] :base Taxable base amount.
|
|
34
|
+
# @option params [Numeric] :total Tax amount.
|
|
35
|
+
# @option params [Integer] :order Display order (0-indexed).
|
|
36
|
+
# @return [Veryfi::Resource] the created tax line
|
|
37
|
+
def create(document_id, params)
|
|
38
|
+
request.post("/partner/documents/#{document_id}/tax-lines", params)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Fetch a single tax line.
|
|
42
|
+
#
|
|
43
|
+
# @param document_id [Integer]
|
|
44
|
+
# @param id [Integer]
|
|
45
|
+
# @param params [Hash] optional query-string parameters
|
|
46
|
+
# @return [Veryfi::Resource]
|
|
47
|
+
def get(document_id, id, params = {})
|
|
48
|
+
request.get("/partner/documents/#{document_id}/tax-lines/#{id}", params)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Update a tax line.
|
|
52
|
+
#
|
|
53
|
+
# @param document_id [Integer]
|
|
54
|
+
# @param id [Integer]
|
|
55
|
+
# @param params [Hash] writable fields you want to change
|
|
56
|
+
# @return [Veryfi::Resource]
|
|
57
|
+
def update(document_id, id, params)
|
|
58
|
+
request.put("/partner/documents/#{document_id}/tax-lines/#{id}", params)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Delete a tax line.
|
|
62
|
+
#
|
|
63
|
+
# @param document_id [Integer]
|
|
64
|
+
# @param id [Integer]
|
|
65
|
+
# @return [Veryfi::Resource]
|
|
66
|
+
def delete(document_id, id)
|
|
67
|
+
request.delete("/partner/documents/#{document_id}/tax-lines/#{id}")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Veryfi
|
|
4
|
+
module Api
|
|
5
|
+
# W-2 endpoints (`/partner/w2s/`).
|
|
6
|
+
#
|
|
7
|
+
# @see https://docs.veryfi.com/api/w2s/
|
|
8
|
+
class W2
|
|
9
|
+
include FilePayload
|
|
10
|
+
include TagOperations
|
|
11
|
+
|
|
12
|
+
ENDPOINT = "/partner/w2s/"
|
|
13
|
+
|
|
14
|
+
attr_reader :request
|
|
15
|
+
|
|
16
|
+
def initialize(request)
|
|
17
|
+
@request = request
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# List previously processed W-2 documents.
|
|
21
|
+
#
|
|
22
|
+
# @param params [Hash] optional query-string parameters
|
|
23
|
+
# @option params [String] :created_date__gt "YYYY-MM-DD HH:MM:SS" — strictly after
|
|
24
|
+
# @option params [String] :created_date__gte after or equal
|
|
25
|
+
# @option params [String] :created_date__lt strictly before
|
|
26
|
+
# @option params [String] :created_date__lte before or equal
|
|
27
|
+
# @option params [Integer] :page (1)
|
|
28
|
+
# @option params [Integer] :page_size (50)
|
|
29
|
+
# @return [Veryfi::Resource] `{ "documents" => [...] }`
|
|
30
|
+
def all(params = {})
|
|
31
|
+
request.get(ENDPOINT, params)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Fetch a single W-2 by id.
|
|
35
|
+
#
|
|
36
|
+
# @param id [Integer]
|
|
37
|
+
# @param params [Hash] optional query-string parameters
|
|
38
|
+
# @return [Veryfi::Resource]
|
|
39
|
+
def get(id, params = {})
|
|
40
|
+
request.get("#{ENDPOINT}#{id}/", params)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Upload a W-2 file and extract its fields.
|
|
44
|
+
#
|
|
45
|
+
# @param raw_params [Hash]
|
|
46
|
+
# @option raw_params [String] :file_path **required.** Local path.
|
|
47
|
+
# @option raw_params [String] :file_name (basename of `:file_path`)
|
|
48
|
+
# @return [Veryfi::Resource]
|
|
49
|
+
def process(raw_params)
|
|
50
|
+
params = raw_params.transform_keys(&:to_sym)
|
|
51
|
+
file_path = params.delete(:file_path)
|
|
52
|
+
file_name = params.delete(:file_name)
|
|
53
|
+
|
|
54
|
+
payload = file_payload(file_path, file_name).merge(params)
|
|
55
|
+
|
|
56
|
+
request.post(ENDPOINT, payload)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# URL variant of {#process}.
|
|
60
|
+
#
|
|
61
|
+
# @param raw_params [Hash]
|
|
62
|
+
# @option raw_params [String] :file_url **required.**
|
|
63
|
+
# @option raw_params [String] :file_name (basename of `:file_url`)
|
|
64
|
+
# @return [Veryfi::Resource]
|
|
65
|
+
def process_url(raw_params)
|
|
66
|
+
params = raw_params.transform_keys(&:to_sym)
|
|
67
|
+
params[:file_name] ||= File.basename(params[:file_url]) if params[:file_url]
|
|
68
|
+
|
|
69
|
+
request.post(ENDPOINT, params)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Update writable fields on a processed W-2.
|
|
73
|
+
#
|
|
74
|
+
# @param id [Integer]
|
|
75
|
+
# @param params [Hash]
|
|
76
|
+
# @return [Veryfi::Resource]
|
|
77
|
+
def update(id, params)
|
|
78
|
+
request.put("#{ENDPOINT}#{id}/", params)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Delete a W-2.
|
|
82
|
+
#
|
|
83
|
+
# @param id [Integer]
|
|
84
|
+
# @return [Veryfi::Resource]
|
|
85
|
+
def delete(id)
|
|
86
|
+
request.delete("#{ENDPOINT}#{id}/")
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|