Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/_test-units.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ jobs:

- name: Install Ghostscript and ImageMagick on macOS
if: runner.os == 'macOS'
run: brew install ghostscript imagemagick
run: |
brew install ghostscript imagemagick
/usr/bin/security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain
- name: Change ImageMagick security policy on Ubuntu
if: runner.os == 'Linux'
run: |
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ end
desc 'Run integration tests'
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = 'spec/**/*_integration.rb'
t.rspec_opts = ['--require', 'integration_helper']
end

Rake::Task[:doc].enhance do
Expand Down
1 change: 1 addition & 0 deletions lib/mindee/http/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require_relative 'response_validation'

module Mindee
# Mindee internal HTTP module.
module HTTP
# API key's default environment key name.
API_KEY_ENV_NAME = 'MINDEE_API_KEY'
Expand Down
1 change: 1 addition & 0 deletions mindee.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'origamindee', '~> 4.0'
spec.add_dependency 'pdf-reader', '~> 2.14'

spec.add_development_dependency 'openssl', '~> 3.3.2'
spec.add_development_dependency 'prism', '~> 1.3'
spec.add_development_dependency 'rake', '~> 13.2'
spec.add_development_dependency 'rbs', '~> 3.6'
Expand Down
1 change: 1 addition & 0 deletions sig/mindee/http/endpoint.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Mindee
def document_queue_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> Net::HTTPResponse
def document_queue_req_get: (String) -> Net::HTTPResponse
def check_api_key: -> void
def configure_ssl: (Net::HTTP) -> void
end
end
end
2 changes: 1 addition & 1 deletion spec/data
Submodule data updated 325 files
8 changes: 7 additions & 1 deletion spec/data.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# frozen_string_literal: true

DATA_DIR = File.join(__dir__, 'data').freeze
ROOT_DATA_DIR = File.join(__dir__, 'data').freeze
FILE_TYPES_DIR = File.join(ROOT_DATA_DIR, 'file_types').freeze
V1_DATA_DIR = File.join(ROOT_DATA_DIR, 'v1').freeze
V2_DATA_DIR = File.join(ROOT_DATA_DIR, 'v2').freeze
V1_ASYNC_DIR = File.join(V1_DATA_DIR, 'async').freeze
V1_PRODUCT_DATA_DIR = File.join(V1_DATA_DIR, 'products').freeze
V1_OCR_DIR = File.join(V1_DATA_DIR, 'extras', 'ocr')

def load_json(dir_path, file_name)
file_data = File.read(File.join(dir_path, file_name))
Expand Down
5 changes: 0 additions & 5 deletions spec/extras/extras_utils.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/image/extracted_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

describe Mindee::Image::ExtractedImage do
let(:file_path) do
File.join(DATA_DIR, 'products', 'invoices', 'default_sample.jpg')
File.join(V1_DATA_DIR, 'products', 'invoices', 'default_sample.jpg')
end
let(:input_source) do
Mindee::Input::Source::PathInputSource.new(file_path)
end
let(:page_id) { 1 }
let(:element_id) { 42 }
let(:output_dir) { "#{DATA_DIR}/output" }
let(:output_dir) { "#{ROOT_DATA_DIR}/output" }

describe '#initialize' do
it 'initializes with correct attributes' do
Expand Down
4 changes: 2 additions & 2 deletions spec/image/image_compressor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

describe Mindee::Image::ImageCompressor do
describe 'Image Quality Compression' do
let(:input_receipt_path) { "#{DATA_DIR}/file_types/receipt.jpg" }
let(:output_dir) { "#{DATA_DIR}/output/" }
let(:input_receipt_path) { "#{FILE_TYPES_DIR}/receipt.jpg" }
let(:output_dir) { "#{ROOT_DATA_DIR}/output/" }

