Class: Ultrasafeai::Batches::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ultrasafeai/batches/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, base_url: nil, environment: nil) ⇒ void

Parameters:



11
12
13
14
15
# File 'lib/ultrasafeai/batches/client.rb', line 11

def initialize(client:, base_url: nil, environment: nil)
  @client = client
  @base_url = base_url
  @environment = environment
end

Instance Method Details

#cancel_batch(request_options: {}, **params) ⇒ Ultrasafeai::Types::Batch

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :batch_id (String)

Returns:



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/ultrasafeai/batches/client.rb', line 129

def cancel_batch(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "batches/#{URI.encode_uri_component(params[:batch_id].to_s)}/cancel",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::Batch.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_batch(request_options: {}, **params) ⇒ Ultrasafeai::Types::Batch

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ultrasafeai/batches/client.rb', line 64

def create_batch(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "POST",
    path: "batches",
    body: Ultrasafeai::Batches::Types::CreateBatchRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::Batch.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_batches(request_options: {}, **params) ⇒ Ultrasafeai::Types::ListResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :limit (Integer, nil)
  • :after (String, nil)

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ultrasafeai/batches/client.rb', line 28

def list_batches(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["after"] = params[:after] if params.key?(:after)

  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "batches",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::ListResponse.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#retrieve_batch(request_options: {}, **params) ⇒ Ultrasafeai::Types::Batch

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :batch_id (String)

Returns:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ultrasafeai/batches/client.rb', line 97

def retrieve_batch(request_options: {}, **params)
  params = Ultrasafeai::Internal::Types::Utils.normalize_keys(params)
  request = Ultrasafeai::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:base),
    method: "GET",
    path: "batches/#{URI.encode_uri_component(params[:batch_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Ultrasafeai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Ultrasafeai::Types::Batch.load(response.body)
  else
    error_class = Ultrasafeai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end