Class: ReductoAI::Client

Inherits:
Object
  • Object
show all
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.

Examples:

Using global configuration

ReductoAI.configure do |config|
  config.api_key = ENV["REDUCTO_API_KEY"]
end

client = ReductoAI::Client.new
client.parse.sync(input: "https://example.com/doc.pdf")

Using per-instance configuration

client = ReductoAI::Client.new(
  api_key: "your-key",
  read_timeout: 60
)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, base_url: nil, logger: nil, open_timeout: nil, read_timeout: nil) ⇒ Client

Creates a new Reducto API client.

Examples:

client = ReductoAI::Client.new(api_key: "sk-...")

Parameters:

  • api_key (String, nil) (defaults to: nil)

    Reducto API key (defaults to global config)

  • base_url (String, nil) (defaults to: nil)

    API base URL (defaults to global config)

  • logger (Logger, nil) (defaults to: nil)

    Logger instance (defaults to global config)

  • open_timeout (Integer, nil) (defaults to: nil)

    Connection timeout in seconds (defaults to global config)

  • read_timeout (Integer, nil) (defaults to: nil)

    Read timeout in seconds (defaults to global config)

Raises:

  • (ArgumentError)

    if api_key is missing or empty



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_keyString (readonly)

Returns Reducto API key.

Returns:

  • (String)

    Reducto API key



42
43
44
# File 'lib/reducto_ai/client.rb', line 42

def api_key
  @api_key
end

#base_urlString (readonly)

Returns Base URL for API requests.

Returns:

  • (String)

    Base URL for API requests



45
46
47
# File 'lib/reducto_ai/client.rb', line 45

def base_url
  @base_url
end

#loggerLogger (readonly)

Returns Logger instance for debugging.

Returns:

  • (Logger)

    Logger instance for debugging



48
49
50
# File 'lib/reducto_ai/client.rb', line 48

def logger
  @logger
end

#open_timeoutInteger (readonly)

Returns Connection open timeout in seconds.

Returns:

  • (Integer)

    Connection open timeout in seconds



51
52
53
# File 'lib/reducto_ai/client.rb', line 51

def open_timeout
  @open_timeout
end

#read_timeoutInteger (readonly)

Returns Request read timeout in seconds.

Returns:

  • (Integer)

    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

#editResources::Edit

Returns the Edit resource for PDF markup operations.

Returns:

See Also:



108
109
110
# File 'lib/reducto_ai/client.rb', line 108

def edit
  @edit ||= Resources::Edit.new(self)
end

#extractResources::Extract

Returns the Extract resource for structured data extraction.

Returns:

See Also:



92
93
94
# File 'lib/reducto_ai/client.rb', line 92

def extract
  @extract ||= Resources::Extract.new(self)
end

#jobsResources::Jobs

Returns the Jobs resource for job management operations.

Returns:

See Also:



124
125
126
# File 'lib/reducto_ai/client.rb', line 124

def jobs
  @jobs ||= Resources::Jobs.new(self)
end

#parseResources::Parse

Returns the Parse resource for document parsing operations.

Returns:

See Also:



84
85
86
# File 'lib/reducto_ai/client.rb', line 84

def parse
  @parse ||= Resources::Parse.new(self)
end

#pipelineResources::Pipeline

Returns the Pipeline resource for multi-step workflows.

Returns:

See Also:



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.

Parameters:

  • path (String)

    API endpoint path

  • body (Hash)

    request body

Returns:

  • (Hash)

    parsed JSON response



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.

Parameters:

  • method (Symbol)

    HTTP method (:get, :post, :put, :delete)

  • path (String)

    API endpoint path

  • body (Hash, nil) (defaults to: nil)

    request body

  • params (Hash, nil) (defaults to: nil)

    query parameters

Returns:

  • (Hash)

    parsed JSON response

Raises:



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.message}"
end

#splitResources::Split

Returns the Split resource for document splitting operations.

Returns:

See Also:



100
101
102
# File 'lib/reducto_ai/client.rb', line 100

def split
  @split ||= Resources::Split.new(self)
end