Build Status semantic-release Gem Version

IBM Cloud VPC Ruby SDK

Ruby client library to interact with various IBM Cloud VPC APIs.

Disclaimer: this SDK is being released initially as a pre-release version. Changes might occur which impact applications that use this SDK.

Table of Contents

Overview

The IBM Cloud VPC Ruby SDK allows developers to programmatically interact with the following IBM Cloud services:

Service Name Imported Class Name
VPC IbmVpc::VpcV1

Prerequisites

  • An IBM Cloud account.
  • An IAM API key to allow the SDK to access your account. Create one here.
  • Ruby 2.3.0 or above.

Installation

To install, use gem

gem install "ibm_vpc"

Using the SDK

For general SDK usage information, please see this link

Authentication

require "ibm_vpc"

# First select an authentication type (IAM, Bearer, etc...)
# See https://github.com/IBM/ibm-cloud-sdk-common/blob/master/README.md#authentication for
# a full list of available authenticators.

# IAM example
authenticator = IbmVpc::Authenticators::IamAuthenticator.new(
  apikey: "<iam_apikey>",
  url: "<iam_url>" # optional - the default value is https://iam.cloud.ibm.com/identity/token
)

# Bearer Token example
authenticator = IbmVpc::Authenticators::BearerTokenAuthenticator.new(
  bearer_token: "<access_token>"
)

Using the VPC API client

Setting up and using the API client is simple, just pass in your authenticator object and then you can issue API calls:


# Pass the authenticator into the VpcV1 service
vpc_v1 = IbmVpc::VpcV1.new(
  version: "2023-12-19" # Will default to the latest version if not specified
  authenticator: authenticator
)

# Now you can start to make API calls
response = vpc_v1.list_instances()
response["instances"].each do |instance|
  puts instance["name"]
end

If a collection response has a lot of items in it, the results will be paginated.

start = nil
instances = []

loop do
  response = vpc_v1.list_instances(start: start)
  instances += response["instances"]

  next_link = response.dig("next", "href")
  break if next_link.nil?

  start = CGI.parse(URI(next_link).query)["start"].first
end

Questions

If you are having difficulties using this SDK or have a question about the IBM Cloud services, please ask a question Stack Overflow.

Issues

If you encounter an issue with the project, you are welcome to submit a bug report. Before that, please search for similar issues. It's possible that someone has already reported the problem.

Open source @ IBM

Find more open source projects on the IBM Github Page

Contributing

See CONTRIBUTING.md.

License

This SDK is released under the Apache 2.0 license. The license's full text can be found in LICENSE.