it 'should compress the image from input source' do
receipt_input = Mindee::Input::Source::PathInputSource.new(input_receipt_path)
Expand Down
4 changes: 2 additions & 2 deletions spec/image/image_extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
describe Mindee::Image do
include Mindee::Image
let(:barcode_path) do
File.join(DATA_DIR, 'products', 'barcode_reader', 'default_sample.jpg')
File.join(V1_DATA_DIR, 'products', 'barcode_reader', 'default_sample.jpg')
end

let(:barcode_json_path) do
File.join(DATA_DIR, 'products', 'barcode_reader', 'response_v1', 'complete.json')
File.join(V1_DATA_DIR, 'products', 'barcode_reader', 'response_v1', 'complete.json')
end

context 'an image extractor' do
Expand Down
2 changes: 1 addition & 1 deletion spec/image/image_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'mindee'

describe Mindee::Image::ImageUtils do
let(:sample_image_path) { "#{DATA_DIR}/file_types/receipt.jpg" }
let(:sample_image_path) { "#{FILE_TYPES_DIR}/receipt.jpg" }
let(:sample_image) { MiniMagick::Image.open(sample_image_path) }

describe 'Image utility module' do
Expand Down
16 changes: 8 additions & 8 deletions spec/input/sources/files_handling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
describe Mindee::Input::Source::LocalInputSource do
context 'An jpg input file' do
it 'should be readable as raw bytes' do
file = File.join(DATA_DIR, 'file_types/receipt.jpg')
file = File.join(FILE_TYPES_DIR, 'receipt.jpg')
input = Mindee::Input::Source::PathInputSource.new(file)
read_f = input.read_contents
expect(read_f.length).to eq(2)
Expand All @@ -17,7 +17,7 @@

context 'A jpga input file' do
it 'should be readable as raw bytes' do
file = File.join(DATA_DIR, 'file_types/receipt.jpga')
file = File.join(FILE_TYPES_DIR, 'receipt.jpga')
input = Mindee::Input::Source::PathInputSource.new(file)
read_f = input.read_contents
expect(read_f.length).to eq(2)
Expand All @@ -27,7 +27,7 @@

context 'A heic input file' do
it 'should be readable as raw bytes' do
file = File.join(DATA_DIR, 'file_types/receipt.heic')
file = File.join(FILE_TYPES_DIR, 'receipt.heic')
input = Mindee::Input::Source::PathInputSource.new(file)
read_f = input.read_contents
expect(read_f.length).to eq(2)
Expand All @@ -37,7 +37,7 @@

context 'A tif input file' do
it 'should be readable as raw bytes' do
file = File.join(DATA_DIR, 'file_types/receipt.tif')
file = File.join(FILE_TYPES_DIR, 'receipt.tif')
input = Mindee::Input::Source::PathInputSource.new(file)
read_f = input.read_contents
expect(read_f.length).to eq(2)
Expand All @@ -47,7 +47,7 @@

context 'A tiff input file' do
it 'should be readable as raw bytes' do
file = File.join(DATA_DIR, 'file_types/receipt.tiff')
file = File.join(FILE_TYPES_DIR, 'receipt.tiff')
input = Mindee::Input::Source::PathInputSource.new(file)
read_f = input.read_contents
expect(read_f.length).to eq(2)
Expand All @@ -57,7 +57,7 @@

context 'A txt input file' do
it 'should stay in base64' do
file = File.join(DATA_DIR, 'file_types/receipt.txt')
file = File.join(FILE_TYPES_DIR, 'receipt.txt')
input = Mindee::Input::Source::Base64InputSource.new(File.read(file), 'receipt.txt')
read_f = input.read_contents
expect(read_f.length).to eq(2)
Expand All @@ -67,7 +67,7 @@

context 'A standard pdf input file' do
it 'should not be converted' do
file = File.join(DATA_DIR, 'file_types/pdf/not_blank_image_only.pdf')
file = File.join(FILE_TYPES_DIR, 'pdf/not_blank_image_only.pdf')
input = Mindee::Input::Source::PathInputSource.new(file)
read_f = input.read_contents
file_contents = File.read(file)
Expand All @@ -79,7 +79,7 @@

