class Mindee::HTTP::Endpoint

def predict_req_post(input_source, all_words: false, full_text: false, close_file: true, cropper: false)

Returns:
  • (Net::HTTPResponse, nil) -

Parameters:
  • cropper (Boolean) -- Whether a cropping operation will be applied
  • close_file (Boolean) -- Whether the file will be closed after reading
  • full_text (Boolean) -- Whether to include the full OCR text response in compatible APIs.
  • all_words (Boolean) -- Whether the full word extraction needs to be performed
  • input_source (Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource) --
def predict_req_post(input_source, all_words: false, full_text: false, close_file: true, cropper: false)
  uri = URI("#{@url_root}/predict")
  params = {}
  params[:cropper] = 'true' if cropper
  params[:full_text_ocr] = 'true' if full_text
  uri.query = URI.encode_www_form(params)
  headers = {
    'Authorization' => "Token #{@api_key}",
    'User-Agent' => USER_AGENT,
  }
  req = Net::HTTP::Post.new(uri, headers)
  form_data = if input_source.is_a?(Mindee::Input::Source::UrlInputSource)
                [['document', input_source.url]]
              else
                [input_source.read_document(close: close_file)]
              end
  form_data.push ['include_mvision', 'true'] if all_words
  req.set_form(form_data, 'multipart/form-data')
  response = nil
  Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @request_timeout) do |http|
    response = http.request(req)
  end
  response
end