Class: TencentCloud::Common::Http::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/tencent_cloud/common/http/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credential, klass, options = {}) ⇒ Request

Returns a new instance of Request.



9
10
11
12
13
14
15
# File 'lib/tencent_cloud/common/http/request.rb', line 9

def initialize(credential, klass, options = {})
  @uri = 'https://' + klass::ENDPOINT
  options[:method] ||= :post
  self.options = options
  self.credential = credential
  self.klass = klass
end

Instance Attribute Details

#credentialObject

Returns the value of attribute credential.



7
8
9
# File 'lib/tencent_cloud/common/http/request.rb', line 7

def credential
  @credential
end

#klassObject

Returns the value of attribute klass.



7
8
9
# File 'lib/tencent_cloud/common/http/request.rb', line 7

def klass
  @klass
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/tencent_cloud/common/http/request.rb', line 7

def options
  @options
end

Instance Method Details

#runObject



34
35
36
# File 'lib/tencent_cloud/common/http/request.rb', line 34

def run
  signed_request.run
end

#signed_requestObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tencent_cloud/common/http/request.rb', line 17

def signed_request
  headers = {
    'content-type' => 'application/json; charset=utf-8',
    'host' => klass::ENDPOINT
  }
  if options[:headers].nil?
    options[:headers] = headers
  else
    options[:headers].merge! headers
  end

  request = Typhoeus::Request.new @uri.to_s, options
  authorization = Sign.new(credential, klass, request).sign_tc3
  request.options[:headers]['Authorization'] = authorization
  request
end