Class: Smplkit::Platform::EnvironmentsClient
- Inherits:
-
Object
- Object
- Smplkit::Platform::EnvironmentsClient
- Defined in:
- lib/smplkit/platform/client.rb
Overview
Sync environment CRUD (client.platform.environments).
Instance Method Summary collapse
- #_create(env) ⇒ Object private
- #_update(env) ⇒ Object private
-
#delete(id) ⇒ void
Delete an environment by id.
-
#get(id) ⇒ Environment
Fetch a single environment by id.
-
#initialize(app_http) ⇒ EnvironmentsClient
constructor
A new instance of EnvironmentsClient.
-
#list(page_number: nil, page_size: nil) ⇒ Array<Environment>
List environments in the account.
-
#new(id, name:, color: nil, classification: EnvironmentClassification::STANDARD) ⇒ Environment
Build an unsaved
Environment; call.saveto persist it.
Constructor Details
#initialize(app_http) ⇒ EnvironmentsClient
Returns a new instance of EnvironmentsClient.
72 73 74 |
# File 'lib/smplkit/platform/client.rb', line 72 def initialize(app_http) @api = SmplkitGeneratedClient::App::EnvironmentsApi.new(app_http) end |
Instance Method Details
#_create(env) ⇒ 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.
126 127 128 129 |
# File 'lib/smplkit/platform/client.rb', line 126 def _create(env) response = ApiSupport::ErrorMapping.call { @api.create_environment(body_for(env)) } from_resource(ApiSupport::ResourceShim.from_model(response.data)) end |
#_update(env) ⇒ 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.
132 133 134 135 136 137 |
# File 'lib/smplkit/platform/client.rb', line 132 def _update(env) raise "cannot update an Environment with no id" if env.id.nil? response = ApiSupport::ErrorMapping.call { @api.update_environment(env.id, body_for(env)) } from_resource(ApiSupport::ResourceShim.from_model(response.data)) end |
#delete(id) ⇒ void
This method returns an undefined value.
Delete an environment by id.
120 121 122 123 |
# File 'lib/smplkit/platform/client.rb', line 120 def delete(id) ApiSupport::ErrorMapping.call { @api.delete_environment(id) } nil end |
#get(id) ⇒ Environment
Fetch a single environment by id.
111 112 113 114 |
# File 'lib/smplkit/platform/client.rb', line 111 def get(id) response = ApiSupport::ErrorMapping.call { @api.get_environment(id) } from_resource(ApiSupport::ResourceShim.from_model(response.data)) end |
#list(page_number: nil, page_size: nil) ⇒ Array<Environment>
List environments in the account.
98 99 100 101 102 103 104 |
# File 'lib/smplkit/platform/client.rb', line 98 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_environments(opts) } (response.data || []).map { |r| from_resource(ApiSupport::ResourceShim.from_model(r)) } end |
#new(id, name:, color: nil, classification: EnvironmentClassification::STANDARD) ⇒ Environment
Build an unsaved Environment; call .save to persist it.
87 88 89 |
# File 'lib/smplkit/platform/client.rb', line 87 def new(id, name:, color: nil, classification: EnvironmentClassification::STANDARD) Environment.new(self, id: id, name: name, color: color, classification: classification) end |