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.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/reducto_ai/client.rb', line 68 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.
42 43 44 |
# File 'lib/reducto_ai/client.rb', line 42 def api_key @api_key end |
#base_url ⇒ String (readonly)
Returns Base URL for API requests.
45 46 47 |
# File 'lib/reducto_ai/client.rb', line 45 def base_url @base_url end |
#logger ⇒ Logger (readonly)
Returns Logger instance for debugging.
48 49 50 |
# File 'lib/reducto_ai/client.rb', line 48 def logger @logger end |
#open_timeout ⇒ Integer (readonly)
Returns Connection open timeout in seconds.
51 52 53 |
# File 'lib/reducto_ai/client.rb', line 51 def open_timeout @open_timeout end |
#read_timeout ⇒ Integer (readonly)
Returns Request read timeout in seconds.
54 55 56 |
# File 'lib/reducto_ai/client.rb', line 54 def read_timeout @read_timeout end |
Instance Method Details
#edit ⇒ Resources::Edit
Returns the Edit resource for PDF markup operations.
108 109 110 |
# File 'lib/reducto_ai/client.rb', line 108 def edit @edit ||= Resources::Edit.new(self) end |
#extract ⇒ Resources::Extract
Returns the Extract resource for structured data extraction.
92 93 94 |
# File 'lib/reducto_ai/client.rb', line 92 def extract @extract ||= Resources::Extract.new(self) end |
#jobs ⇒ Resources::Jobs
Returns the Jobs resource for job management operations.
124 125 126 |
# File 'lib/reducto_ai/client.rb', line 124 def jobs @jobs ||= Resources::Jobs.new(self) end |
#parse ⇒ Resources::Parse
Returns the Parse resource for document parsing operations.
84 85 86 |
# File 'lib/reducto_ai/client.rb', line 84 def parse @parse ||= Resources::Parse.new(self) end |
#pipeline ⇒ Resources::Pipeline
Returns the Pipeline resource for multi-step workflows.
116 117 118 |
# File 'lib/reducto_ai/client.rb', line 116 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.
157 158 159 |
# File 'lib/reducto_ai/client.rb', line 157 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.
142 143 144 145 146 147 148 |
# File 'lib/reducto_ai/client.rb', line 142 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.
100 101 102 |
# File 'lib/reducto_ai/client.rb', line 100 def split @split ||= Resources::Split.new(self) end |