Class: Smplkit::Platform::EnvironmentsClient

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

Overview

Sync environment CRUD (client.platform.environments).

Instance Method Summary collapse

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.

Parameters:

  • id (String)

    Identifier of the environment to delete.



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.

Parameters:

  • id (String)

    Identifier of the environment to fetch.

Returns:

Raises:



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.

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

Returns:

  • (Array<Environment>)

    The environments on the requested page.



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.

Parameters:

  • id (String)

    Stable, human-readable identifier for the environment (for example “production”).

  • name (String)

    Display name shown in the Console.

  • color (Color, String, nil) (defaults to: nil)

    Accent color for the environment, as a Color or a CSS hex string. Defaults to no color.

  • classification (String) (defaults to: EnvironmentClassification::STANDARD)

    Whether the environment participates in the standard environment ordering. Defaults to EnvironmentClassification::STANDARD.

Returns:

  • (Environment)

    An unsaved environment bound to this client.



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