Class: IBM::Cloud::SDKHTTP::BaseInstance

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
BaseHTTPMixin
Defined in:
lib/ibm/cloud/sdk_http/base_instance.rb

Overview

Container that encapsulates the VPC API.

Direct Known Subclasses

IBM::Cloud::SDK::VPC::VPCInstance

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseHTTPMixin

#adhoc, #delete, #get, #metadata, #patch, #post, #put, #unchecked_response, #url

Constructor Details

#initialize(parent, data: {}, id_key: 'id', endpoint: nil) ⇒ BaseInstance

Returns a new instance of BaseInstance.



15
16
17
18
19
20
21
22
23
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 15

def initialize(parent, data: {}, id_key: 'id', endpoint: nil)
  @data = data

  endpoint ||= data[id_key.to_sym]
  @connection = parent.connection
  @token = parent.token
  @endpoint = parent.url(endpoint)
  @logger = parent.logger
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



25
26
27
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 25

def connection
  @connection
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



25
26
27
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 25

def endpoint
  @endpoint
end

#loggerObject (readonly)

Returns the value of attribute logger.



25
26
27
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 25

def logger
  @logger
end

#tokenObject (readonly)

Returns the value of attribute token.



25
26
27
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 25

def token
  @token
end

Instance Method Details

#detailsSDKResponse

Fetch the instance details for this resource.

Returns:



29
30
31
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 29

def details
  get.hash_response
end

#refreshBaseInstance

Fetch the instance details from the server. Clear current data and save the results.

Returns:



35
36
37
38
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 35

def refresh
  @data.replace(details)
  self
end

#removeObject

Send a delete request to the server for this resource.



46
47
48
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 46

def remove
  delete
end

#update(payload) ⇒ Object

Send an update to the server for this resource.



41
42
43
# File 'lib/ibm/cloud/sdk_http/base_instance.rb', line 41

def update(payload)
  patch(payload: payload)
end