Class: Smplkit::Platform::ContextTypesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/platform/client.rb

Overview

Sync context-type CRUD (client.platform.context_types).

Instance Method Summary collapse

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.

Parameters:

  • id (String)

    Identifier of the context type to delete.



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.

Parameters:

  • id (String)

    Identifier of the context type to fetch.

Returns:

Raises:



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.

Parameters:

  • page_number (Integer, nil) (defaults to: nil)

    1-based page to fetch. Defaults to the first page.

  • page_size (Integer, nil) (defaults to: nil)

    Maximum number of context types per page. Defaults to the server’s page size.

Returns:

  • (Array<ContextType>)

    The context types on the requested page.



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.

Parameters:

  • id (String)

    Stable, human-readable identifier for the context type (for example “user”).

  • name (String, nil) (defaults to: nil)

    Display name shown in the Console. Defaults to id when omitted.

  • attributes (Hash, nil) (defaults to: nil)

    Known-attribute slots, keyed by attribute name, with a metadata dict per slot. Defaults to no declared attributes.

Returns:

  • (ContextType)

    An unsaved context type bound to this client.



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