aliyun-rails 0.1.18 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e27be7e1a623946c583fc2d8dfd8144c76352b1370f37954f07d1a92379903d
4
- data.tar.gz: 73ce2236eacb879c9a4648a1b03701a2f33dfd5ab3060a854fbbb51c54fb50ad
3
+ metadata.gz: 5ccdac6af59f37792525c9a0b013bd0bfd6a100bb716144cc9396096ade241b8
4
+ data.tar.gz: 1337c663672fe95a6e3e98d72995065435ed40ef05fe8cb9cfdd6cb0566a4805
5
5
  SHA512:
6
- metadata.gz: 6db85298bf709c4688a92b7c45c34376c043156ae00443882030e1382b6ae36a5eef5456b1c3f317074799440d7edce17751afb1b560a98ad7cef09425014bfb
7
- data.tar.gz: 5041a64210b45a9cf036e4573bb33a9cbc8a652c2f9fcf167f634477cf816a5daf4709e9e3836718a7bc306e2f424edc9b99f21d686e53579c929e03ddf8b49f
6
+ metadata.gz: 50f671530e769630468705c677ce1787e0924a9fcd82e53133374bafe8edb9b69faa5d14b2f45830c287a24cf920866530576ca73cbb6249fbd01067cb075d6b
7
+ data.tar.gz: f974dca4cf118419bdfca3d5ff5ee7cced1a2e848293e0d58c642362658a30cc8ce70f6328e98f0bbcbe3dc531da792dd0d72247323b1f93787031f050043a7f
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.14] - 2022-04-01
4
+
5
+ - 优化 rpc_client 代码
6
+ - 优化 roa_client 代码
7
+ - 完善代码范例
8
+
9
+ ## [0.1.0] - 2022-03-31
10
+
11
+ - 首次发布代码
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at careline@foxmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1 @@
1
+ ## 待添加
@@ -1,19 +1,18 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "set"
4
2
  require "openssl"
5
3
  require "faraday"
6
- require "erb"
7
4
  require "active_support/all"
8
5
 
9
6
  module Aliyun
10
7
  module Connector
11
8
  class RPCClient
9
+
12
10
  attr_accessor :endpoint, :api_version, :access_key_id, :access_key_secret,
13
11
  :security_token, :codes, :opts, :verbose
14
12
 
15
13
  # 对象初始化属性
16
- def initialize(config = {}, verbose = false)
14
+ def initialize(config, verbose = false)
15
+
17
16
  validate config
18
17
 
19
18
  self.endpoint = config[:endpoint]
@@ -30,30 +29,32 @@ module Aliyun
30
29
 
31
30
  # 通用请求接口
32
31
  def request(action:, params: {}, opts: {})
33
- opts = self.opts.merge(opts)
34
- action = action.upcase_first if opts[:format_action]
35
- params = format_params(params) unless opts[:format_params]
36
- defaults = default_params
37
- params = { Action: action }.merge(defaults).merge(params)
38
- method = (opts[:method] || "GET").upcase
39
- sign = "#{method}&#{encode('/')}&#{encode(params.to_query)}"
40
- secret = "#{self.access_key_secret}&"
41
- signature = Base64.encode64(OpenSSL::HMAC.digest("sha1", secret, sign)).strip
42
- params["Signature"] = signature
32
+ opts = self.opts.merge(opts)
33
+ action = action.upcase_first if opts[:format_action]
34
+ params = format_params(params) unless opts[:format_params]
35
+ defaults = default_params
36
+ params = { Action: action }.merge(defaults).merge(params)
37
+ method = (opts[:method] || "GET").upcase
38
+ normalized = normalize(params)
39
+ canonicalized = canonicalize(normalized)
40
+ string_to_sign = "#{method}&#{encode('/')}&#{encode(canonicalized)}"
41
+ secret = "#{self.access_key_secret}&"
42
+ signature = Base64.encode64(OpenSSL::HMAC.digest("sha1", secret, string_to_sign)).strip
43
+ normalized.push(["Signature", encode(signature)])
43
44
 
44
45
  # 转换为 query 样式
45
- query_string = params.to_query
46
+ querystring = canonicalize(normalized)
46
47
 
47
48
  # 特殊处理 POST
48
- uri = opts[:method] == "POST" ? "/" : "/?#{query_string}"
49
+ uri = opts[:method] == "POST" ? "/" : "/?#{querystring}"
49
50
 
