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.



32
33
34
35
36
37
38
# File 'lib/smplkit/account/client.rb', line 32

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



46
47
48
49
50
# File 'lib/smplkit/account/client.rb', line 46

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

#getObject



40
41
42
43
44
# File 'lib/smplkit/account/client.rb', line 40

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