Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 15 additions & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
root = true

# All files
[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[*.{rb,rake,gemspec,rbs,ru}]
indent_style = space
# Config files
[*.{yml,yaml,toml}]
indent_size = 2

[*.{yml,yaml,json,toml}]
indent_style = space
# JSON files
[*.json]
indent_size = 2

# Markdown files
[*.{md,markdown}]
trim_trailing_whitespace = false

[*.{rb,rake,gemspec,rbs,ru}]
indent_size = 2

[*.sh]
indent_style = space
indent_size = 2

[Makefile]
Expand Down
65 changes: 25 additions & 40 deletions lib/mindee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,14 @@ module Dependencies
module Error
end

# Custom extraction module
module Extraction
# Custom geometry module
module Geometry
end

# Mindee internal http module.
module HTTP
end

# PDF-specific operations.
module PDF
end

# Document handling.
module Input
# Document source handling.
module Source
end
end

module Image
# Miscellaneous image operations.
module ImageUtils
Expand All @@ -43,35 +32,27 @@ module ImageCompressor
end
end

# Logging
module Logging
end

# Document input-related internals.
# Document handling.
module Input
end

# Collection of all internal products.
module Product
# Europe-specific products.
module EU
end

# France-specific products.
module FR
# Document source handling.
module Source
end
end

# Indian-specific products.
module IND
end
# Logging
module Logging
end

# US-specific products.
module US
end
# PDF-specific operations.
module PDF
end

# V1-specific module.
module V1
# Custom extraction for V1.
module Extraction
end

# HTTP module for V1.
module HTTP
end
Expand Down Expand Up @@ -101,10 +82,6 @@ module FR

# V2-specific module.
module V2
# Mindee internal http module.
module HTTP
end

# File operations.
module FileOperation
# Crop operations.
Expand All @@ -116,8 +93,8 @@ module Split
end
end

# Product-specific module.
module Product
# HTTP module for V2.
module HTTP
end

# V2 parsing module.
Expand All @@ -126,6 +103,14 @@ module Parsing
module Search
end
end

# Product-specific module.
module Product
end

# V2 search module.
module Search
end
end
end

Expand Down
32 changes: 32 additions & 0 deletions lib/mindee/input/polling_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@ def initialize(initial_delay_sec: 2.0, delay_sec: 1.5, max_retries: 80)
@initial_delay_sec = initial_delay_sec
@delay_sec = delay_sec
@max_retries = max_retries
validate_settings
end

# Loads from a Hash.
def self.from_hash(polling_options: {})
polling_options = polling_options
.transform_keys(&:to_sym)
.slice(:initial_delay_sec, :delay_sec, :max_retries)
.compact
new(**polling_options)
end

private

# Validates the parameters for async auto-polling
def validate_settings
min_delay_sec = 1
min_initial_delay_sec = 1
min_retries = 2

if @delay_sec < min_delay_sec
raise ArgumentError,
"Cannot set auto-poll delay to less than #{min_delay_sec} second(s)"
end
if @initial_delay_sec < min_initial_delay_sec
raise ArgumentError,
"Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)"
end
return unless @max_retries < min_retries

raise ArgumentError,
"Cannot set auto-poll retries to less than #{min_retries}"
end
end
end
Expand Down
31 changes: 26 additions & 5 deletions lib/mindee/v1/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ def initialize(api_key: '')
# * `:max_retries` [Integer] Maximum number of retries. Defaults to 80.
# @param enqueue [bool] Whether to enqueue the file.
# @return [Mindee::V1::Parsing::Common::ApiResponse]
def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true)
def parse(
input_source,
product_class,
endpoint: nil,
options: {},
enqueue: true
)
opts = normalize_parse_options(options)
process_pdf_if_required(input_source, opts) if input_source.is_a?(Input::Source::LocalInputSource)
endpoint ||= initialize_endpoint(product_class)
Expand Down Expand Up @@ -122,7 +128,12 @@ def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true
# * `:cropper` [bool, nil] Whether to include cropper results for each page.
# This performs a cropping operation on the server and will increase response time.
# @return [Mindee::V1::Parsing::Common::ApiResponse]
def parse_sync(input_source, product_class, endpoint, options)
def parse_sync(
input_source,
product_class,
endpoint,
options
)
logger.debug("Parsing document as '#{endpoint.url_root}'")

prediction, raw_http = endpoint.predict(
Expand Down Expand Up @@ -159,7 +170,12 @@ def parse_sync(input_source, product_class, endpoint, options)
# * `:workflow_id` [String, nil] ID of the workflow to use.
# @param endpoint [Mindee::V1::HTTP::Endpoint] Endpoint of the API.
# @return [Mindee::V1::Parsing::Common::ApiResponse]
def enqueue(input_source, product_class, endpoint: nil, options: {})
def enqueue(
input_source,
product_class,
endpoint: nil,
options: {}
)
opts = normalize_parse_options(options)
endpoint ||= initialize_endpoint(product_class)
logger.debug("Enqueueing document as '#{endpoint.url_root}'")
Expand Down Expand Up @@ -369,7 +385,12 @@ def validate_async_params(initial_delay_sec, delay_sec, max_retries)
# standard (off the shelf) endpoint.
# @param version [String] For custom endpoints, version of the product.
# @return [Mindee::V1::HTTP::Endpoint]
def initialize_endpoint(product_class, endpoint_name: '', account_name: '', version: '')
def initialize_endpoint(
product_class,
endpoint_name: '',
account_name: '',
version: ''
)
if (endpoint_name.nil? || endpoint_name.empty?) && product_class == Mindee::V1::Product::Universal::Universal
raise Mindee::Error::MindeeConfigurationError, 'Missing argument endpoint_name when using custom class'
end
Expand Down Expand Up @@ -421,7 +442,7 @@ def process_pdf_if_required(input_source, opts)
opts.page_options.on_min_pages &&
input_source.pdf?

input_source.process_pdf(opts.page_options)
input_source.apply_page_options(opts.page_options)
end

private :parse_sync, :validate_async_params, :initialize_endpoint, :fix_endpoint_name, :fix_version,
Expand Down
Loading
Loading