Class: Payabli::Ocr::Client
- Inherits:
-
Object
- Object
- Payabli::Ocr::Client
- Defined in:
- lib/payabli/ocr/client.rb
Instance Method Summary collapse
- #initialize(client:) ⇒ void constructor
-
#ocr_document_form(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseOcr
Use this endpoint to upload an image file for OCR processing.
-
#ocr_document_json(request_options: {}, **params) ⇒ Payabli::Types::PayabliApiResponseOcr
Use this endpoint to submit a Base64-encoded image file for OCR processing.
Constructor Details
#initialize(client:) ⇒ void
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::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.
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: [:base_url], method: "POST", path: "Import/ocrDocumentForm/#{URI.encode_uri_component(params[:type_result].to_s)}", body: Payabli::Types::FileContentImageOnly.new(params).to_h, 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::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::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.
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: [:base_url], method: "POST", path: "Import/ocrDocumentJson/#{URI.encode_uri_component(params[:type_result].to_s)}", body: Payabli::Types::FileContentImageOnly.new(params).to_h, 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::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 |