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



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

Returns Reducto API key.

Returns:

  • (String)

    Reducto API key



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

def api_key
  @api_key
end

#base_urlString (readonly)

Returns Base URL for API requests.

Returns:

  • (String)

    Base URL for API requests



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

def base_url
  @base_url
end

#loggerLogger (readonly)

Returns Logger instance for debugging.

Returns:

  • (Logger)

    Logger instance for debugging



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

def logger
  @logger
end

#open_timeoutInteger (readonly)

Returns Connection open timeout in seconds.

Returns:

  • (Integer)

    Connection open timeout in seconds



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

def open_timeout
  @open_timeout
end

#read_timeoutInteger (readonly)

Returns Request read timeout in seconds.

Returns:

  • (Integer)

    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

#editResources::Edit

Returns the Edit resource for PDF markup operations.

Returns:

See Also:



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

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

#extractResources::Extract

Returns the Extract resource for structured data extraction.

Returns:

See Also:



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

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

#jobsResources::Jobs

Returns the Jobs resource for job management operations.

Returns:

See Also:



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

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

#parseResources::Parse

Returns the Parse resource for document parsing operations.

Returns:

See Also:



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

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

#pipelineResources::Pipeline

Returns the Pipeline resource for multi-step workflows.

Returns:

See Also:



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.

Parameters:

  • path (String)

    API endpoint path

  • body (Hash)

    request body

Returns:

  • (Hash)

    parsed JSON response



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.

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:



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

#splitResources::Split

Returns the Split resource for document splitting operations.

Returns:

See Also:



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

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