Class: Smplkit::Account::AccountClient

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/account/client.rb

Overview

The Smpl Account client (sync).

Exposes the authenticated account’s own configuration, reachable as client.account (Smplkit::Client) or constructed directly:

 = Smplkit::AccountClient.new(api_key: "sk_...")
settings = .settings.get
settings.environment_order = ["production", "staging"]
settings.save

Sub-client: settings (get/save). Pure CRUD — no install required.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, base_url: nil, profile: nil, base_domain: nil, scheme: nil, debug: nil, extra_headers: nil) ⇒ AccountClient

Returns a new instance of AccountClient.



103
104
105
106
107
108
109
110
# File 'lib/smplkit/account/client.rb', line 103

def initialize(api_key: nil, base_url: nil, profile: nil, base_domain: nil,
               scheme: nil, debug: nil, extra_headers: nil)
  app_url, resolved_key, headers = Account.(
    api_key: api_key, base_url: base_url, profile: profile,
    base_domain: base_domain, scheme: scheme, debug: debug, extra_headers: extra_headers
  )
  @settings = SettingsClient.new(app_url, resolved_key, headers.empty? ? nil : headers)
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



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

def settings
  @settings
end

Class Method Details

.open(**kwargs) ⇒ Object

Construct, yield to the block, and close on exit.



116
117
118
119
120
121
122
123
# File 'lib/smplkit/account/client.rb', line 116

def self.open(**kwargs)
  client = new(**kwargs)
  begin
    yield client
  ensure
    client.close
  end
end

Instance Method Details

#closeObject

No-op — the settings client opens a short-lived HTTP client per call.



113
# File 'lib/smplkit/account/client.rb', line 113

def close; end