Class: Smplkit::Platform::ServicesClient
- Inherits:
-
Object
- Object
- Smplkit::Platform::ServicesClient
- Defined in:
- lib/smplkit/platform/client.rb
Overview
Sync service CRUD (client.platform.services).
Instance Method Summary collapse
- #_create(svc) ⇒ Object private
- #_update(svc) ⇒ Object private
-
#delete(id) ⇒ void
Delete a service by id.
-
#get(id) ⇒ Service
Fetch a single service by id.
-
#initialize(app_http) ⇒ ServicesClient
constructor
A new instance of ServicesClient.
-
#list(page_number: nil, page_size: nil) ⇒ Array<Service>
List services in the account.
-
#new(id, name:) ⇒ Service
Build an unsaved
Service; call.saveto persist it.
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.
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.
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.
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 |