tencentcloud-sdk-ruby 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a660b1a26fdbd2f0564ad8fd9dd2ca52b1a1dc57186f7bf0e8832eda35cab4e5
|
4
|
+
data.tar.gz: 1a382388800705f92ee23cf46127d67b1cc48e1b2a3f96d07a64c9347587102c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09c0b042a6dfb3c4fc80995560ec8e69814b6d6c30d7fae93c9b4d21ba056b16b1fe34ade7cff0ad5ed756e6d1913c2b2c712bfbb6deef4c49d4190fa0b3bc3b'
|
7
|
+
data.tar.gz: 96ec85883076fec0694fcc19083d7beddd82d43ec21fab653cf94a8cca5a8430a2aff94a73a16f5072e22548268a0306d8ff38a712c18b59f00b5a3c6e2b3617
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module TencentCloud
|
6
|
+
class CaptchaClient
|
7
|
+
API_VERSION = '2019-07-22'
|
8
|
+
Action = 'DescribeCaptchaResult'
|
9
|
+
CaptchaType = 9
|
10
|
+
REQUEST_PATH = '/'
|
11
|
+
JSON_CONTENT = 'application/json'
|
12
|
+
MULTIPART_CONTENT = 'multipart/form-data'
|
13
|
+
FORM_URLENCODED_CONTENT = 'application/x-www-form-urlencoded'
|
14
|
+
ENDPOINT = 'captcha.tencentcloudapi.com'
|
15
|
+
|
16
|
+
def initialize(secret_id, secret_key)
|
17
|
+
@api_version = '2019-07-22'
|
18
|
+
@secret_id = secret_id
|
19
|
+
@secret_key = secret_key
|
20
|
+
@token = nil
|
21
|
+
@region = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def http_request(data)
|
25
|
+
uri = URI.parse("https://#{ENDPOINT}")
|
26
|
+
request = Net::HTTP::Post.new(uri.to_s)
|
27
|
+
request = build_req_with_v3_signature(Action, data, request, options = {})
|
28
|
+
|
29
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
30
|
+
http.request request
|
31
|
+
end
|
32
|
+
end
|
33
|
+
def build_req_with_v3_signature(action, params, req, options = {})
|
34
|
+
content_type = JSON_CONTENT
|
35
|
+
timestamp = Time.current.to_i
|
36
|
+
header = {}
|
37
|
+
header['Content-Type'] = content_type
|
38
|
+
header['Host'] = ENDPOINT
|
39
|
+
header['X-TC-Action'] = action
|
40
|
+
header['X-TC-Timestamp'] = timestamp
|
41
|
+
header['X-TC-Version'] = @api_version
|
42
|
+
header['X-TC-Region'] = @region
|
43
|
+
header['X-TC-Token'] = @token if @token
|
44
|
+
req.body = JSON.generate(params, { 'ascii_only' => true, 'space' => ' ' })
|
45
|
+
payload = req.body
|
46
|
+
canonical_querystring = ''
|
47
|
+
hashed_payload = Digest::SHA256.hexdigest(payload)
|
48
|
+
|
49
|
+
authorization = sign_v3(content_type, ENDPOINT, 'POST', '/',
|
50
|
+
canonical_querystring, hashed_payload, header['X-TC-Timestamp'],
|
51
|
+
@secret_id, @secret_key)
|
52
|
+
header['Authorization'] = authorization
|
53
|
+
header.each do |k, v|
|
54
|
+
req[k] = v
|
55
|
+
end
|
56
|
+
req
|
57
|
+
end
|
58
|
+
def sign_v3(content_type, endpoint, method, uri, query, payload, timestamp, secret_id, secret_key)
|
59
|
+
canonical_headers = "content-type:#{content_type}\nhost:#{endpoint}\n"
|
60
|
+
signed_headers = 'content-type;host'
|
61
|
+
canonical_request = [
|
62
|
+
method,
|
63
|
+
uri,
|
64
|
+
query,
|
65
|
+
canonical_headers,
|
66
|
+
signed_headers,
|
67
|
+
payload,
|
68
|
+
].join("\n")
|
69
|
+
service = endpoint.split('.')[0]
|
70
|
+
|
71
|
+
date = Time.at(timestamp).utc.strftime('%Y-%m-%d')
|
72
|
+
credential_scope = date + '/' + service + '/' + 'tc3_request'
|
73
|
+
algorithm = 'TC3-HMAC-SHA256'
|
74
|
+
hashed_request_payload = Digest::SHA256.hexdigest(canonical_request)
|
75
|
+
string_to_sign = [
|
76
|
+
algorithm,
|
77
|
+
timestamp,
|
78
|
+
credential_scope,
|
79
|
+
hashed_request_payload,
|
80
|
+
].join("\n")
|
81
|
+
|
82
|
+
digest = OpenSSL::Digest.new('sha256')
|
83
|
+
secret_date = OpenSSL::HMAC.digest(digest, 'TC3' + secret_key, date)
|
84
|
+
secret_service = OpenSSL::HMAC.digest(digest, secret_date, service)
|
85
|
+
secret_signing = OpenSSL::HMAC.digest(digest, secret_service, 'tc3_request')
|
86
|
+
signature = OpenSSL::HMAC.hexdigest(digest, secret_signing, string_to_sign)
|
87
|
+
"#{algorithm} Credential=#{secret_id}/#{credential_scope}, SignedHeaders=#{signed_headers}, Signature=#{signature}"
|
88
|
+
end
|
89
|
+
def format_params(prefix = nil, params)
|
90
|
+
d = {}
|
91
|
+
case params
|
92
|
+
when Hash
|
93
|
+
params.each do |k, v|
|
94
|
+
key = prefix ? "#{prefix}.#{k}" : k.to_s
|
95
|
+
d.update(format_params(key, v))
|
96
|
+
end
|
97
|
+
when Array
|
98
|
+
params.each_with_index do |v, i|
|
99
|
+
key = prefix ? "#{prefix}.#{i}" : i.to_s
|
100
|
+
d.update(format_params(key, v))
|
101
|
+
end
|
102
|
+
else
|
103
|
+
d[prefix] = params
|
104
|
+
end
|
105
|
+
d
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -7,7 +7,7 @@ require 'tencent_cloud/common/http/sign'
|
|
7
7
|
module TencentCloud
|
8
8
|
module Common
|
9
9
|
class BaseClient
|
10
|
-
def initialize(credential, region)
|
10
|
+
def initialize(credential, region = nil)
|
11
11
|
@credential = credential
|
12
12
|
@region = region
|
13
13
|
end
|
@@ -22,10 +22,13 @@ module TencentCloud
|
|
22
22
|
headers = {
|
23
23
|
'X-TC-Action' => action,
|
24
24
|
'X-TC-Version' => self.class::API_VERSION,
|
25
|
-
'X-TC-Region' => @region,
|
26
25
|
'X-TC-Timestamp' => Time.now.to_i
|
27
26
|
}
|
28
|
-
|
27
|
+
headers['X-TC-Region'] = @region if @region
|
28
|
+
request = TencentCloud::Common::Http::Request.new @credential,
|
29
|
+
self.class,
|
30
|
+
headers: headers,
|
31
|
+
body: JSON.generate(body, space: ' ')
|
29
32
|
request.run
|
30
33
|
end
|
31
34
|
|
@@ -31,7 +31,11 @@ module TencentCloud
|
|
31
31
|
|
32
32
|
# 文本分类
|
33
33
|
# https://cloud.tencent.com/document/api/271/35496
|
34
|
-
text_classification: 'TextClassification'
|
34
|
+
text_classification: 'TextClassification',
|
35
|
+
|
36
|
+
# 词法分析V2
|
37
|
+
# https://cloud.tencent.com/document/product/271/90611
|
38
|
+
parse_words: 'ParseWords'
|
35
39
|
}.freeze
|
36
40
|
end
|
37
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tencentcloud-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FengCe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- examples/trtc/v20190722/describe_room_information.rb
|
107
107
|
- examples/trtc/v20190722/start_mcu_mix_transcode.rb
|
108
108
|
- lib/tencent_cloud.rb
|
109
|
+
- lib/tencent_cloud/captcha/v20190722/captcha_client.rb
|
109
110
|
- lib/tencent_cloud/common/base_client.rb
|
110
111
|
- lib/tencent_cloud/common/credential.rb
|
111
112
|
- lib/tencent_cloud/common/exception/tencent_cloud_sdk_exception.rb
|
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
141
|
- !ruby/object:Gem::Version
|
141
142
|
version: '0'
|
142
143
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
144
|
+
rubygems_version: 3.4.13
|
144
145
|
signing_key:
|
145
146
|
specification_version: 4
|
146
147
|
summary: 腾讯云开发者工具套件(SDK)3.0,SDK3.0是云 API3.0 平台的配套工具
|