Class: Smplkit::Account::SettingsClient

Inherits:
Object
  • Object
show all
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

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
41
42
43
44
45
# 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"
  }
  # Default SDK User-Agent unless the caller supplied one (any casing) —
  # without it this raw Faraday connection would fall through to
  # Faraday's own "Faraday vX.Y.Z" default.
  @headers["User-Agent"] = Smplkit.user_agent unless Transport.user_agent_supplied?(extra_headers)
  @headers.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.



58
59
60
61
62
# File 'lib/smplkit/account/client.rb', line 58

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

#getSmplkit::Account::AccountSettings

Fetch the authenticated account's current settings.

Returns:



51
52
53
54
55
# File 'lib/smplkit/account/client.rb', line 51

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