veryfi 0.0.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +26 -0
- data/.github/workflows/test.yml +22 -0
- data/.rubocop.yml +24 -0
- data/Gemfile.lock +56 -39
- data/README.md +57 -45
- data/bin/release +12 -0
- data/coverage/coverage-badge.png +0 -0
- data/docs/.gitignore +5 -0
- data/docs/404.html +25 -0
- data/docs/Gemfile +30 -0
- data/docs/Gemfile.lock +282 -0
- data/docs/_config.yml +50 -0
- data/docs/_includes/footer.html +35 -0
- data/docs/_includes/header.html +30 -0
- data/docs/index.markdown +273 -0
- data/lib/veryfi/api/document.rb +60 -1
- data/lib/veryfi/api/document_tag.rb +31 -0
- data/lib/veryfi/api/line_item.rb +35 -0
- data/lib/veryfi/api/tag.rb +23 -0
- data/lib/veryfi/client.rb +13 -19
- data/lib/veryfi/error.rb +45 -0
- data/lib/veryfi/request.rb +51 -8
- data/lib/veryfi/signature.rb +2 -2
- data/lib/veryfi/version.rb +1 -1
- data/lib/veryfi.rb +4 -0
- data/veryfi.gemspec +7 -3
- metadata +68 -11
- data/bin/build +0 -6
data/docs/index.markdown
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
---
|
2
|
+
# Feel free to add content and custom Front Matter to this file.
|
3
|
+
# To modify the layout, see https://jekyllrb.com/docs/themes/#overriding-theme-defaults
|
4
|
+
|
5
|
+
layout: home
|
6
|
+
---
|
7
|
+
|
8
|
+
- [Minimal example](#minimal-example)
|
9
|
+
- [Document API](#document-api)
|
10
|
+
- [Line Items API](#line-items-api)
|
11
|
+
- [Tags API](#tags-api)
|
12
|
+
|
13
|
+
### Minimal example
|
14
|
+
|
15
|
+
Below is a sample script using <a href="https://www.veryfi.com" target="_blank">**Veryfi**</a> for OCR and extracting data from a document:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'veryfi'
|
19
|
+
|
20
|
+
veryfi_client = Veryfi::Client.new(
|
21
|
+
client_id: 'your_client_id',
|
22
|
+
client_secret: 'your_client_secret',
|
23
|
+
username: 'your_username',
|
24
|
+
api_key: 'your_password'
|
25
|
+
)
|
26
|
+
```
|
27
|
+
|
28
|
+
This submits a document for processing (3-5 seconds for a response)
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
params = {
|
32
|
+
file_path: './test/receipt.jpg',
|
33
|
+
auto_delete: true,
|
34
|
+
boost_mode: false,
|
35
|
+
async: false,
|
36
|
+
external_id: '123456789',
|
37
|
+
max_pages_to_process: 10,
|
38
|
+
tags: ['tag1'],
|
39
|
+
categories: [
|
40
|
+
'Advertising & Marketing',
|
41
|
+
'Automotive'
|
42
|
+
]
|
43
|
+
}
|
44
|
+
|
45
|
+
response = veryfi_client.document.process(params)
|
46
|
+
|
47
|
+
puts response
|
48
|
+
```
|
49
|
+
|
50
|
+
...or with a URL
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
params = {
|
54
|
+
file_url: "https://raw.githubusercontent.com/veryfi/veryfi-python/master/tests/assets/receipt_public.jpg",
|
55
|
+
auto_delete: true,
|
56
|
+
boost_mode: false,
|
57
|
+
async: false,
|
58
|
+
external_id: "123456789",
|
59
|
+
max_pages_to_process: 10,
|
60
|
+
tags: ["tag1"],
|
61
|
+
categories: [
|
62
|
+
"Advertising & Marketing",
|
63
|
+
"Automotive"
|
64
|
+
]
|
65
|
+
}
|
66
|
+
|
67
|
+
response = veryfi_client.document.process_url(params)
|
68
|
+
|
69
|
+
puts response
|
70
|
+
```
|
71
|
+
|
72
|
+
This will produce the following response:
|
73
|
+
|
74
|
+
```json
|
75
|
+
{
|
76
|
+
"abn_number": "",
|
77
|
+
"account_number": "",
|
78
|
+
"bill_to_address": "2 Court Square\nNew York, NY 12210",
|
79
|
+
"bill_to_name": "John Smith",
|
80
|
+
"bill_to_vat_number": "",
|
81
|
+
"card_number": "",
|
82
|
+
"cashback": 0,
|
83
|
+
"category": "Repairs & Maintenance",
|
84
|
+
"created": "2021-06-28 19:20:02",
|
85
|
+
"currency_code": "USD",
|
86
|
+
"date": "2019-02-11 00:00:00",
|
87
|
+
"delivery_date": "",
|
88
|
+
"discount": 0,
|
89
|
+
"document_reference_number": "",
|
90
|
+
"document_title": "",
|
91
|
+
"document_type": "invoice",
|
92
|
+
"due_date": "2019-02-26",
|
93
|
+
"duplicate_of": 37055375,
|
94
|
+
"external_id": "",
|
95
|
+
"id": 37187909,
|
96
|
+
"img_file_name": "receipt.png",
|
97
|
+
"img_thumbnail_url": "https://scdn.veryfi.com/receipts/thumbnail.png",
|
98
|
+
"img_url": "https://scdn.veryfi.com/receipts/receipt.png",
|
99
|
+
"insurance": "",
|
100
|
+
"invoice_number": "US-001",
|
101
|
+
"is_duplicate": 1,
|
102
|
+
"line_items": [
|
103
|
+
{
|
104
|
+
"date": "",
|
105
|
+
"description": "Front and rear brake cables",
|
106
|
+
"discount": 0,
|
107
|
+
"id": 68004313,
|
108
|
+
"order": 0,
|
109
|
+
"price": 100,
|
110
|
+
"quantity": 1,
|
111
|
+
"reference": "",
|
112
|
+
"section": "",
|
113
|
+
"sku": "",
|
114
|
+
"tax": 0,
|
115
|
+
"tax_rate": 0,
|
116
|
+
"total": 100,
|
117
|
+
"type": "product",
|
118
|
+
"unit_of_measure": ""
|
119
|
+
},
|
120
|
+
{
|
121
|
+
"date": "",
|
122
|
+
"description": "New set of pedal arms",
|
123
|
+
"discount": 0,
|
124
|
+
"id": 68004315,
|
125
|
+
"order": 1,
|
126
|
+
"price": 15,
|
127
|
+
"quantity": 2,
|
128
|
+
"reference": "",
|
129
|
+
"section": "",
|
130
|
+
"sku": "",
|
131
|
+
"tax": 0,
|
132
|
+
"tax_rate": 0,
|
133
|
+
"total": 30,
|
134
|
+
"type": "product",
|
135
|
+
"unit_of_measure": ""
|
136
|
+
},
|
137
|
+
{
|
138
|
+
"date": "",
|
139
|
+
"description": "Labor 3hrs",
|
140
|
+
"discount": 0,
|
141
|
+
"id": 68004316,
|
142
|
+
"order": 2,
|
143
|
+
"price": 5,
|
144
|
+
"quantity": 3,
|
145
|
+
"reference": "",
|
146
|
+
"section": "",
|
147
|
+
"sku": "",
|
148
|
+
"tax": 0,
|
149
|
+
"tax_rate": 0,
|
150
|
+
"total": 15,
|
151
|
+
"type": "service",
|
152
|
+
"unit_of_measure": ""
|
153
|
+
}
|
154
|
+
],
|
155
|
+
"notes": "",
|
156
|
+
"ocr_text": "\n\fEast Repair Inc.\n1912 Harvest Lane\nNew York, NY 12210\n\nBILL TO\t\tSHIP TO\tRECEIPT #\tUS-001\nJohn Smith\t\tJohn Smith\tRECEIPT DATE\t11/02/2019\n2 Court Square\t3787 Pineview Drive\n\tP.O.#\t2312/2019\nNew York, NY 12210\tCambridge, MA 12210\n\tDUE DATE\t26/02/2019\nReceipt Total\t\t\t$154.06\n\nQTY DESCRIPTION\t\t\tUNIT PRICE\tAMOUNT\n1\tFront and rear brake cables\t\t100.00\t100.00\n2\tNew set of pedal arms\t\t\t15.00\t30.00\n3\tLabor 3hrs\t\t\t\t5.00\t15.00\n\n\tSubtotal\t145.00\n\tSales Tax 6.25%\t9.06\n\nTERMS & CONDITIONS\nPayment is due within 15 days\nPlease make checks payable to: East Repair\n\tJohn Smith\n\tInc.\n",
|
157
|
+
"order_date": "",
|
158
|
+
"payment_display_name": "",
|
159
|
+
"payment_terms": "15 days",
|
160
|
+
"payment_type": "",
|
161
|
+
"phone_number": "",
|
162
|
+
"purchase_order_number": "2312/2019",
|
163
|
+
"rounding": 0,
|
164
|
+
"service_end_date": "",
|
165
|
+
"service_start_date": "",
|
166
|
+
"ship_date": "",
|
167
|
+
"ship_to_address": "3787 Pineview Drive\nCambridge, MA 12210",
|
168
|
+
"ship_to_name": "John Smith",
|
169
|
+
"shipping": 0,
|
170
|
+
"store_number": "",
|
171
|
+
"subtotal": 145,
|
172
|
+
"tax": 9.06,
|
173
|
+
"tax_lines": [
|
174
|
+
{
|
175
|
+
"base": 0,
|
176
|
+
"name": "Sales",
|
177
|
+
"order": 0,
|
178
|
+
"rate": 6.25,
|
179
|
+
"total": 9.06
|
180
|
+
}
|
181
|
+
],
|
182
|
+
"tip": 0,
|
183
|
+
"total": 154.06,
|
184
|
+
"total_weight": "",
|
185
|
+
"tracking_number": "",
|
186
|
+
"updated": "2021-06-28 19:20:03",
|
187
|
+
"vat_number": "",
|
188
|
+
"vendor": {
|
189
|
+
"address": "1912 Harvest Lane\nNew York, NY 12210",
|
190
|
+
"category": "Car Repair",
|
191
|
+
"email": "",
|
192
|
+
"fax_number": "",
|
193
|
+
"name": "East Repair",
|
194
|
+
"phone_number": "",
|
195
|
+
"raw_name": "East Repair Inc.",
|
196
|
+
"vendor_logo": "https://cdn.veryfi.com/logos/tmp/560806841.png",
|
197
|
+
"vendor_reg_number": "",
|
198
|
+
"vendor_type": "Car Repair",
|
199
|
+
"web": ""
|
200
|
+
},
|
201
|
+
"vendor_account_number": "",
|
202
|
+
"vendor_bank_name": "",
|
203
|
+
"vendor_bank_number": "",
|
204
|
+
"vendor_bank_swift": "",
|
205
|
+
"vendor_iban": ""
|
206
|
+
}
|
207
|
+
```
|
208
|
+
|
209
|
+
---
|
210
|
+
|
211
|
+
### Document API
|
212
|
+
|
213
|
+
See [API schema](https://app.swaggerhub.com/apis/Veryfi/verify-api/) for request params and response details.
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
# Update document
|
217
|
+
veryfi_client.document.update(document_id, params)
|
218
|
+
|
219
|
+
# Delete document by ID
|
220
|
+
veryfi_client.document.delete(document_id)
|
221
|
+
|
222
|
+
# Get document by ID
|
223
|
+
veryfi_client.document.get(document_id)
|
224
|
+
|
225
|
+
# List all documents
|
226
|
+
veryfi_client.document.all
|
227
|
+
```
|
228
|
+
|
229
|
+
---
|
230
|
+
|
231
|
+
### Line Items API
|
232
|
+
|
233
|
+
See [API schema](https://app.swaggerhub.com/apis/Veryfi/verify-api/) for request params and response details.
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
# Get document line items
|
237
|
+
veryfi_client.line_items.all(document_id)
|
238
|
+
|
239
|
+
# Get line item by document id and line item id
|
240
|
+
veryfi_client.line_items.get(document_id, id)
|
241
|
+
|
242
|
+
# Create/update/delete document line item
|
243
|
+
veryfi_client.line_items.create(document_id, params)
|
244
|
+
veryfi_client.line_items.update(document_id, params)
|
245
|
+
veryfi_client.line_items.delete(document_id, params)
|
246
|
+
```
|
247
|
+
|
248
|
+
---
|
249
|
+
|
250
|
+
### Tags API
|
251
|
+
|
252
|
+
See [API schema](https://app.swaggerhub.com/apis/Veryfi/verify-api/) for request params and response details.
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
# Tags
|
256
|
+
# List all tags
|
257
|
+
veryfi_client.tag.all
|
258
|
+
|
259
|
+
# Delete a tag by ID
|
260
|
+
veryfi_client.tag.delete(id)
|
261
|
+
|
262
|
+
# List all document tags
|
263
|
+
veryfi_client.document_tag.all(document_id)
|
264
|
+
|
265
|
+
# Add tag to document
|
266
|
+
veryfi_client.document_tag.add(document_id, name: "tag_name")
|
267
|
+
|
268
|
+
# Delete tag by document id and tag id
|
269
|
+
veryfi_client.document_tag.delete(document_id, id)
|
270
|
+
|
271
|
+
# Delete all document tags
|
272
|
+
veryfi_client.document_tag.delete_all(document_id)
|
273
|
+
```
|
data/lib/veryfi/api/document.rb
CHANGED
@@ -1,8 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "base64"
|
4
|
+
|
3
5
|
module Veryfi
|
4
6
|
module Api
|
5
7
|
class Document
|
8
|
+
CATEGORIES = [
|
9
|
+
"Advertising & Marketing",
|
10
|
+
"Automotive",
|
11
|
+
"Bank Charges & Fees",
|
12
|
+
"Legal & Professional Services",
|
13
|
+
"Insurance",
|
14
|
+
"Meals & Entertainment",
|
15
|
+
"Office Supplies & Software",
|
16
|
+
"Taxes & Licenses",
|
17
|
+
"Travel",
|
18
|
+
"Rent & Lease",
|
19
|
+
"Repairs & Maintenance",
|
20
|
+
"Payroll",
|
21
|
+
"Utilities",
|
22
|
+
"Job Supplies",
|
23
|
+
"Grocery"
|
24
|
+
].freeze
|
25
|
+
|
6
26
|
attr_reader :request
|
7
27
|
|
8
28
|
def initialize(request)
|
@@ -12,12 +32,51 @@ module Veryfi
|
|
12
32
|
def all(params = {})
|
13
33
|
response = request.get("/partner/documents/", params)
|
14
34
|
|
15
|
-
|
35
|
+
response.is_a?(Hash) ? [response] : response
|
36
|
+
end
|
37
|
+
|
38
|
+
def process(raw_params)
|
39
|
+
params = setup_create_params(raw_params)
|
40
|
+
|
41
|
+
file_content = File.read(params[:file_path])
|
42
|
+
file_name = File.basename(params[:file_path], ".*")
|
43
|
+
file_data = Base64.encode64(file_content).gsub("\n", "")
|
44
|
+
|
45
|
+
payload = params.reject { |k| k == :file_path }.merge(
|
46
|
+
file_name: file_name,
|
47
|
+
file_data: file_data
|
48
|
+
)
|
49
|
+
|
50
|
+
request.post("/partner/documents/", payload)
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_url(raw_params)
|
54
|
+
params = setup_create_params(raw_params)
|
55
|
+
|
56
|
+
request.post("/partner/documents/", params)
|
16
57
|
end
|
17
58
|
|
18
59
|
def get(id, params = {})
|
19
60
|
request.get("/partner/documents/#{id}", params)
|
20
61
|
end
|
62
|
+
|
63
|
+
def update(id, params)
|
64
|
+
request.put("/partner/documents/#{id}", params)
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete(id)
|
68
|
+
request.delete("/partner/documents/#{id}")
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def setup_create_params(raw_params)
|
74
|
+
params = raw_params.transform_keys(&:to_sym)
|
75
|
+
|
76
|
+
params[:categories] = CATEGORIES if params[:categories].to_a.empty?
|
77
|
+
|
78
|
+
params
|
79
|
+
end
|
21
80
|
end
|
22
81
|
end
|
23
82
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Veryfi
|
4
|
+
module Api
|
5
|
+
class DocumentTag
|
6
|
+
attr_reader :request
|
7
|
+
|
8
|
+
def initialize(request)
|
9
|
+
@request = request
|
10
|
+
end
|
11
|
+
|
12
|
+
def all(document_id, params = {})
|
13
|
+
response = request.get("/partner/documents/#{document_id}/tags/", params)
|
14
|
+
|
15
|
+
response["tags"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def add(document_id, params)
|
19
|
+
request.put("/partner/documents/#{document_id}/tags/", params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_all(document_id)
|
23
|
+
request.delete("/partner/documents/#{document_id}/tags/")
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete(document_id, id)
|
27
|
+
request.delete("/partner/documents/#{document_id}/tags/#{id}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Veryfi
|
4
|
+
module Api
|
5
|
+
class LineItem
|
6
|
+
attr_reader :request
|
7
|
+
|
8
|
+
def initialize(request)
|
9
|
+
@request = request
|
10
|
+
end
|
11
|
+
|
12
|
+
def all(document_id, params = {})
|
13
|
+
response = request.get("/partner/documents/#{document_id}/line-items/", params)
|
14
|
+
|
15
|
+
response["line_items"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(document_id, params)
|
19
|
+
request.post("/partner/documents/#{document_id}/line-items/", params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(document_id, id, params = {})
|
23
|
+
request.get("/partner/documents/#{document_id}/line-items/#{id}", params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update(document_id, id, params)
|
27
|
+
request.put("/partner/documents/#{document_id}/line-items/#{id}", params)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(document_id, id)
|
31
|
+
request.delete("/partner/documents/#{document_id}/line-items/#{id}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Veryfi
|
4
|
+
module Api
|
5
|
+
class Tag
|
6
|
+
attr_reader :request
|
7
|
+
|
8
|
+
def initialize(request)
|
9
|
+
@request = request
|
10
|
+
end
|
11
|
+
|
12
|
+
def all(params = {})
|
13
|
+
response = request.get("/partner/tags/", params)
|
14
|
+
|
15
|
+
response["tags"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(id)
|
19
|
+
request.delete("/partner/tags/#{id}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|