Class: KintsugiSDK::OpenApiSDK

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/kintsugi_sdk/openapisdk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, retry_config: nil, timeout_ms: nil, security: nil, security_source: nil, server_idx: nil, server_url: nil, url_params: nil, debug_logging: nil) ⇒ OpenApiSDK



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kintsugi_sdk/openapisdk.rb', line 34

def initialize(client: nil, retry_config: nil, timeout_ms: nil, security: nil, security_source: nil, server_idx: nil, server_url: nil, url_params: nil, debug_logging: nil)
  ## Instantiates the SDK configuring it with the provided parameters.
  # @param [T.nilable(Faraday::Connection)] client The faraday HTTP client to use for all operations
  # @param [T.nilable(::KintsugiSDK::Utils::RetryConfig)] retry_config The retry configuration to use for all operations
  # @param [T.nilable(Integer)] timeout_ms Request timeout in milliseconds for all operations
  # @param [T.nilable(Models::Shared::Security)] security: The security details required for authentication
  # @param [T.proc.returns(T.nilable(Models::Shared::Security))] security_source: A function that returns security details required for authentication
  # @param [T.nilable(::Integer)] server_idx The index of the server to use for all operations
  # @param [T.nilable(::String)] server_url The server URL to use for all operations
  # @param [T.nilable(::Hash<::Symbol, ::String>)] url_params Parameters to optionally template the server URL with

  connection_options = {
    request: {
      params_encoder: Faraday::FlatParamsEncoder
    }
  }
  connection_options[:request][:timeout] = (timeout_ms.to_f / 1000) unless timeout_ms.nil?

  debug_enabled = debug_logging == true || ENV['KINTSUGI_DEBUG'] == 'true'

  client ||= Faraday.new(**connection_options) do |f|
    f.request :multipart, {}
    f.response :logger, $stdout, { headers: true, bodies: true, errors: true } if debug_enabled
  end
  
  if !server_url.nil?
    if !url_params.nil?
      server_url = Utils.template_url(server_url, url_params)
    end
  end

  server_idx = 0 if server_idx.nil?
  hooks = SDKHooks::Hooks.new
  @sdk_configuration = SDKConfiguration.new(
    client,
    hooks,
    retry_config,
    timeout_ms,
    security,
    security_source,
    server_url,
    server_idx
  )
  @sdk_configuration = hooks.sdk_init(config: @sdk_configuration)
  init_sdks
end

Instance Attribute Details

#address_validationObject

Returns the value of attribute address_validation.



19
20
21
# File 'lib/kintsugi_sdk/openapisdk.rb', line 19

def address_validation
  @address_validation
end

#customersObject

Returns the value of attribute customers.



19
20
21
# File 'lib/kintsugi_sdk/openapisdk.rb', line 19

def customers
  @customers
end

#exemptionsObject

Returns the value of attribute exemptions.



19
20
21
# File 'lib/kintsugi_sdk/openapisdk.rb', line 19

def exemptions
  @exemptions
end

#nexusObject

Returns the value of attribute nexus.



19
20
21
# File 'lib/kintsugi_sdk/openapisdk.rb', line 19

def nexus
  @nexus
end

#productsObject

Returns the value of attribute products.



19
20
21
# File 'lib/kintsugi_sdk/openapisdk.rb', line 19

def products
  @products
end

#tax_estimationObject

Returns the value of attribute tax_estimation.



19
20
21
# File 'lib/kintsugi_sdk/openapisdk.rb', line 19

def tax_estimation
  @tax_estimation
end

#transactionsObject

Returns the value of attribute transactions.



19
20
21
# File 'lib/kintsugi_sdk/openapisdk.rb', line 19

def transactions
  @transactions
end

Instance Method Details

#get_url(base_url:, url_variables: nil) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/kintsugi_sdk/openapisdk.rb', line 93

def get_url(base_url:, url_variables: nil)
  sd_base_url, sd_options = @sdk_configuration.get_server_details

  if base_url.nil?
    base_url = sd_base_url
  end

  if url_variables.nil?
    url_variables = sd_options
  end

  return Utils.template_url base_url, url_variables
end

#init_sdksObject



82
83
84
85
86
87
88
89
90
# File 'lib/kintsugi_sdk/openapisdk.rb', line 82

def init_sdks
  @address_validation = AddressValidation.new(@sdk_configuration)
  @customers = Customers.new(@sdk_configuration)
  @exemptions = Exemptions.new(@sdk_configuration)
  @nexus = Nexus.new(@sdk_configuration)
  @products = Products.new(@sdk_configuration)
  @transactions = Transactions.new(@sdk_configuration)
  @tax_estimation = TaxEstimation.new(@sdk_configuration)
end