Class: Voltaria::Sandbox::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/voltaria/sandbox/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/voltaria/sandbox/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#update_client(request_options: {}, **params) ⇒ Voltaria::Types::ClientResponse

Update an existing client's status or credit limit using their client ID.

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)

Options Hash (**params):

  • :client_id (String)

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/voltaria/sandbox/client.rb', line 25

def update_client(request_options: {}, **params)
  params = Voltaria::Internal::Types::Utils.normalize_keys(params)
  request_data = Voltaria::Sandbox::Types::ClientUpdateSandbox.new(params).to_h
  non_body_param_names = ["client_id"]
  body = request_data.except(*non_body_param_names)

  request = Voltaria::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "v2/sandbox/clients/#{URI.encode_uri_component(params[:client_id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Voltaria::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Voltaria::Types::ClientResponse.load(response.body)
  else
    error_class = Voltaria::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_loan(request_options: {}, **params) ⇒ Voltaria::Types::LoanResponseWithInstallments

Update the status of a specific loan using its unique loan ID.

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)

Options Hash (**params):

  • :loan_id (String)

Returns:



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

def update_loan(request_options: {}, **params)
  params = Voltaria::Internal::Types::Utils.normalize_keys(params)
  request_data = Voltaria::Sandbox::Types::LoanUpdateSandbox.new(params).to_h
  non_body_param_names = ["loan_id"]
  body = request_data.except(*non_body_param_names)

  request = Voltaria::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "v2/sandbox/loans/#{URI.encode_uri_component(params[:loan_id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Voltaria::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Voltaria::Types::LoanResponseWithInstallments.load(response.body)
  else
    error_class = Voltaria::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#webhook_test(request_options: {}, **params) ⇒ Hash[String, Object]

Test a webhook subscription by ID or trigger all by event type.

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:

  • (Hash[String, Object])

Raises:

  • (error_class)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/voltaria/sandbox/client.rb', line 102

def webhook_test(request_options: {}, **params)
  params = Voltaria::Internal::Types::Utils.normalize_keys(params)
  request = Voltaria::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/sandbox/webhooks/trigger",
    body: Voltaria::Sandbox::Types::WebhookTestSandbox.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Voltaria::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Voltaria::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end