Class: IBM::Cloud::SDK::VPC::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm/cloud/sdk/vpc/helpers/connection.rb

Overview

The Connection object to be used for all HTTP requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, logger: nil, client: nil) ⇒ Connection

Returns a new instance of Connection.



16
17
18
19
20
21
# File 'lib/ibm/cloud/sdk/vpc/helpers/connection.rb', line 16

def initialize(api_key, logger: nil, client: nil)
  @api_key = api_key
  @logger = logger
  @client = client
  @token = Token.new(api_key, logger: logger, client: client)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



23
24
25
# File 'lib/ibm/cloud/sdk/vpc/helpers/connection.rb', line 23

def client
  @client
end

Instance Method Details

#adhoc(verb, uri, opts = {}) ⇒ IBM::Cloud::SDK::VPC::Response

Send a HTTP request. Checks the validity of the response.

Parameters:

  • verb (String)

    THe HTTP verb to use for this request.

  • uri (String)

    The Full URL to send.

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :params (Hash)

    Parameters for URL encoding parameters.

  • :json (Hash)

    Used when sending a hash as application/json content type.

  • :form (Hash)

    Used when sending a hash as a form.

  • :headers (Hash)

    Used to modify headers for request.

Returns:

Raises:



34
35
36
# File 'lib/ibm/cloud/sdk/vpc/helpers/connection.rb', line 34

def adhoc(verb, uri, opts = {})
  unverified_request(verb, uri, opts).raise_for_status?
end

#authorization_headerObject

Get bearer token string for clients not using the adhoc method.



46
47
48
# File 'lib/ibm/cloud/sdk/vpc/helpers/connection.rb', line 46

def authorization_header
  @token.authorization_header
end

#unverified_request(verb, uri, opts = {}) ⇒ Object

Send a HTTP request. Don’t do any validation checks.

See Also:

  • for options.


40
41
42
43
# File 'lib/ibm/cloud/sdk/vpc/helpers/connection.rb', line 40

def unverified_request(verb, uri, opts = {})
  response = @client.auth(@token.authorization_header).request(verb.to_s.downcase.to_sym, uri, opts)
  Response.new(response)
end