Class: Assinafy::Resources::AccountResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Assinafy::Resources::AccountResource
- Defined in:
- lib/assinafy/resources/account_resource.rb,
sig/assinafy.rbs
Overview
Accounts (workspaces): CRUD plus the per-account theme, KPI stats, and brand logo (upload/download/delete).
See https://api.assinafy.com.br/v1/docs for the Account Object and its related endpoints.
Constant Summary
Constants inherited from BaseResource
BaseResource::AUTH_HEADERS, BaseResource::PAGINATION_HEADERS, BaseResource::PATH_SEGMENT
Instance Method Summary collapse
-
#create(payload) ⇒ Hash
Create a new account (workspace).
-
#delete(force: false, account_id_override: nil) ⇒ nil
Delete an account.
-
#delete_logo(account_id_override = nil) ⇒ nil
Delete the account brand logo.
-
#download_logo(account_id_override = nil) ⇒ String
Download the account brand logo as raw image bytes.
-
#get(account_id_override = nil) ⇒ Hash
Fetch an account by ID (defaults to the client's account).
-
#list ⇒ Hash{Symbol=>Array,nil}
List the accounts (workspaces) the authenticated user can access.
-
#stats(granularity: nil, month: nil, account_id_override: nil) ⇒ Array<Hash>
Fetch per-account document KPIs.
-
#theme(account_id_override = nil) ⇒ Hash
Fetch the account's public theme (name, brand colors, logo URL).
-
#update(payload, account_id_override = nil) ⇒ Hash
Update an account.
-
#upload_logo(source, account_id_override = nil) ⇒ nil, Hash
Upload (replace) the account brand logo.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from Assinafy::Resources::BaseResource
Instance Method Details
#create(payload) ⇒ Hash
Create a new account (workspace).
60 61 62 63 64 65 66 67 |
# File 'lib/assinafy/resources/account_resource.rb', line 60 def create(payload) body = body_params(require_payload(payload, 'Account payload')) require_present(body['name'], 'name') call('Failed to create account') do http_post('accounts', body) end end |
#delete(force: false, account_id_override: nil) ⇒ nil
Delete an account. Deletion is blocked while documents are pending.
For an active paid subscription, pass force: true to cancel the
subscription as part of deletion.
136 137 138 139 140 141 142 143 |
# File 'lib/assinafy/resources/account_resource.rb', line 136 def delete(force: false, account_id_override: nil) acc_id = account_id(account_id_override) force = require_boolean(force, 'force') call_void('Failed to delete account') do http_delete("accounts/#{acc_id}", body: body_params(force: force)) end end |
#delete_logo(account_id_override = nil) ⇒ nil
Delete the account brand logo.
265 266 267 268 269 270 271 |
# File 'lib/assinafy/resources/account_resource.rb', line 265 def delete_logo(account_id_override = nil) acc_id = account_id(account_id_override) call_void('Failed to delete account logo') do http_delete("accounts/#{acc_id}/logo") end end |
#download_logo(account_id_override = nil) ⇒ String
Download the account brand logo as raw image bytes.
219 220 221 222 223 224 225 |
# File 'lib/assinafy/resources/account_resource.rb', line 219 def download_logo(account_id_override = nil) acc_id = account_id(account_id_override) call_binary('Failed to download account logo') do http_get("accounts/#{acc_id}/logo") end end |
#get(account_id_override = nil) ⇒ Hash
Fetch an account by ID (defaults to the client's account).
86 87 88 89 90 91 92 |
# File 'lib/assinafy/resources/account_resource.rb', line 86 def get(account_id_override = nil) acc_id = account_id(account_id_override) call('Failed to fetch account') do http_get("accounts/#{acc_id}") end end |
#list ⇒ Hash{Symbol=>Array,nil}
List the accounts (workspaces) the authenticated user can access.
34 35 36 37 38 |
# File 'lib/assinafy/resources/account_resource.rb', line 34 def list call_list('Failed to list accounts') do http_get('accounts') end end |
#stats(granularity: nil, month: nil, account_id_override: nil) ⇒ Array<Hash>
Documented in the API reference but not enabled on every environment — the sandbox currently returns 404 for this route.
Fetch per-account document KPIs.
201 202 203 204 205 206 207 |
# File 'lib/assinafy/resources/account_resource.rb', line 201 def stats(granularity: nil, month: nil, account_id_override: nil) acc_id = account_id(account_id_override) call_array('Failed to fetch account stats') do http_get("accounts/#{acc_id}/stats", query_params(granularity: granularity, month: month)) end end |
#theme(account_id_override = nil) ⇒ Hash
Fetch the account's public theme (name, brand colors, logo URL).
161 162 163 164 165 166 167 |
# File 'lib/assinafy/resources/account_resource.rb', line 161 def theme(account_id_override = nil) acc_id = account_id(account_id_override) call('Failed to fetch account theme') do http_get("accounts/#{acc_id}/theme") end end |
#update(payload, account_id_override = nil) ⇒ Hash
Update an account.
113 114 115 116 117 118 119 120 |
# File 'lib/assinafy/resources/account_resource.rb', line 113 def update(payload, account_id_override = nil) acc_id = account_id(account_id_override) body = body_params(require_payload(payload, 'Account payload')) call('Failed to update account') do http_put("accounts/#{acc_id}", body) end end |
#upload_logo(source, account_id_override = nil) ⇒ nil, Hash
Upload (replace) the account brand logo.
247 248 249 250 251 252 253 254 |
# File 'lib/assinafy/resources/account_resource.rb', line 247 def upload_logo(source, account_id_override = nil) acc_id = account_id(account_id_override) buffer, file_name = read_source(source) call('Failed to upload account logo') do http_post("accounts/#{acc_id}/logo", { file: file_part(buffer, file_name) }) end end |