Class: Smplkit::Account::SettingsClient
- Inherits:
-
Object
- Object
- Smplkit::Account::SettingsClient
- Defined in:
- lib/smplkit/account/client.rb
Overview
Sync account-settings get/save (client.account.settings).
The endpoint isn’t JSON:API — body is a raw JSON object — so we use an HTTP client directly rather than going through a generated client.
Constant Summary collapse
- SETTINGS_PATH =
"/api/v1/accounts/current/settings"
Instance Method Summary collapse
- #_save(data) ⇒ Object private
-
#get ⇒ Smplkit::Account::AccountSettings
Fetch the authenticated account’s current settings.
-
#initialize(app_base_url, api_key, extra_headers = nil) ⇒ SettingsClient
constructor
A new instance of SettingsClient.
Constructor Details
#initialize(app_base_url, api_key, extra_headers = nil) ⇒ SettingsClient
Returns a new instance of SettingsClient.
34 35 36 37 38 39 40 |
# File 'lib/smplkit/account/client.rb', line 34 def initialize(app_base_url, api_key, extra_headers = nil) @base_url = app_base_url @headers = { "Authorization" => "Bearer #{api_key}", "Content-Type" => "application/json" }.merge(extra_headers || {}) end |
Instance Method Details
#_save(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 57 |
# File 'lib/smplkit/account/client.rb', line 53 def _save(data) resp = connection.put(SETTINGS_PATH) { |req| req.body = JSON.generate(data) } Errors.raise_for_status(resp.status, resp.body.to_s) AccountSettings.new(self, data: parse_body(resp.body)) end |
#get ⇒ Smplkit::Account::AccountSettings
Fetch the authenticated account’s current settings.
46 47 48 49 50 |
# File 'lib/smplkit/account/client.rb', line 46 def get resp = connection.get(SETTINGS_PATH) Errors.raise_for_status(resp.status, resp.body.to_s) AccountSettings.new(self, data: parse_body(resp.body)) end |