class TencentCloud::Common::BaseClient

Public Class Methods

new(credential, region) click to toggle source
# File lib/tencent_cloud/common/base_client.rb, line 10
def initialize(credential, region)
  @credential = credential
  @region = region
end

Public Instance Methods

camel_case(str) click to toggle source
# File lib/tencent_cloud/common/base_client.rb, line 15
def camel_case(str)
  return str if str !~ /_/ && str =~ /[A-Z]+.*/

  str.split('_').map(&:capitalize).join
end
get_response(action, body) click to toggle source
# File lib/tencent_cloud/common/base_client.rb, line 21
def get_response(action, body)
  headers = {
    'X-TC-Action' => action,
    'X-TC-Version' => self.class::API_VERSION,
    'X-TC-Region' => @region,
    'X-TC-Timestamp' => Time.now.to_i
  }
  request = TencentCloud::Common::Http::Request.new @credential, self.class, headers: headers, body: JSON.generate(body, space: ' ')
  request.run
end
method_missing(m, body) click to toggle source
# File lib/tencent_cloud/common/base_client.rb, line 32
def method_missing(m, body)
  unless self.class::APIS.keys.include?(m)
    raise TencentCloud::Common::Exception::TencentCloudSDKException, 'InvalidMethod, method not found'
  end

  api = self.class::APIS[m]
  unless body.is_a?(Hash)
    raise TencentCloud::Common::Exception::TencentCloudSDKException, 'InvalidPayload, payload must be a hash'
  end

  get_response(api, body)
  # puts "There's no method called #{m} here -- please try again."
end