Class: ReductoAI::Client
- Inherits:
-
Object
- Object
- ReductoAI::Client
- Defined in:
- lib/reducto_ai/client.rb
Overview
HTTP client for the Reducto document intelligence API.
Provides access to all Reducto API endpoints through resource objects. Configure globally via configure or pass parameters directly to the constructor.
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
Reducto API key.
-
#base_url ⇒ String
readonly
Base URL for API requests.
-
#logger ⇒ Logger
readonly
Logger instance for debugging.
-
#open_timeout ⇒ Integer
readonly
Connection open timeout in seconds.
-
#read_timeout ⇒ Integer
readonly
Request read timeout in seconds.
Instance Method Summary collapse
-
#edit ⇒ Resources::Edit
Returns the Edit resource for PDF markup operations.
-
#extract ⇒ Resources::Extract
Returns the Extract resource for structured data extraction.
-
#initialize(api_key: nil, base_url: nil, logger: nil, open_timeout: nil, read_timeout: nil) ⇒ Client
constructor
Creates a new Reducto API client.
-
#jobs ⇒ Resources::Jobs
Returns the Jobs resource for job management operations.
-
#parse ⇒ Resources::Parse
Returns the Parse resource for document parsing operations.
-
#pipeline ⇒ Resources::Pipeline
Returns the Pipeline resource for multi-step workflows.
-
#post(path, body) ⇒ Hash
private
Convenience method for POST requests.
-
#request(method, path, body: nil, params: nil) ⇒ Hash
private
Makes an HTTP request to the Reducto API.
-
#split ⇒ Resources::Split
Returns the Split resource for document splitting operations.
Constructor Details
#initialize(api_key: nil, base_url: nil, logger: nil, open_timeout: nil, read_timeout: nil) ⇒ Client
Creates a new Reducto API client.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/reducto_ai/client.rb', line 69 def initialize(api_key: nil, base_url: nil, logger: nil, open_timeout: nil, read_timeout: nil) configuration = ReductoAI.config @api_key = api_key || configuration.api_key @base_url = base_url || configuration.base_url @logger = logger || configuration.logger @open_timeout = open_timeout || configuration.open_timeout @read_timeout = read_timeout || configuration.read_timeout raise ArgumentError, "Missing API key for ReductoAI" if @api_key.to_s.empty? end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns Reducto API key.
43 44 45 |
# File 'lib/reducto_ai/client.rb', line 43 def api_key @api_key end |
#base_url ⇒ String (readonly)
Returns Base URL for API requests.
46 47 48 |
# File 'lib/reducto_ai/client.rb', line 46 def base_url @base_url end |
#logger ⇒ Logger (readonly)
Returns Logger instance for debugging.
49 50 51 |
# File 'lib/reducto_ai/client.rb', line 49 def logger @logger end |
#open_timeout ⇒ Integer (readonly)
Returns Connection open timeout in seconds.
52 53 54 |
# File 'lib/reducto_ai/client.rb', line 52 def open_timeout @open_timeout end |
#read_timeout ⇒ Integer (readonly)
Returns Request read timeout in seconds.
55 56 57 |
# File 'lib/reducto_ai/client.rb', line 55 def read_timeout @read_timeout end |
Instance Method Details
#edit ⇒ Resources::Edit
Returns the Edit resource for PDF markup operations.
109 110 111 |
# File 'lib/reducto_ai/client.rb', line 109 def edit @edit ||= Resources::Edit.new(self) end |
#extract ⇒ Resources::Extract
Returns the Extract resource for structured data extraction.
93 94 95 |
# File 'lib/reducto_ai/client.rb', line 93 def extract @extract ||= Resources::Extract.new(self) end |
#jobs ⇒ Resources::Jobs
Returns the Jobs resource for job management operations.
125 126 127 |
# File 'lib/reducto_ai/client.rb', line 125 def jobs @jobs ||= Resources::Jobs.new(self) end |
#parse ⇒ Resources::Parse
Returns the Parse resource for document parsing operations.
85 86 87 |
# File 'lib/reducto_ai/client.rb', line 85 def parse @parse ||= Resources::Parse.new(self) end |
#pipeline ⇒ Resources::Pipeline
Returns the Pipeline resource for multi-step workflows.
117 118 119 |
# File 'lib/reducto_ai/client.rb', line 117 def pipeline @pipeline ||= Resources::Pipeline.new(self) end |
#post(path, body) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convenience method for POST requests.
158 159 160 |
# File 'lib/reducto_ai/client.rb', line 158 def post(path, body) request(:post, path, body: body) end |
#request(method, path, body: nil, params: nil) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes an HTTP request to the Reducto API.
143 144 145 146 147 148 149 |
# File 'lib/reducto_ai/client.rb', line 143 def request(method, path, body: nil, params: nil) response = execute_request(method, path, body: body, params: params) log_response(method, path, response) handle_response(response) rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e raise NetworkError, "Network error: #{e.}" end |
#split ⇒ Resources::Split
Returns the Split resource for document splitting operations.
101 102 103 |
# File 'lib/reducto_ai/client.rb', line 101 def split @split ||= Resources::Split.new(self) end |