50
51
  # 初始化会话
51
- response = connection.send(method.downcase, uri) do |r|
52
+ response = connection.send(method.downcase, uri) do |request|
52
53
  if opts[:method] == "POST"
53
- r.headers["Content-Type"] = "application/x-www-form-urlencoded"
54
- r.body = query_string
54
+ request.headers["Content-Type"] = "application/x-www-form-urlencoded"
55
+ request.body = querystring
55
56
  end
56
- r.headers["User-Agent"] = DEFAULT_UA
57
+ request.headers["User-Agent"] = DEFAULT_UA
57
58
  end
58
59
 
59
60
  # 解析接口响应
@@ -72,22 +73,22 @@ module Aliyun
72
73
 
73
74
  # 设置缺省参数
74
75
  def default_params
75
- params = {
76
- Format: "JSON",
77
- SignatureMethod: "HMAC-SHA1",
78
- SignatureNonce: SecureRandom.hex(8),
79
- SignatureVersion: "1.0",
80
- Timestamp: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
81
- AccessKeyId: self.access_key_id,
82
- Version: self.api_version,
76
+ default_params = {
77
+ "Format" => "JSON",
78
+ "SignatureMethod" => "HMAC-SHA1",
79
+ "SignatureNonce" => SecureRandom.hex(16),
80
+ "SignatureVersion" => "1.0",
81
+ "Timestamp" => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
82
+ "AccessKeyId" => self.access_key_id,
83
+ "Version" => self.api_version,
83
84
  }
84
- params[:SecurityToken] = self.security_token if self.security_token.present?
85
- params
85
+ default_params["SecurityToken"] = self.security_token if self.security_token
86
+ default_params
86
87
  end
87
88
 
88
89
  # 消息签名需要
89
- def encode(input)
90
- ERB::Util.url_encode input
90
+ def encode(string)
91
+ ERB::Util.url_encode(string)
91
92
  end
92
93
 
93
94
  # 转换 HASH key 样式
@@ -96,6 +97,37 @@ module Aliyun
96
97
  param_hash
97
98
  end
98
99
 
100
+ def replace_repeat_list(target, key, repeat)
101
+ repeat.each_with_index do |item, index|
102
+ if item && item.instance_of?(Hash)
103
+ item.each_key { |k| target["#{key}.#{index.next}.#{k}"] = item[k] }
104
+ else
105
+ target["#{key}.#{index.next}"] = item
106
+ end
107
+ end
108
+ target
109
+ end
110
+
111
+ def flat_params(params)
112
+ target = {}
113
+ params.each do |key, value|
114
+ if value.instance_of?(Array)
115
+ replace_repeat_list(target, key, value)
116
+ else
117
+ target[key.to_s] = value
118
+ end
119
+ end
120
+ target.to_query
121
+ end
122
+
123
+ def normalize(params)
124
+ flat_params(params).sort.to_h.map { |key, value| [encode(key), encode(value)] }
125
+ end
126
+
127
+ def canonicalize(normalized)
128
+ normalized.map { |element| "#{element.first}=#{element.last}" }.join("&")
129
+ end
130
+
99
131
  def validate(config = {})
100
132
  config.with_indifferent_access
101
133
  raise ArgumentError, 'must pass "config"' unless config
data/lib/aliyun/dyvms.rb CHANGED
@@ -19,7 +19,7 @@ module Aliyun
19
19
  TtsParam: tts_param.to_json
20
20
  }
21
21
  opts = { method: "POST", timeout: 15000 }
22
- request(action: "SendSms", params: params, opts: opts)
22
+ request(action: "SingleCallByTts", params: params, opts: opts)
23
23
  end
24
24
  end
25
25
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aliyun
4
- VERSION = "0.1.18"
4
+ VERSION = "0.1.21"
5
5
  DEFAULT_UA = "AlibabaCloud (#{Gem::Platform.local.os}; " +
6
6
  "#{Gem::Platform.local.cpu}) Ruby/#{RUBY_VERSION} Core/#{VERSION}"
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyun-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - WENWU.YAN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-03 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -45,6 +45,9 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - CHANGELOG.md
49
+ - CODE_OF_CONDUCT.md
50
+ - CONTRIBUTING.md
48
51
  - LICENSE.txt
49
52
  - README.md
50
53
  - Rakefile