SecretID
, SecretKey
, and endpoint. The general format of endpoint is \\*.tencentcloudapi.com
. For example, the endpoint of CVM is cvm.tencentcloudapi.com
. For more information, please see the documentation of the specified product.SecretId
and SecretKey
.SecretId
is used to identify the API requester.SecretKey
is used to encrypt the string to sign that can be verified on the server.SecretKey
private and avoid disclosure.$ cd tencentcloud-sdk-ruby/tencentcloud$ cd tencentcloud-sdk-common$ gem build tencentcloud-sdk-common.gemspec$ gem install tencentcloud-sdk-common-1.0.0.gem$ cd ../tencentcloud-sdk-cvm$ gem build tencentcloud-sdk-cvm.gemspec$ gem install tencentcloud-sdk-cvm-1.0.0.gem
# -*- coding: UTF-8 -*-require 'tencentcloud-sdk-common'require 'tencentcloud-sdk-cvm'include TencentCloud::Commoninclude TencentCloud::Cvm::V20170312begincre = Credential.new('SecretId', 'SecretKey')req = DescribeInstancesRequest.new(nil, nil, 0, 1)cli = Client.new(cre, 'ap-guangzhou')cli.DescribeInstances(req)rescue TencentCloudSDKException => eputs e.messageputs e.backtrace.inspectend
# -*- coding: UTF-8 -*-require 'tencentcloud-sdk-common'require 'tencentcloud-sdk-cvm'begininclude TencentCloud::Common# Import the client module of the corresponding product moduleinclude TencentCloud::Cvm::V20170312# Instantiate an authentication object. Pass in `secretId` and `secretKey` of your Tencent Cloud account as the input parameters and keep them confidentialcred = Credential.new('SecretId', 'SecretKey')# Instantiate an HTTP optionhttpProfile = HttpProfile.new()# If you need to specify the proxy for API access, you can initialize HttpProfile as follows# httpProfile = HttpProfile.new(proxy='http://username:password@proxy IP:proxy port')httpProfile.scheme = "https" # HTTP is supported if the network environment has access to the public network, and HTTPS is used by default and recommendedhttpProfile.req_method = "GET" # GET request (POST request is used by default)httpProfile.req_timeout = 30 # Specify the request timeout value in seconds. The default value is 60shttpProfile.endpoint = "cvm.tencentcloudapi.com" # Specify the endpoint. If you do not specify the endpoint, nearby access is enabled by default# (Optional) Instantiate a client optionclientProfile = ClientProfile.new()clientProfile.sign_method = "TC3-HMAC-SHA256" # Specify the signature algorithmclientProfile.language = "en-US" # Specify to display in English (the default value is Chinese)clientProfile.http_profile = httpProfileclientProfile.debug = true # Print `debug` logs# Instantiate the client object of the requested product (with CVM as an example). `clientProfile` is optional.client = Client.new(cred, "ap-shanghai", clientProfile)# Instantiate a CVM instance information query request object. Each API corresponds to a request objectreq = DescribeInstancesRequest.new()# Populate the request parameters. Here, the member variables of the request object are the input parameters of the corresponding API.# You can view the definition of the request parameters in the API documentation at the official website or by redirecting to the definition of the request object.respFilter = Filter.new() # Create a `Filter` object to query CVM instances in the `zone` dimension.respFilter.Name = "zone"respFilter.Values = ["ap-shanghai-1", "ap-shanghai-2"]req.Filters = [respFilter] # `Filters` is a list of `Filter` objects# Initialize the request by calling the `DescribeInstances` method on the client object. Note: the request method name corresponds to the request object# The returned `resp` is an instance of the `DescribeInstancesResponse` class which corresponds to the request objectresp = client.DescribeInstances(req)# A string return packet in JSON format is outputtedputs resp.serialize# You can also take a single value.# You can view the definition of the return field in the API documentation at the official website or by redirecting to the definition of the response object.puts resp.TotalCountrescue TencentCloudSDKException => eputs e.messageputs e.backtrace.inspectend
proxy
when initializing HttpProfile
.https_proxy
.
Was this page helpful?