Sha256: 466f88ea6953859ccab26b550f245d15f1ce3fccc1e4a41779e40e989238e1a9
Contents?: true
Size: 1.63 KB
Versions: 2
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true require 'tencent_cloud/common/exception/tencent_cloud_sdk_exception' require 'tencent_cloud/common/credential' require 'tencent_cloud/common/http/request' require 'tencent_cloud/common/http/sign' module TencentCloud module Common class BaseClient def initialize(credential, region = nil) @credential = credential @region = region end def camel_case(str) return str if str !~ /_/ && str =~ /[A-Z]+.*/ str.split('_').map(&:capitalize).join end def get_response(action, body) headers = { 'X-TC-Action' => action, 'X-TC-Version' => self.class::API_VERSION, 'X-TC-Timestamp' => Time.now.to_i } headers['X-TC-Region'] = @region if @region request = TencentCloud::Common::Http::Request.new @credential, self.class, headers: headers, body: JSON.generate(body, space: ' ') request.run end 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tencentcloud-sdk-ruby-0.4.8 | lib/tencent_cloud/common/base_client.rb |
tencentcloud-sdk-ruby-0.3.6 | lib/tencent_cloud/common/base_client.rb |