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.



68
69
70
# File 'lib/smplkit/platform/client.rb', line 68

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

Instance Method Details

#_create(env) ⇒ Object



95
96
97
98
# File 'lib/smplkit/platform/client.rb', line 95

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



100
101
102
103
104
105
# File 'lib/smplkit/platform/client.rb', line 100

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) ⇒ Object



90
91
92
93
# File 'lib/smplkit/platform/client.rb', line 90

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

#get(id) ⇒ Object



85
86
87
88
# File 'lib/smplkit/platform/client.rb', line 85

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) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/smplkit/platform/client.rb', line 77

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) ⇒ Object

Return an unsaved Environment. Call .save to persist.



73
74
75
# File 'lib/smplkit/platform/client.rb', line 73

def new(id, name:, color: nil, classification: EnvironmentClassification::STANDARD)
  Environment.new(self, id: id, name: name, color: color, classification: classification)
end