Class: ERPC::ClientConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/erpc_sdk/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, endpoint: DEFAULT_ENDPOINT, account_endpoint: DEFAULT_ACCOUNT_ENDPOINT, user_endpoint: DEFAULT_USER_ENDPOINT, headers: {}, timeout: DEFAULT_TIMEOUT) ⇒ ClientConfig

Returns a new instance of ClientConfig.

Raises:



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/erpc_sdk/config.rb', line 61

def initialize(api_key:, endpoint: DEFAULT_ENDPOINT, account_endpoint: DEFAULT_ACCOUNT_ENDPOINT,
               user_endpoint: DEFAULT_USER_ENDPOINT, headers: {}, timeout: DEFAULT_TIMEOUT)
  @api_key = api_key.to_s.strip
  raise ConfigError, "api_key must not be empty" if @api_key.empty?
  raise ConfigError, "timeout must be positive" unless timeout.is_a?(Numeric) && timeout.finite? && timeout.positive?

  @endpoint = URLs.normalize_endpoint(endpoint)
  @account_endpoint = URLs.normalize_endpoint()
  @user_endpoint = URLs.normalize_endpoint(user_endpoint)
  @headers = headers.to_h.transform_keys(&:to_s).transform_values(&:to_s).freeze
  @timeout = timeout.to_f
end

Instance Attribute Details

#account_endpointObject (readonly)

Returns the value of attribute account_endpoint.



59
60
61
# File 'lib/erpc_sdk/config.rb', line 59

def 
  @account_endpoint
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



59
60
61
# File 'lib/erpc_sdk/config.rb', line 59

def api_key
  @api_key
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



59
60
61
# File 'lib/erpc_sdk/config.rb', line 59

def endpoint
  @endpoint
end

#headersObject (readonly)

Returns the value of attribute headers.



59
60
61
# File 'lib/erpc_sdk/config.rb', line 59

def headers
  @headers
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



59
60
61
# File 'lib/erpc_sdk/config.rb', line 59

def timeout
  @timeout
end

#user_endpointObject (readonly)

Returns the value of attribute user_endpoint.



59
60
61
# File 'lib/erpc_sdk/config.rb', line 59

def user_endpoint
  @user_endpoint
end

Instance Method Details

#inspectObject



74
75
76
77
78
# File 'lib/erpc_sdk/config.rb', line 74

def inspect
  "#<#{self.class} api_key=[REDACTED] endpoint=#{endpoint.inspect} " \
    "account_endpoint=#{.inspect} user_endpoint=#{user_endpoint.inspect} " \
    "header_names=#{headers.keys.inspect} timeout=#{timeout.inspect}>"
end