Class: Tabscanner::Request
- Inherits:
-
Object
- Object
- Tabscanner::Request
- Defined in:
- lib/tabscanner/request.rb
Overview
Handles HTTP requests to the Tabscanner API
This class manages multipart form data uploads for image processing and handles all HTTP communication with proper error handling.
Class Method Summary collapse
-
.submit_receipt(file_path_or_io) ⇒ String
Submit a receipt image for processing.
Class Method Details
.submit_receipt(file_path_or_io) ⇒ String
Submit a receipt image for processing
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tabscanner/request.rb', line 29 def self.submit_receipt(file_path_or_io) config = Tabscanner.config config.validate! # Handle file input - convert file path to IO if needed file_io, filename = normalize_file_input(file_path_or_io) # Build the connection conn = build_connection(config) # Make the request response = conn.post('/api/2/process') do |req| req.body = build_multipart_body(file_io, filename) end # Debug logging for request/response log_request_response('POST', '/api/2/process', response, config) if config.debug? handle_response(response) ensure # Close file if we opened it file_io&.close if file_path_or_io.is_a?(String) && file_io end |