Coder Social home page Coder Social logo

veryfi-ruby's Introduction

Veryfi SDK for Ruby

Version Test Coverage

veryfi-ruby is a Ruby gem for communicating with the Veryfi OCR API

Documentation

Table of Contents

Example

Below is a sample script using Veryfi for OCR and extracting data from a document:

require 'veryfi'

veryfi_client = Veryfi::Client.new(
  client_id: 'your_client_id',
  client_secret: 'your_client_secret',
  username: 'your_username',
  api_key: 'your_password'
)

This submits a document for processing (3-5 seconds for a response)

params = {
  file_path: './test/receipt.jpg',
  auto_delete: true,
  boost_mode: false,
  async: false,
  external_id: '123456789',
  max_pages_to_process: 10,
  tags: ['tag1'],
  categories: [
    'Advertising & Marketing',
    'Automotive'
  ]
}

response = veryfi_client.document.process(params)

puts response

...or with a URL

params = {
  file_url: 'https://raw.githubusercontent.com/veryfi/veryfi-python/master/tests/assets/receipt_public.jpg',
  auto_delete: true,
  boost_mode: false,
  async: false,
  external_id: '123456789',
  max_pages_to_process: 10,
  tags: ['tag1'],
  categories: [
    'Advertising & Marketing',
    'Automotive'
  ]
}

response = veryfi_client.document.process_url(params)

puts response

This will produce the following response:

{
  "abn_number": "",
  "account_number": "",
  "bill_to_address": "2 Court Square\nNew York, NY 12210",
  "bill_to_name": "John Smith",
  "bill_to_vat_number": "",
  "card_number": "",
  "cashback": 0,
  "category": "Repairs & Maintenance",
  "created": "2021-06-28 19:20:02",
  "currency_code": "USD",
  "date": "2019-02-11 00:00:00",
  "delivery_date": "",
  "discount": 0,
  "document_reference_number": "",
  "document_title": "",
  "document_type": "invoice",
  "due_date": "2019-02-26",
  "duplicate_of": 37055375,
  "external_id": "",
  "id": 37187909,
  "img_file_name": "receipt.png",
  "img_thumbnail_url": "https://scdn.veryfi.com/receipts/thumbnail.png",
  "img_url": "https://scdn.veryfi.com/receipts/receipt.png",
  "insurance": "",
  "invoice_number": "US-001",
  "is_duplicate": 1,
  "line_items": [
    {
      "date": "",
      "description": "Front and rear brake cables",
      "discount": 0,
      "id": 68004313,
      "order": 0,
      "price": 100,
      "quantity": 1,
      "reference": "",
      "section": "",
      "sku": "",
      "tax": 0,
      "tax_rate": 0,
      "total": 100,
      "type": "product",
      "unit_of_measure": ""
    },
    {
      "date": "",
      "description": "New set of pedal arms",
      "discount": 0,
      "id": 68004315,
      "order": 1,
      "price": 15,
      "quantity": 2,
      "reference": "",
      "section": "",
      "sku": "",
      "tax": 0,
      "tax_rate": 0,
      "total": 30,
      "type": "product",
      "unit_of_measure": ""
    },
    {
      "date": "",
      "description": "Labor 3hrs",
      "discount": 0,
      "id": 68004316,
      "order": 2,
      "price": 5,
      "quantity": 3,
      "reference": "",
      "section": "",
      "sku": "",
      "tax": 0,
      "tax_rate": 0,
      "total": 15,
      "type": "service",
      "unit_of_measure": ""
    }
  ],
  "notes": "",
  "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",
  "order_date": "",
  "payment_display_name": "",
  "payment_terms": "15 days",
  "payment_type": "",
  "phone_number": "",
  "purchase_order_number": "2312/2019",
  "rounding": 0,
  "service_end_date": "",
  "service_start_date": "",
  "ship_date": "",
  "ship_to_address": "3787 Pineview Drive\nCambridge, MA 12210",
  "ship_to_name": "John Smith",
  "shipping": 0,
  "store_number": "",
  "subtotal": 145,
  "tax": 9.06,
  "tax_lines": [
    {
      "base": 0,
      "name": "Sales",
      "order": 0,
      "rate": 6.25,
      "total": 9.06
    }
  ],
  "tip": 0,
  "total": 154.06,
  "total_weight": "",
  "tracking_number": "",
  "updated": "2021-06-28 19:20:03",
  "vat_number": "",
  "vendor": {
    "address": "1912 Harvest Lane\nNew York, NY 12210",
    "category": "Car Repair",
    "email": "",
    "fax_number": "",
    "name": "East Repair",
    "phone_number": "",
    "raw_name": "East Repair Inc.",
    "vendor_logo": "https://cdn.veryfi.com/logos/tmp/560806841.png",
    "vendor_reg_number": "",
    "vendor_type": "Car Repair",
    "web": ""
  },
  "vendor_account_number": "",
  "vendor_bank_name": "",
  "vendor_bank_number": "",
  "vendor_bank_swift": "",
  "vendor_iban": ""
}

