Class: Veryfi::Api::Document
- Inherits:
-
Object
- Object
- Veryfi::Api::Document
- Defined in:
- lib/veryfi/api/document.rb
Overview
Receipts & invoices endpoints (/partner/documents/).
Constant Summary collapse
- CATEGORIES =
Default categories sent with
process/process_urlwhen the caller does not supply their own:categorieslist. Veryfi will bucket the document into one of these values for thecategoryfield on the response. [ "Advertising & Marketing", "Automotive", "Bank Charges & Fees", "Legal & Professional Services", "Insurance", "Meals & Entertainment", "Office Supplies & Software", "Taxes & Licenses", "Travel", "Rent & Lease", "Repairs & Maintenance", "Payroll", "Utilities", "Job Supplies", "Grocery" ].freeze
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#all(params = {}) ⇒ Veryfi::Resource
List previously processed documents.
-
#delete(id) ⇒ Veryfi::Resource
Delete a document.
-
#get(id, params = {}) ⇒ Veryfi::Resource
Fetch a single document by id.
-
#initialize(request) ⇒ Document
constructor
A new instance of Document.
-
#process(raw_params) ⇒ Veryfi::Resource
Upload a local file and extract its data.
-
#process_bulk(file_urls) ⇒ Veryfi::Resource
Bulk-process many documents from URLs in a single call.
-
#process_url(raw_params) ⇒ Veryfi::Resource
Process a document from a public URL.
-
#update(id, params) ⇒ Veryfi::Resource
Update writable fields on a previously processed document.
Constructor Details
#initialize(request) ⇒ Document
Returns a new instance of Document.
35 36 37 |
# File 'lib/veryfi/api/document.rb', line 35 def initialize(request) @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
33 34 35 |
# File 'lib/veryfi/api/document.rb', line 33 def request @request end |
Instance Method Details
#all(params = {}) ⇒ Veryfi::Resource
List previously processed documents.
55 56 57 |
# File 'lib/veryfi/api/document.rb', line 55 def all(params = {}) request.get("/partner/documents/", params) end |
#delete(id) ⇒ Veryfi::Resource
Delete a document.
182 183 184 |
# File 'lib/veryfi/api/document.rb', line 182 def delete(id) request.delete("/partner/documents/#{id}") end |
#get(id, params = {}) ⇒ Veryfi::Resource
Fetch a single document by id.
158 159 160 |
# File 'lib/veryfi/api/document.rb', line 158 def get(id, params = {}) request.get("/partner/documents/#{id}", params) end |
#process(raw_params) ⇒ Veryfi::Resource
Upload a local file and extract its data.
Required:
:file_path— path on disk to the file to process.
All other keys below are optional. Omitting a key is equivalent to passing its default value — both produce the same API call. Pass a key explicitly only when you want a non-default value or when you want to make the intent explicit in your code.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/veryfi/api/document.rb', line 96 def process(raw_params) params = setup_create_params(raw_params) file_content = File.read(params[:file_path]) file_data = Base64.encode64(file_content).gsub("\n", "") file_name = params[:file_name] || File.basename(params[:file_path], ".*") payload = params.reject { |k| k == :file_path }.merge( file_name: file_name, file_data: file_data ) request.post("/partner/documents/", payload) end |
#process_bulk(file_urls) ⇒ Veryfi::Resource
This endpoint must be enabled for your account. Contact support@veryfi.com.
Bulk-process many documents from URLs in a single call.
144 145 146 |
# File 'lib/veryfi/api/document.rb', line 144 def process_bulk(file_urls) request.post("/partner/documents/bulk/", file_urls: file_urls) end |
#process_url(raw_params) ⇒ Veryfi::Resource
Process a document from a public URL.
Either :file_url (single) or :file_urls (multiple, processed as
one logical document) must be present. All other params behave the
same as in #process.
131 132 133 134 135 |
# File 'lib/veryfi/api/document.rb', line 131 def process_url(raw_params) params = setup_create_params(raw_params) request.post("/partner/documents/", params) end |
#update(id, params) ⇒ Veryfi::Resource
Update writable fields on a previously processed document.
172 173 174 |
# File 'lib/veryfi/api/document.rb', line 172 def update(id, params) request.put("/partner/documents/#{id}", params) end |