Class: IBM::CloudSDK

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm/cloud_sdk.rb

Overview

Holds the SDK pieces.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, logger: nil) ⇒ CloudSDK



12
13
14
15
16
# File 'lib/ibm/cloud_sdk.rb', line 12

def initialize(api_key, logger: nil)
  @logger = logger || Logger.new($stdout, level: :warn)
  @connection = IBM::Cloud::SDKHTTP::HTTPConnection.new(@logger)
  @token = IBM::Cloud::SDKHTTP::IAMToken.new(api_key, @connection, logger: @logger)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



18
19
20
# File 'lib/ibm/cloud_sdk.rb', line 18

def connection
  @connection
end

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/ibm/cloud_sdk.rb', line 18

def logger
  @logger
end

#tokenObject (readonly)

Returns the value of attribute token.



18
19
20
# File 'lib/ibm/cloud_sdk.rb', line 18

def token
  @token
end

Instance Method Details

#add_proxy(uri) ⇒ Object

Add a proxy to the configuration.



22
23
24
25
26
27
# File 'lib/ibm/cloud_sdk.rb', line 22

def add_proxy(uri)
  raise "URI #{uri} is not set properly. Requires a full url, and optional user & password" if uri.relative?

  path = "#{uri.scheme}://#{uri.hostname}"
  @connection.class.http_proxy(path, uri.port, uri.user, uri.password)
end

#tagsObject



29
30
31
# File 'lib/ibm/cloud_sdk.rb', line 29

def tags
  @tags ||= IBM::Cloud::SDK::Tags.new(@connection, @token, logger: @logger)
end

#vpc(region = 'us-east') ⇒ Object

Get an instance of the VPC API.



35
36
37
# File 'lib/ibm/cloud_sdk.rb', line 35

def vpc(region = 'us-east')
  @vpc ||= IBM::Cloud::SDK::Vpc.new(region, @connection, @token, logger: @logger)
end