Class: Smplkit::Platform::ContextTypesClient
- Inherits:
-
Object
- Object
- Smplkit::Platform::ContextTypesClient
- Defined in:
- lib/smplkit/platform/client.rb
Overview
Sync context-type CRUD (client.platform.context_types).
Instance Method Summary collapse
- #_create(ct) ⇒ Object private
- #_update(ct) ⇒ Object private
-
#delete(id) ⇒ void
Delete a context type by id.
-
#get(id) ⇒ ContextType
Fetch a single context type by id.
-
#initialize(app_http) ⇒ ContextTypesClient
constructor
A new instance of ContextTypesClient.
-
#list(page_number: nil, page_size: nil) ⇒ Array<ContextType>
List context types in the account.
-
#new(id, name: nil, attributes: nil) ⇒ ContextType
Build an unsaved
ContextType; call.saveto persist it.
Constructor Details
#initialize(app_http) ⇒ ContextTypesClient
Returns a new instance of ContextTypesClient.
273 274 275 |
# File 'lib/smplkit/platform/client.rb', line 273 def initialize(app_http) @api = SmplkitGeneratedClient::App::ContextTypesApi.new(app_http) end |
Instance Method Details
#_create(ct) ⇒ 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.
326 327 328 329 |
# File 'lib/smplkit/platform/client.rb', line 326 def _create(ct) response = ApiSupport::ErrorMapping.call { @api.create_context_type(body_for(ct)) } from_resource(ApiSupport::ResourceShim.from_model(response.data)) end |
#_update(ct) ⇒ 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.
332 333 334 335 336 337 |
# File 'lib/smplkit/platform/client.rb', line 332 def _update(ct) raise "cannot update a ContextType with no id" if ct.id.nil? response = ApiSupport::ErrorMapping.call { @api.update_context_type(ct.id, body_for(ct)) } from_resource(ApiSupport::ResourceShim.from_model(response.data)) end |
#delete(id) ⇒ void
This method returns an undefined value.
Delete a context type by id.
320 321 322 323 |
# File 'lib/smplkit/platform/client.rb', line 320 def delete(id) ApiSupport::ErrorMapping.call { @api.delete_context_type(id) } nil end |
#get(id) ⇒ ContextType
Fetch a single context type by id.
311 312 313 314 |
# File 'lib/smplkit/platform/client.rb', line 311 def get(id) response = ApiSupport::ErrorMapping.call { @api.get_context_type(id) } from_resource(ApiSupport::ResourceShim.from_model(response.data)) end |
#list(page_number: nil, page_size: nil) ⇒ Array<ContextType>
List context types in the account.
298 299 300 301 302 303 304 |
# File 'lib/smplkit/platform/client.rb', line 298 def list(page_number: nil, page_size: nil) opts = {} opts[:page_number] = page_number unless page_number.nil? opts[:page_size] = page_size unless page_size.nil? response = ApiSupport::ErrorMapping.call { @api.list_context_types(opts) } (response.data || []).map { |r| from_resource(ApiSupport::ResourceShim.from_model(r)) } end |
#new(id, name: nil, attributes: nil) ⇒ ContextType
Build an unsaved ContextType; call .save to persist it.
287 288 289 |
# File 'lib/smplkit/platform/client.rb', line 287 def new(id, name: nil, attributes: nil) ContextType.new(self, id: id, name: name || id, attributes: attributes || {}) end |