Class: Smplkit::Platform::ServicesClient

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

Overview

Sync service CRUD (client.platform.services).

Instance Method Summary collapse

Constructor Details

#initialize(app_http) ⇒ ServicesClient

Returns a new instance of ServicesClient.



174
175
176
# File 'lib/smplkit/platform/client.rb', line 174

def initialize(app_http)
  @api = SmplkitGeneratedClient::App::ServicesApi.new(app_http)
end

Instance Method Details

#_create(svc) ⇒ 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.



222
223
224
225
# File 'lib/smplkit/platform/client.rb', line 222

def _create(svc)
  response = ApiSupport::ErrorMapping.call { @api.create_service(create_body_for(svc)) }
  from_resource(ApiSupport::ResourceShim.from_model(response.data))
end

#_update(svc) ⇒ 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.



228
229
230
231
232
233
# File 'lib/smplkit/platform/client.rb', line 228

def _update(svc)
  raise "cannot update a Service with no id" if svc.id.nil?

  response = ApiSupport::ErrorMapping.call { @api.update_service(svc.id, body_for(svc)) }
  from_resource(ApiSupport::ResourceShim.from_model(response.data))
end

#delete(id) ⇒ void

This method returns an undefined value.

Delete a service by id.

Parameters:

  • id (String)

    Identifier of the service to delete.



216
217
218
219
# File 'lib/smplkit/platform/client.rb', line 216

def delete(id)
  ApiSupport::ErrorMapping.call { @api.delete_service(id) }
  nil
end

#get(id) ⇒ Service

Fetch a single service by id.

Parameters:

  • id (String)

    Identifier of the service to fetch.

Returns:

  • (Service)

    The matching service.

Raises:



207
208
209
210
# File 'lib/smplkit/platform/client.rb', line 207

def get(id)
  response = ApiSupport::ErrorMapping.call { @api.get_service(id) }
  from_resource(ApiSupport::ResourceShim.from_model(response.data))
end

#list(page_number: nil, page_size: nil) ⇒ Array<Service>

List services 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 services per page. Defaults to the server’s page size.

Returns:

  • (Array<Service>)

    The services on the requested page.



194
195
196
197
198
199
200
# File 'lib/smplkit/platform/client.rb', line 194

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_services(opts) }
  (response.data || []).map { |r| from_resource(ApiSupport::ResourceShim.from_model(r)) }
end

#new(id, name:) ⇒ Service

Build an unsaved Service; call .save to persist it.

Parameters:

  • id (String)

    Stable, human-readable identifier for the service.

  • name (String)

    Display name shown in the Console.

Returns:

  • (Service)

    An unsaved service bound to this client.



183
184
185
# File 'lib/smplkit/platform/client.rb', line 183

def new(id, name:)
  Service.new(self, id: id, name: name)
end