context 'A valid written pdf input file' do
it 'should not be converted' do
file = File.join(DATA_DIR, 'file_types/pdf/valid_exported.pdf')
file = File.join(FILE_TYPES_DIR, 'pdf/valid_exported.pdf')
input = Mindee::Input::Source::PathInputSource.new(file)
read_f = input.read_contents
file_contents = File.read(file)
Expand Down
4 changes: 2 additions & 2 deletions spec/input/sources/local_input_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require 'mindee'

describe Mindee::Input::Source::PathInputSource do
let(:input_file) { "#{DATA_DIR}/products/invoices/default_sample.jpg" }
let(:output_dir) { "#{DATA_DIR}/output/" }
let(:input_file) { "#{V1_DATA_DIR}/products/invoices/default_sample.jpg" }
let(:output_dir) { "#{ROOT_DATA_DIR}/output/" }

describe '#write_to_file' do
let(:local_input_source) { described_class.new(input_file) }
Expand Down
24 changes: 12 additions & 12 deletions spec/input/sources/sources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
context 'An image input file' do
it 'should load a JPEG from a path' do
input_source = Mindee::Input::Source::PathInputSource.new(
File.join(DATA_DIR, 'file_types/receipt.jpg')
File.join(FILE_TYPES_DIR, 'receipt.jpg')
)
expect(input_source.file_mimetype).to eq('image/jpeg')
expect(input_source.filename).to eq('receipt.jpg')
expect(input_source.page_count).to eq(1)
expect(input_source.pdf?).to eq(false)

input_source = Mindee::Input::Source::PathInputSource.new(
File.join(DATA_DIR, 'file_types/receipt.jpga')
File.join(FILE_TYPES_DIR, 'receipt.jpga')
)
expect(input_source.file_mimetype).to eq('image/jpeg')
expect(input_source.filename).to eq('receipt.jpga')
Expand All @@ -29,15 +29,15 @@

it 'should load a TIFF from a path' do
input_source = Mindee::Input::Source::PathInputSource.new(
File.join(DATA_DIR, 'file_types/receipt.tif')
File.join(FILE_TYPES_DIR, 'receipt.tif')
)
expect(input_source.file_mimetype).to eq('image/tiff')
expect(input_source.filename).to eq('receipt.tif')
expect(input_source.page_count).to eq(1)
expect(input_source.pdf?).to eq(false)

input_source = Mindee::Input::Source::PathInputSource.new(
File.join(DATA_DIR, 'file_types/receipt.tiff')
File.join(FILE_TYPES_DIR, 'receipt.tiff')
)
expect(input_source.file_mimetype).to eq('image/tiff')
expect(input_source.filename).to eq('receipt.tiff')
Expand All @@ -47,7 +47,7 @@

it 'should load a HEIC from a path' do
input_source = Mindee::Input::Source::PathInputSource.new(
File.join(DATA_DIR, 'file_types/receipt.heic')
File.join(FILE_TYPES_DIR, 'receipt.heic')
)
expect(input_source.file_mimetype).to eq('image/heic')
expect(input_source.filename).to eq('receipt.heic')
Expand All @@ -59,23 +59,23 @@
context 'A PDF input file' do
it 'should load a multi-page PDF from a path' do
input_source = Mindee::Input::Source::PathInputSource.new(
File.join(DATA_DIR, 'products/invoices/invoice.pdf')
File.join(V1_DATA_DIR, 'products/invoices/invoice.pdf')
)
expect(input_source.file_mimetype).to eq('application/pdf')
expect(input_source.filename).to eq('invoice.pdf')
expect(input_source.page_count).to eq(2)
expect(input_source.pdf?).to eq(true)

input_source = Mindee::Input::Source::PathInputSource.new(
File.join(DATA_DIR, 'products/invoices/invoice.pdf')
File.join(V1_DATA_DIR, 'products/invoices/invoice.pdf')
)
expect(input_source.file_mimetype).to eq('application/pdf')
expect(input_source.filename).to eq('invoice.pdf')
expect(input_source.page_count).to eq(2)
expect(input_source.pdf?).to eq(true)

