Class: PdfServices::Ocr::External

Inherits:
Operation show all
Defined in:
lib/pdfservices/operations/ocr/external.rb

Constant Summary collapse

EXTERNAL_OPTIONS =
%i[input output params download_from_external].freeze
INPUT_KEYS =
%i[uri storage].freeze
OUTPUT_KEYS =
%i[uri storage].freeze
PARAMS_KEYS =
%i[ocr_lang ocr_type].freeze
STORAGE_OPTIONS =
%i[S3 SHAREPOINT DROPBOX BLOB].freeze

Constants inherited from Operation

Operation::OCR_LANGS, Operation::OCR_TYPES, Operation::OPERATION_ENDPOINT

Constants inherited from Base::Operation

Base::Operation::ASSETS_ENDPOINT, Base::Operation::BASE_ENDPOINT, Base::Operation::STATUS

Instance Method Summary collapse

Methods inherited from Base::Operation

#handle_response, #poll_document_result, #upload_asset

Constructor Details

#initialize(api) ⇒ External

Returns a new instance of External.



12
13
14
15
16
# File 'lib/pdfservices/operations/ocr/external.rb', line 12

def initialize(api)
  super
  @download_from_external = false
  @download_uri = nil
end

Instance Method Details

#execute(url, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pdfservices/operations/ocr/external.rb', line 18

def execute(url, options = {})
  @download_from_external = options[:download_from_external] || false
  options[:input][:uri] = options[:input][:uri] || url
  validate_options(options)

  @download_uri = options[:output][:uri] if @download_from_external

  response = @api.post(OPERATION_ENDPOINT,
                       body: request_body(asset.id, options),
                       headers: request_headers)
  handle_response(response, asset.id)
end