Class: Payabli::Ocr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/payabli/ocr/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/payabli/ocr/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#ocr_document_form(request_options: {}, **params) ⇒ Payabli::Ocr::Types::PayabliApiResponseOcr

Use this endpoint to upload an image file for OCR processing. The accepted file formats include PDF, JPG, JPEG, PNG, and GIF. Specify the desired type of result (either ‘bill’ or ‘invoice’) in the path parameter ‘typeResult`. The response will contain the OCR processing results, including extracted data such as bill number, vendor information, bill items, and more.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/payabli/ocr/client.rb', line 28

def ocr_document_form(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "/Import/ocrDocumentForm/#{URI.encode_uri_component(params[:type_result].to_s)}",
    body: Payabli::Ocr::Types::FileContentImageOnly.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Ocr::Types::PayabliApiResponseOcr.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#ocr_document_json(request_options: {}, **params) ⇒ Payabli::Ocr::Types::PayabliApiResponseOcr

Use this endpoint to submit a Base64-encoded image file for OCR processing. The accepted file formats include PDF, JPG, JPEG, PNG, and GIF. Specify the desired type of result (either ‘bill’ or ‘invoice’) in the path parameter ‘typeResult`. The response will contain the OCR processing results, including extracted data such as bill number, vendor information, bill items, and more.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/payabli/ocr/client.rb', line 66

def ocr_document_json(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "/Import/ocrDocumentJson/#{URI.encode_uri_component(params[:type_result].to_s)}",
    body: Payabli::Ocr::Types::FileContentImageOnly.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Ocr::Types::PayabliApiResponseOcr.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end