Installation

gem install veryfi

Or add to your Gemfile:

gem 'veryfi', '~> 0.1'

Getting Started

Obtaining Client ID and user keys

If you don't have an account with Veryfi, please go ahead and register here: https://hub.veryfi.com/signup/api/

Ruby API Client Library

The veryfi-ruby gem can be used to communicate with Veryfi API. All available functionality is described in docs

Need help?

If you run into any issue or need help installing or using the library, please contact [email protected].

If you found a bug in this library or would like new features added, then open an issue or pull requests against this repo!

For Developers

Install

bin/setup

Quality tools

  • bin/quality based on RuboCop
  • .rubocop.yml describes active checks

Develop

bin/ci checks your specs and runs quality tools

Release

  1. Change version in lib/veryfi/version.rb
  2. Run bundle - this should update Gemfile.lock
  3. Commit changes, push to a new Github branch, and merge
  4. On Github go to Actions -> Release -> and click Run workflow to trigger a new release
  5. Release workflow will publish gem to Rubygems

veryfi-ruby's People

Contributors

abakonski avatar dbirulia avatar kaevan89 avatar manycoding avatar martinsabo avatar matt-veryfi avatar saboter avatar slavakisel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

veryfi-ruby's Issues

Delete request for documents uploaded via web interface fails

Hello,

we run into weird problem with files which were uploaded to veryfi directly via web interface.
We are able to retrieve them via api request but we are not able to delete them.

Delete request fails with internal server error:

.rvm/gems/ruby-3.1.1/gems/veryfi-0.1.4/lib/veryfi/request.rb:63:in `make_request': Internal Server Error (Veryfi::Error::InternalError)

Delete request for documents uploaded via api works ok.

Is this a known bug or feature?

Thank you.

Version bump

It looks like the release action for 1.0.2 never pushed the update to rubygems. Wondering if someone can take a look and bump the version for the faraday dependency

Thanks

Get BadRequest response with Readme example

Given:

  • Have valid credentials on Veryfi.com and set them on the docker.env file
  • Create VeryfiClient instance with the next code
VeryfiClient = Veryfi::Client.new(
  client_id: ENV.fetch('VERYFI_CLIENT_ID', nil),
  client_secret: ENV.fetch('VERYFI_CLIENT_SECRET', nil),
  username: ENV.fetch('VERYFI_USERNAME', nil),
  api_key: ENV.fetch('VERYFI_API_KEY', nil),
)
  • set request parameters as described on README
params = {
  file_path: 'spec/fixtures/purchase_vendor_bills/vendor_bill.pdf',
  auto_delete: true,
  boost_mode: false,
  async: false,
  external_id: '123456789',
  max_pages_to_process: 10,
  tags: ['tag1'],
  categories: [
    'Advertising & Marketing',
    'Automotive'
  ]
}

Then make a request with the below code
VeryfiClient.document.process(params)

and got an error

Veryfi::Error::BadRequest: Bad Request
from /project_gems/ruby/2.7.0/gems/veryfi-0.1.3/lib/veryfi/request.rb:63:in `make_request'

The same result with only :file_path parameter

params = {
  file_path: 'spec/fixtures/purchase_vendor_bills/vendor_bill.pdf',
}

UPDATE:: Made some investigation.

API responses 400 when "file_name" POST-parameter hasn't extension.
For example,

{
  "file_name": "invoice",
  "file_data": "application/pdf;base64,JVBERi0xLjQKJcfsj6IKJSVJbnZvY......."
}

returns 400

But

{
  "file_name": "invoice.pdf",
  "file_data": "application/pdf;base64,JVBERi0xLjQKJcfsj6IKJSVJbnZvY........"
}

returns 201.

Newly released 1.0.2 gem is not loading properly in rails project

Hi,
it seems that the latest 1.0.2 gem is not working properly:

  • removed gem "veryfi", git: "https://github.com/veryfi/veryfi-ruby.git" from my Gemfile
  • added gem "veryfi", "~> 1.0.2"
  • bundle update veryfi
  • new gem was installed
  • spec started to fail because the veryfi gem was not properly loaded
  • require 'veryfi' in the console fails as well

Same behavior/issue is present in freshly created rails app.

Thanks.

Martin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.