input_source = Mindee::Input::Source::PathInputSource.new(
File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf')
File.join(V1_DATA_DIR, 'products/invoices/invoice_10p.pdf')
)
expect(input_source.file_mimetype).to eq('application/pdf')
expect(input_source.filename).to eq('invoice_10p.pdf')
Expand All @@ -89,7 +89,7 @@
it 'Should not raise a mime error' do
expect do
mindee_client.source_from_path(
"#{DATA_DIR}/file_types/pdf/broken_fixable.pdf", repair_pdf: true
"#{FILE_TYPES_DIR}/pdf/broken_fixable.pdf", repair_pdf: true
)
end.not_to raise_error
end
Expand All @@ -100,7 +100,7 @@
it 'Should raise an error' do
expect do
mindee_client.source_from_path(
"#{DATA_DIR}/file_types/pdf/broken_unfixable.pdf", repair_pdf: true
"#{FILE_TYPES_DIR}/pdf/broken_unfixable.pdf", repair_pdf: true
)
end.to raise_error Mindee::Errors::MindeePDFError
end
Expand All @@ -109,9 +109,9 @@
context 'A broken fixable invoice PDF' do
mindee_client = Mindee::Client.new(api_key: 'invalid-api-key')
it 'Should send correct results' do
source_doc_original = mindee_client.source_from_path("#{DATA_DIR}/products/invoices/invoice.pdf")
source_doc_original = mindee_client.source_from_path("#{V1_DATA_DIR}/products/invoices/invoice.pdf")
expect do
source_doc_fixed = mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_invoice.pdf",
source_doc_fixed = mindee_client.source_from_path("#{FILE_TYPES_DIR}/pdf/broken_invoice.pdf",
repair_pdf: true)
expect(source_doc_fixed.read_contents[0].to_s).to eq(source_doc_original.read_contents[0].to_s)
end.not_to raise_error
Expand Down
2 changes: 1 addition & 1 deletion spec/input/sources/url_input_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:valid_url) { 'https://validurl/some/file.jpg' }
let(:valid_url_no_filename) { 'https://validurl/some/' }
let(:invalid_url) { 'http://invalidurl/some/file.jpg' }
let(:output_dir) { "#{DATA_DIR}/output/" }
let(:output_dir) { "#{ROOT_DATA_DIR}/output/" }

describe '#initialize' do
context 'with valid URL' do
Expand Down
3 changes: 3 additions & 0 deletions spec/integration_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative 'openssl_crl_workaround'
12 changes: 12 additions & 0 deletions spec/openssl_crl_workaround.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require 'openssl'

params = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS

params[:verify_mode] = OpenSSL::SSL::VERIFY_PEER

if params[:verify_flags]
params[:verify_flags] &=
~(OpenSSL::X509::V_FLAG_CRL_CHECK_ALL | OpenSSL::X509::V_FLAG_CRL_CHECK)
end
8 changes: 3 additions & 5 deletions spec/pdf/extracted_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
require 'mindee'

describe Mindee::PDF::PDFExtractor::ExtractedPDF do
let(:product_data_dir) { File.join(DATA_DIR, 'products') }
let(:output_dir) { File.join(DATA_DIR, 'output') }
let(:file_types_dir) { File.join(DATA_DIR, 'file_types') }
let(:valid_pdf_path) { "#{product_data_dir}/invoices/invoice.pdf" }
let(:invalid_pdf_path) { "#{file_types_dir}/receipt.txt" }
let(:output_dir) { File.join(V1_DATA_DIR, 'output') }
let(:valid_pdf_path) { "#{V1_PRODUCT_DATA_DIR}/invoices/invoice.pdf" }
let(:invalid_pdf_path) { "#{FILE_TYPES_DIR}/receipt.txt" }
let(:output_path) { "#{output_dir}/sample_output.pdf" }

before do
Expand Down
Loading