aliyun-rails 0.1.16 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTING.md +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +152 -152
- data/Rakefile +8 -8
- data/lib/aliyun/connector/roa_client.rb +166 -166
- data/lib/aliyun/connector/rpc_client.rb +147 -116
- data/lib/aliyun/dysms.rb +25 -25
- data/lib/aliyun/dyvms.rb +25 -25
- data/lib/aliyun/version.rb +7 -7
- data/lib/aliyun-rails.rb +25 -26
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb272181c60129e57686d1086eb34e5b4cb20776926c600ca9865e8a8e7537d3
|
4
|
+
data.tar.gz: 345f2c7bfc4135d42c4f8d9a0c4caab0218a5c419bde70fb4e13ae5f44414ac0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c17e6d850d702b250aefab7c0934990271a244ff97cfcc1e2f27870117f5ccbee62445e95fb0e3cec7207fedbc226986bd7e40ffd50da951e9bbdbad36ee46
|
7
|
+
data.tar.gz: 234b8e75fb51905c926ac4204c6ee5259a9f854ad0f8efb6b2b482a0870abc51fae36ce5203d131c970175474ccc06e4e3dddb0480f03d27d2b0a5471c8e1ba2
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
|
+
## 待添加
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 WENWU.YAN
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,153 +1,153 @@
|
|
1
|
-
[English](./README.md) | 简体中文
|
2
|
-
|
3
|
-
|
4
|
-
<p align="center">
|
5
|
-
<a href=" https://www.alibabacloud.com"><img src="https://aliyunsdk-pages.alicdn.com/icons/Aliyun.svg"></a>
|
6
|
-
</p>
|
7
|
-
|
8
|
-
<h1 align="center">非官方SDK套件-用于RAILS项目管理阿里云相关资源,已集成接口鉴权、短信服务、和语音服务功能</h1>
|
9
|
-
|
10
|
-
<p align="center">
|
11
|
-
<a href="https://badge.fury.io/rb/aliyun-rails"><img src="https://badge.fury.io/rb/aliyun-rails.svg" alt="Gem Version"></a>
|
12
|
-
<a href="https://travis-ci.org/ciscolive/aliyun-rails"><img src="https://travis-ci.org/ciscolive/aliyun-rails.svg?branch=master" alt="Build Status"></a>
|
13
|
-
<a href="https://ci.appveyor.com/project/ciscolive/aliyun-rails/branch/master"><img src="https://ci.appveyor.com/api/projects/status/uyepkk5bjbynofvu/branch/master?svg=true" alt="Build status"></a>
|
14
|
-
<a href="https://codecov.io/gh/ciscolive/aliyun-rails"><img src="https://codecov.io/gh/ciscolive/aliyun-rails/branch/master/graph/badge.svg" alt="codecov"></a>
|
15
|
-
</p>
|
16
|
-
|
17
|
-
|
18
|
-
- 支持 Rails 轻松访问阿里云服务,例如:弹性云主机(ECS)、负载均衡(SLB)、云监控(CloudMonitor)等。
|
19
|
-
- 已集成阿里云短信服务和语音服务,满足日常短信和电话告警需求。
|
20
|
-
|
21
|
-
本文档介绍如何安装和使用 aliyun-rails
|
22
|
-
|
23
|
-
## 使用诊断
|
24
|
-
|
25
|
-
[Troubleshoot](https://troubleshoot.api.aliyun.com/?source=github_sdk) 提供 OpenAPI 使用诊断服务,通过 `RequestID` 或 `报错信息`
|
26
|
-
,帮助开发者快速定位,为开发者提供解决方案。
|
27
|
-
|
28
|
-
## 安装
|
29
|
-
|
30
|
-
```sh
|
31
|
-
$ gem install aliyun-rails
|
32
|
-
```
|
33
|
-
|
34
|
-
## 使用
|
35
|
-
|
36
|
-
- 加载模块自动挂载几个常量:Dysms、Dyvms、RPCClient和ROAClient
|
37
|
-
|
38
|
-
CALL_TTS 实例:
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
require "aliyun-rails"
|
42
|
-
|
43
|
-
client = Aliyun::Dyvms.new(
|
44
|
-
access_key_id: ENV['ACCESS_KEY_ID'],
|
45
|
-
access_key_secret: ENV['ACCESS_KEY_SECRET'],
|
46
|
-
)
|
47
|
-
|
48
|
-
# 可以直接将API参数放到RAILS项目 * config/initializers *下
|
49
|
-
# Aliyun.config do |aliyun|
|
50
|
-
# aliyun.access_key_id = "XXX"
|
51
|
-
# aliyun.access_key_secret = "YYY"
|
52
|
-
# end
|
53
|
-
# 随后直接初始化
|
54
|
-
# client = Aliyun::Dyvms.new
|
55
|
-
|
56
|
-
# 调用语音方法 single_call_by_tts method
|
57
|
-
response = client.single_call_by_tts("075566668888", "13900001234", "TTS_CODE", { TTS_PARAM: 2022 })
|
58
|
-
|
59
|
-
puts response
|
60
|
-
|
61
|
-
```
|
62
|
-
|
63
|
-
SEND_SMS 示例:
|
64
|
-
|
65
|
-
```ruby
|
66
|
-
require "aliyun-rails"
|
67
|
-
|
68
|
-
client = Aliyun::Dysms.new(
|
69
|
-
access_key_id: ENV['ACCESS_KEY_ID'],
|
70
|
-
access_key_secret: ENV['ACCESS_KEY_SECRET'],
|
71
|
-
)
|
72
|
-
|
73
|
-
# 可以直接将API参数放到RAILS项目 * config/initializers *下
|
74
|
-
# Aliyun.config do |aliyun|
|
75
|
-
# aliyun.access_key_id = "XXX"
|
76
|
-
# aliyun.access_key_secret = "YYY"
|
77
|
-
# end
|
78
|
-
# 随后直接初始化
|
79
|
-
# client = Dysms.new
|
80
|
-
|
81
|
-
# 调用短信方法 send_sms method
|
82
|
-
response = client.send_sms("1380000000", "SMS_10010", { param1: "11" }, "SIGN_NAME")
|
83
|
-
|
84
|
-
puts response
|
85
|
-
```
|
86
|
-
|
87
|
-
RPC 示例:
|
88
|
-
|
89
|
-
```ruby
|
90
|
-
require 'aliyun-rails'
|
91
|
-
|
92
|
-
# 实例化对象
|
93
|
-
client = RPCClient.new(
|
94
|
-
endpoint: 'http://ros.aliyuncs.com',
|
95
|
-
api_version: '2015-09-01',
|
96
|
-
access_key_id: ENV['ACCESS_KEY_ID'],
|
97
|
-
access_key_secret: ENV['ACCESS_KEY_SECRET'],
|
98
|
-
security_token: 'TOKEN_KEY'
|
99
|
-
)
|
100
|
-
|
101
|
-
# 请求接口查询
|
102
|
-
params = { key: (1..11).to_a.map(&:to_s) }
|
103
|
-
request_option = { method: 'POST', timeout: 15000 }
|
104
|
-
response = client.request(
|
105
|
-
action: 'DescribeRegions',
|
106
|
-
params: params,
|
107
|
-
opts: request_option
|
108
|
-
)
|
109
|
-
|
110
|
-
puts response
|
111
|
-
|
112
|
-
```
|
113
|
-
|
114
|
-
ROA 示例:
|
115
|
-
|
116
|
-
```ruby
|
117
|
-
require 'aliyun-rails'
|
118
|
-
|
119
|
-
# 初始化对象
|
120
|
-
client = ROAClient.new(
|
121
|
-
endpoint: 'http://ros.aliyuncs.com',
|
122
|
-
api_version: '2015-09-01',
|
123
|
-
access_key_id: ENV['ACCESS_KEY_ID'],
|
124
|
-
access_key_secret: ENV['ACCESS_KEY_SECRET'],
|
125
|
-
)
|
126
|
-
|
127
|
-
# 请求接口查询
|
128
|
-
response = client.request(
|
129
|
-
method: 'GET',
|
130
|
-
uri: '/regions',
|
131
|
-
options: {
|
132
|
-
timeout: 15000
|
133
|
-
}
|
134
|
-
)
|
135
|
-
|
136
|
-
puts response.body
|
137
|
-
```
|
138
|
-
|
139
|
-
## 问题
|
140
|
-
|
141
|
-
[提交 Issue](https://github.com/ciscolive/aliyun-rails/issues/new/choose),不符合指南的问题可能会立即关闭。
|
142
|
-
|
143
|
-
## 发行说明
|
144
|
-
|
145
|
-
每个版本的详细更改记录在[发行说明](CHANGELOG.md)中。
|
146
|
-
|
147
|
-
## 贡献
|
148
|
-
|
149
|
-
提交 Pull Request 之前请阅读[贡献指南](CONTRIBUTING.md)。
|
150
|
-
|
151
|
-
## 许可证
|
152
|
-
|
1
|
+
[English](./README.md) | 简体中文
|
2
|
+
|
3
|
+
|
4
|
+
<p align="center">
|
5
|
+
<a href=" https://www.alibabacloud.com"><img src="https://aliyunsdk-pages.alicdn.com/icons/Aliyun.svg"></a>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<h1 align="center">非官方SDK套件-用于RAILS项目管理阿里云相关资源,已集成接口鉴权、短信服务、和语音服务功能</h1>
|
9
|
+
|
10
|
+
<p align="center">
|
11
|
+
<a href="https://badge.fury.io/rb/aliyun-rails"><img src="https://badge.fury.io/rb/aliyun-rails.svg" alt="Gem Version"></a>
|
12
|
+
<a href="https://travis-ci.org/ciscolive/aliyun-rails"><img src="https://travis-ci.org/ciscolive/aliyun-rails.svg?branch=master" alt="Build Status"></a>
|
13
|
+
<a href="https://ci.appveyor.com/project/ciscolive/aliyun-rails/branch/master"><img src="https://ci.appveyor.com/api/projects/status/uyepkk5bjbynofvu/branch/master?svg=true" alt="Build status"></a>
|
14
|
+
<a href="https://codecov.io/gh/ciscolive/aliyun-rails"><img src="https://codecov.io/gh/ciscolive/aliyun-rails/branch/master/graph/badge.svg" alt="codecov"></a>
|
15
|
+
</p>
|
16
|
+
|
17
|
+
|
18
|
+
- 支持 Rails 轻松访问阿里云服务,例如:弹性云主机(ECS)、负载均衡(SLB)、云监控(CloudMonitor)等。
|
19
|
+
- 已集成阿里云短信服务和语音服务,满足日常短信和电话告警需求。
|
20
|
+
|
21
|
+
本文档介绍如何安装和使用 aliyun-rails
|
22
|
+
|
23
|
+
## 使用诊断
|
24
|
+
|
25
|
+
[Troubleshoot](https://troubleshoot.api.aliyun.com/?source=github_sdk) 提供 OpenAPI 使用诊断服务,通过 `RequestID` 或 `报错信息`
|
26
|
+
,帮助开发者快速定位,为开发者提供解决方案。
|
27
|
+
|
28
|
+
## 安装
|
29
|
+
|
30
|
+
```sh
|
31
|
+
$ gem install aliyun-rails
|
32
|
+
```
|
33
|
+
|
34
|
+
## 使用
|
35
|
+
|
36
|
+
- 加载模块自动挂载几个常量:Dysms、Dyvms、RPCClient和ROAClient
|
37
|
+
|
38
|
+
CALL_TTS 实例:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require "aliyun-rails"
|
42
|
+
|
43
|
+
client = Aliyun::Dyvms.new(
|
44
|
+
access_key_id: ENV['ACCESS_KEY_ID'],
|
45
|
+
access_key_secret: ENV['ACCESS_KEY_SECRET'],
|
46
|
+
)
|
47
|
+
|
48
|
+
# 可以直接将API参数放到RAILS项目 * config/initializers *下
|
49
|
+
# Aliyun.config do |aliyun|
|
50
|
+
# aliyun.access_key_id = "XXX"
|
51
|
+
# aliyun.access_key_secret = "YYY"
|
52
|
+
# end
|
53
|
+
# 随后直接初始化
|
54
|
+
# client = Aliyun::Dyvms.new
|
55
|
+
|
56
|
+
# 调用语音方法 single_call_by_tts method
|
57
|
+
response = client.single_call_by_tts("075566668888", "13900001234", "TTS_CODE", { TTS_PARAM: 2022 })
|
58
|
+
|
59
|
+
puts response
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
SEND_SMS 示例:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require "aliyun-rails"
|
67
|
+
|
68
|
+
client = Aliyun::Dysms.new(
|
69
|
+
access_key_id: ENV['ACCESS_KEY_ID'],
|
70
|
+
access_key_secret: ENV['ACCESS_KEY_SECRET'],
|
71
|
+
)
|
72
|
+
|
73
|
+
# 可以直接将API参数放到RAILS项目 * config/initializers *下
|
74
|
+
# Aliyun.config do |aliyun|
|
75
|
+
# aliyun.access_key_id = "XXX"
|
76
|
+
# aliyun.access_key_secret = "YYY"
|
77
|
+
# end
|
78
|
+
# 随后直接初始化
|
79
|
+
# client = Dysms.new
|
80
|
+
|
81
|
+
# 调用短信方法 send_sms method
|
82
|
+
response = client.send_sms("1380000000", "SMS_10010", { param1: "11" }, "SIGN_NAME")
|
83
|
+
|
84
|
+
puts response
|
85
|
+
```
|
86
|
+
|
87
|
+
RPC 示例:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require 'aliyun-rails'
|
91
|
+
|
92
|
+
# 实例化对象
|
93
|
+
client = RPCClient.new(
|
94
|
+
endpoint: 'http://ros.aliyuncs.com',
|
95
|
+
api_version: '2015-09-01',
|
96
|
+
access_key_id: ENV['ACCESS_KEY_ID'],
|
97
|
+
access_key_secret: ENV['ACCESS_KEY_SECRET'],
|
98
|
+
security_token: 'TOKEN_KEY'
|
99
|
+
)
|
100
|
+
|
101
|
+
# 请求接口查询
|
102
|
+
params = { key: (1..11).to_a.map(&:to_s) }
|
103
|
+
request_option = { method: 'POST', timeout: 15000 }
|
104
|
+
response = client.request(
|
105
|
+
action: 'DescribeRegions',
|
106
|
+
params: params,
|
107
|
+
opts: request_option
|
108
|
+
)
|
109
|
+
|
110
|
+
puts response
|
111
|
+
|
112
|
+
```
|
113
|
+
|
114
|
+
ROA 示例:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
require 'aliyun-rails'
|
118
|
+
|
119
|
+
# 初始化对象
|
120
|
+
client = ROAClient.new(
|
121
|
+
endpoint: 'http://ros.aliyuncs.com',
|
122
|
+
api_version: '2015-09-01',
|
123
|
+
access_key_id: ENV['ACCESS_KEY_ID'],
|
124
|
+
access_key_secret: ENV['ACCESS_KEY_SECRET'],
|
125
|
+
)
|
126
|
+
|
127
|
+
# 请求接口查询
|
128
|
+
response = client.request(
|
129
|
+
method: 'GET',
|
130
|
+
uri: '/regions',
|
131
|
+
options: {
|
132
|
+
timeout: 15000
|
133
|
+
}
|
134
|
+
)
|
135
|
+
|
136
|
+
puts response.body
|
137
|
+
```
|
138
|
+
|
139
|
+
## 问题
|
140
|
+
|
141
|
+
[提交 Issue](https://github.com/ciscolive/aliyun-rails/issues/new/choose),不符合指南的问题可能会立即关闭。
|
142
|
+
|
143
|
+
## 发行说明
|
144
|
+
|
145
|
+
每个版本的详细更改记录在[发行说明](CHANGELOG.md)中。
|
146
|
+
|
147
|
+
## 贡献
|
148
|
+
|
149
|
+
提交 Pull Request 之前请阅读[贡献指南](CONTRIBUTING.md)。
|
150
|
+
|
151
|
+
## 许可证
|
152
|
+
|
153
153
|
[MIT](LICENSE.txt)
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
require "rubocop/rake_task"
|
5
|
-
|
6
|
-
RuboCop::RakeTask.new
|
7
|
-
|
8
|
-
task default: :rubocop
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rubocop/rake_task"
|
5
|
+
|
6
|
+
RuboCop::RakeTask.new
|
7
|
+
|
8
|
+
task default: :rubocop
|
@@ -1,166 +1,166 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "faraday"
|
4
|
-
require "securerandom"
|
5
|
-
require "active_support/all"
|
6
|
-
require "net/http"
|
7
|
-
|
8
|
-
module Net::HTTPHeader
|
9
|
-
def capitalize(name)
|
10
|
-
name
|
11
|
-
end
|
12
|
-
private :capitalize
|
13
|
-
end
|
14
|
-
|
15
|
-
module Aliyun
|
16
|
-
module Connector
|
17
|
-
class ROAClient
|
18
|
-
attr_accessor :endpoint, :api_version, :access_key_id,
|
19
|
-
:access_key_secret, :security_token, :hostname, :opts
|
20
|
-
|
21
|
-
def initialize(config)
|
22
|
-
validate config
|
23
|
-
|
24
|
-
self.endpoint = config[:endpoint]
|
25
|
-
self.api_version = config[:api_version]
|
26
|
-
self.access_key_id = config[:access_key_id]
|
27
|
-
self.access_key_secret = config[:access_key_secret]
|
28
|
-
self.security_token = config[:security_token]
|
29
|
-
end
|
30
|
-
|
31
|
-
def request(method:, uri:, params: {}, body: {}, headers: {}, options: {})
|
32
|
-
# :"Content-Type" => "application/json" to "content-type" => "application/json"
|
33
|
-
headers.deep_transform_keys! { |key| key.to_s.downcase }
|
34
|
-
mix_headers = default_headers.merge(headers)
|
35
|
-
|
36
|
-
response = connection.send(method.downcase) do |request|
|
37
|
-
request.url uri, params
|
38
|
-
if body
|
39
|
-
if mix_headers["content-type"].start_with? "application/json"
|
40
|
-
request_body = body.to_json
|
41
|
-
elsif mix_headers["content-type"].start_with? "application/x-www-form-urlencoded"
|
42
|
-
request_body = URI.encode_www_form(body)
|
43
|
-
else
|
44
|
-
request_body = body
|
45
|
-
end
|
46
|
-
mix_headers["content-md5"] = Digest::MD5.base64digest request_body
|
47
|
-
mix_headers["content-length"] = request_body.length.to_s
|
48
|
-
request.body = request_body
|
49
|
-
end
|
50
|
-
string2sign = string_to_sign(method, uri, mix_headers, params)
|
51
|
-
mix_headers[:authorization] = authorization(string2sign)
|
52
|
-
mix_headers.each { |key, value| request.headers[key] = value }
|
53
|
-
end
|
54
|
-
|
55
|
-
return response if options.has_key? :raw_body
|
56
|
-
|
57
|
-
response_content_type = response.headers["Content-Type"] || ""
|
58
|
-
if response_content_type.start_with?("application/json")
|
59
|
-
if response.status >= 400
|
60
|
-
result = JSON.parse(response.body)
|
61
|
-
raise StandardError, "code: #{response.status}, #{result['Message']} requestid: #{result['RequestId']}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
if response_content_type.start_with?("text/xml")
|
66
|
-
result = Hash.from_xml(response.body)
|
67
|
-
raise ACSError, result["Error"] if result["Error"]
|
68
|
-
end
|
69
|
-
|
70
|
-
response
|
71
|
-
end
|
72
|
-
|
73
|
-
def connection(adapter = Faraday.default_adapter)
|
74
|
-
Faraday.new(url: self.endpoint) { |f| f.adapter adapter }
|
75
|
-
end
|
76
|
-
|
77
|
-
def get(uri: "", headers: {}, params: {}, options: {})
|
78
|
-
request(method: :get, uri: uri, params: params, body: {}, headers: headers, options: options)
|
79
|
-
end
|
80
|
-
|
81
|
-
def post(uri: "", headers: {}, params: {}, body: {}, options: {})
|
82
|
-
request(method: :post, uri: uri, params: params, body: body, headers: headers, options: options)
|
83
|
-
end
|
84
|
-
|
85
|
-
def put(uri: "", headers: {}, params: {}, body: {}, options: {})
|
86
|
-
request(method: :put, uri: uri, params: params, body: body, headers: headers, options: options)
|
87
|
-
end
|
88
|
-
|
89
|
-
def delete(uri: "", headers: {}, params: {}, options: {})
|
90
|
-
request(method: :delete, uri: uri, params: params, body: {}, headers: headers, options: options)
|
91
|
-
end
|
92
|
-
|
93
|
-
def default_headers
|
94
|
-
default_headers = {
|
95
|
-
"accept" => "application/json",
|
96
|
-
"date" => Time.now.httpdate,
|
97
|
-
"host" => URI(self.endpoint).host,
|
98
|
-
"x-acs-signature-nonce" => SecureRandom.hex(16),
|
99
|
-
"x-acs-signature-method" => "HMAC-SHA1",
|
100
|
-
"x-acs-signature-version" => "1.0",
|
101
|
-
"x-acs-version" => self.api_version,
|
102
|
-
"x-sdk-client" => "RUBY(#{RUBY_VERSION})", # FIXME: 如何获取Gem的名称和版本号
|
103
|
-
"user-agent" => DEFAULT_UA
|
104
|
-
}
|
105
|
-
if self.security_token
|
106
|
-
default_headers["x-acs-accesskey-id"] = self.access_key_id
|
107
|
-
default_headers["x-acs-security-token"] = self.security_token
|
108
|
-
end
|
109
|
-
default_headers
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
def string_to_sign(method, uri, headers, query = {})
|
114
|
-
header_string = [
|
115
|
-
method,
|
116
|
-
headers["accept"],
|
117
|
-
headers["content-md5"] || "",
|
118
|
-
headers["content-type"] || "",
|
119
|
-
headers["date"],
|
120
|
-
].join("\n")
|
121
|
-
"#{header_string}\n#{canonicalized_headers(headers)}#{canonicalized_resource(uri, query)}"
|
122
|
-
end
|
123
|
-
|
124
|
-
def canonicalized_headers(headers)
|
125
|
-
headers.keys.select { |key| key.to_s.start_with? "x-acs-" }
|
126
|
-
.sort.map { |key| "#{key}:#{headers[key].strip}\n" }.join
|
127
|
-
end
|
128
|
-
|
129
|
-
def canonicalized_resource(uri, query_hash = {})
|
130
|
-
query_string = query_hash.sort.map { |key, value| "#{key}=#{value}" }.join("&")
|
131
|
-
query_string.empty? ? uri : "#{uri}?#{query_string}"
|
132
|
-
end
|
133
|
-
|
134
|
-
def authorization(string_to_sign)
|
135
|
-
"acs #{self.access_key_id}:#{signature(string_to_sign)}"
|
136
|
-
end
|
137
|
-
|
138
|
-
def signature(string_to_sign)
|
139
|
-
Base64.encode64(OpenSSL::HMAC.digest("sha1", self.access_key_secret, string_to_sign)).strip
|
140
|
-
end
|
141
|
-
|
142
|
-
def validate(config)
|
143
|
-
raise ArgumentError, 'must pass "config"' unless config
|
144
|
-
raise ArgumentError, 'must pass "config[:endpoint]"' unless config[:endpoint]
|
145
|
-
unless config[:endpoint].start_with?("http://") || config[:endpoint].start_with?("https://")
|
146
|
-
raise ArgumentError, '"config.endpoint" must starts with \'https://\' or \'http://\'.'
|
147
|
-
end
|
148
|
-
raise ArgumentError, 'must pass "config[:api_version]"' unless config[:api_version]
|
149
|
-
raise ArgumentError, 'must pass "config[:access_key_id]"' unless config[:access_key_id]
|
150
|
-
raise ArgumentError, 'must pass "config[:access_key_secret]"' unless config[:access_key_secret]
|
151
|
-
end
|
152
|
-
|
153
|
-
class ACSError < StandardError
|
154
|
-
attr_accessor :code
|
155
|
-
|
156
|
-
def initialize(error)
|
157
|
-
self.code = error["Code"]
|
158
|
-
message = error["Message"]
|
159
|
-
host_id = error["HostId"]
|
160
|
-
request_id = error["RequestId"]
|
161
|
-
super("#{message} host_id: #{host_id}, request_id: #{request_id}")
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "securerandom"
|
5
|
+
require "active_support/all"
|
6
|
+
require "net/http"
|
7
|
+
|
8
|
+
module Net::HTTPHeader
|
9
|
+
def capitalize(name)
|
10
|
+
name
|
11
|
+
end
|
12
|
+
private :capitalize
|
13
|
+
end
|
14
|
+
|
15
|
+
module Aliyun
|
16
|
+
module Connector
|
17
|
+
class ROAClient
|
18
|
+
attr_accessor :endpoint, :api_version, :access_key_id,
|
19
|
+
:access_key_secret, :security_token, :hostname, :opts
|
20
|
+
|
21
|
+
def initialize(config)
|
22
|
+
validate config
|
23
|
+
|
24
|
+
self.endpoint = config[:endpoint]
|
25
|
+
self.api_version = config[:api_version]
|
26
|
+
self.access_key_id = config[:access_key_id]
|
27
|
+
self.access_key_secret = config[:access_key_secret]
|
28
|
+
self.security_token = config[:security_token]
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(method:, uri:, params: {}, body: {}, headers: {}, options: {})
|
32
|
+
# :"Content-Type" => "application/json" to "content-type" => "application/json"
|
33
|
+
headers.deep_transform_keys! { |key| key.to_s.downcase }
|
34
|
+
mix_headers = default_headers.merge(headers)
|
35
|
+
|
36
|
+
response = connection.send(method.downcase) do |request|
|
37
|
+
request.url uri, params
|
38
|
+
if body
|
39
|
+
if mix_headers["content-type"].start_with? "application/json"
|
40
|
+
request_body = body.to_json
|
41
|
+
elsif mix_headers["content-type"].start_with? "application/x-www-form-urlencoded"
|
42
|
+
request_body = URI.encode_www_form(body)
|
43
|
+
else
|
44
|
+
request_body = body
|
45
|
+
end
|
46
|
+
mix_headers["content-md5"] = Digest::MD5.base64digest request_body
|
47
|
+
mix_headers["content-length"] = request_body.length.to_s
|
48
|
+
request.body = request_body
|
49
|
+
end
|
50
|
+
string2sign = string_to_sign(method, uri, mix_headers, params)
|
51
|
+
mix_headers[:authorization] = authorization(string2sign)
|
52
|
+
mix_headers.each { |key, value| request.headers[key] = value }
|
53
|
+
end
|
54
|
+
|
55
|
+
return response if options.has_key? :raw_body
|
56
|
+
|
57
|
+
response_content_type = response.headers["Content-Type"] || ""
|
58
|
+
if response_content_type.start_with?("application/json")
|
59
|
+
if response.status >= 400
|
60
|
+
result = JSON.parse(response.body)
|
61
|
+
raise StandardError, "code: #{response.status}, #{result['Message']} requestid: #{result['RequestId']}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if response_content_type.start_with?("text/xml")
|
66
|
+
result = Hash.from_xml(response.body)
|
67
|
+
raise ACSError, result["Error"] if result["Error"]
|
68
|
+
end
|
69
|
+
|
70
|
+
response
|
71
|
+
end
|
72
|
+
|
73
|
+
def connection(adapter = Faraday.default_adapter)
|
74
|
+
Faraday.new(url: self.endpoint) { |f| f.adapter adapter }
|
75
|
+
end
|
76
|
+
|
77
|
+
def get(uri: "", headers: {}, params: {}, options: {})
|
78
|
+
request(method: :get, uri: uri, params: params, body: {}, headers: headers, options: options)
|
79
|
+
end
|
80
|
+
|
81
|
+
def post(uri: "", headers: {}, params: {}, body: {}, options: {})
|
82
|
+
request(method: :post, uri: uri, params: params, body: body, headers: headers, options: options)
|
83
|
+
end
|
84
|
+
|
85
|
+
def put(uri: "", headers: {}, params: {}, body: {}, options: {})
|
86
|
+
request(method: :put, uri: uri, params: params, body: body, headers: headers, options: options)
|
87
|
+
end
|
88
|
+
|
89
|
+
def delete(uri: "", headers: {}, params: {}, options: {})
|
90
|
+
request(method: :delete, uri: uri, params: params, body: {}, headers: headers, options: options)
|
91
|
+
end
|
92
|
+
|
93
|
+
def default_headers
|
94
|
+
default_headers = {
|
95
|
+
"accept" => "application/json",
|
96
|
+
"date" => Time.now.httpdate,
|
97
|
+
"host" => URI(self.endpoint).host,
|
98
|
+
"x-acs-signature-nonce" => SecureRandom.hex(16),
|
99
|
+
"x-acs-signature-method" => "HMAC-SHA1",
|
100
|
+
"x-acs-signature-version" => "1.0",
|
101
|
+
"x-acs-version" => self.api_version,
|
102
|
+
"x-sdk-client" => "RUBY(#{RUBY_VERSION})", # FIXME: 如何获取Gem的名称和版本号
|
103
|
+
"user-agent" => DEFAULT_UA
|
104
|
+
}
|
105
|
+
if self.security_token
|
106
|
+
default_headers["x-acs-accesskey-id"] = self.access_key_id
|
107
|
+
default_headers["x-acs-security-token"] = self.security_token
|
108
|
+
end
|
109
|
+
default_headers
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
def string_to_sign(method, uri, headers, query = {})
|
114
|
+
header_string = [
|
115
|
+
method,
|
116
|
+
headers["accept"],
|
117
|
+
headers["content-md5"] || "",
|
118
|
+
headers["content-type"] || "",
|
119
|
+
headers["date"],
|
120
|
+
].join("\n")
|
121
|
+
"#{header_string}\n#{canonicalized_headers(headers)}#{canonicalized_resource(uri, query)}"
|
122
|
+
end
|
123
|
+
|
124
|
+
def canonicalized_headers(headers)
|
125
|
+
headers.keys.select { |key| key.to_s.start_with? "x-acs-" }
|
126
|
+
.sort.map { |key| "#{key}:#{headers[key].strip}\n" }.join
|
127
|
+
end
|
128
|
+
|
129
|
+
def canonicalized_resource(uri, query_hash = {})
|
130
|
+
query_string = query_hash.sort.map { |key, value| "#{key}=#{value}" }.join("&")
|
131
|
+
query_string.empty? ? uri : "#{uri}?#{query_string}"
|
132
|
+
end
|
133
|
+
|
134
|
+
def authorization(string_to_sign)
|
135
|
+
"acs #{self.access_key_id}:#{signature(string_to_sign)}"
|
136
|
+
end
|
137
|
+
|
138
|
+
def signature(string_to_sign)
|
139
|
+
Base64.encode64(OpenSSL::HMAC.digest("sha1", self.access_key_secret, string_to_sign)).strip
|
140
|
+
end
|
141
|
+
|
142
|
+
def validate(config)
|
143
|
+
raise ArgumentError, 'must pass "config"' unless config
|
144
|
+
raise ArgumentError, 'must pass "config[:endpoint]"' unless config[:endpoint]
|
145
|
+
unless config[:endpoint].start_with?("http://") || config[:endpoint].start_with?("https://")
|
146
|
+
raise ArgumentError, '"config.endpoint" must starts with \'https://\' or \'http://\'.'
|
147
|
+
end
|
148
|
+
raise ArgumentError, 'must pass "config[:api_version]"' unless config[:api_version]
|
149
|
+
raise ArgumentError, 'must pass "config[:access_key_id]"' unless config[:access_key_id]
|
150
|
+
raise ArgumentError, 'must pass "config[:access_key_secret]"' unless config[:access_key_secret]
|
151
|
+
end
|
152
|
+
|
153
|
+
class ACSError < StandardError
|
154
|
+
attr_accessor :code
|
155
|
+
|
156
|
+
def initialize(error)
|
157
|
+
self.code = error["Code"]
|
158
|
+
message = error["Message"]
|
159
|
+
host_id = error["HostId"]
|
160
|
+
request_id = error["RequestId"]
|
161
|
+
super("#{message} host_id: #{host_id}, request_id: #{request_id}")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -1,116 +1,147 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "
|
4
|
-
require "
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
1
|
+
require "set"
|
2
|
+
require "openssl"
|
3
|
+
require "faraday"
|
4
|
+
require "active_support/all"
|
5
|
+
|
6
|
+
module Aliyun
|
7
|
+
|
8
|
+
class RPCClient
|
9
|
+
|
10
|
+
attr_accessor :endpoint, :api_version, :access_key_id, :access_key_secret,
|
11
|
+
:security_token, :codes, :opts, :verbose
|
12
|
+
|
13
|
+
# 对象初始化属性
|
14
|
+
def initialize(config, verbose = false)
|
15
|
+
|
16
|
+
validate config
|
17
|
+
|
18
|
+
self.endpoint = config[:endpoint]
|
19
|
+
self.api_version = config[:api_version]
|
20
|
+
self.access_key_id = config[:access_key_id] || Aliyun.access_key_id
|
21
|
+
self.access_key_secret = config[:access_key_secret] || Aliyun.access_key_secret
|
22
|
+
self.security_token = config[:security_token]
|
23
|
+
self.opts = config[:opts] || {}
|
24
|
+
self.verbose = verbose.instance_of?(TrueClass) && verbose
|
25
|
+
|
26
|
+
self.codes = Set.new [200, "200", "OK", "Success"]
|
27
|
+
self.codes.merge config[:codes] if config[:codes]
|
28
|
+
end
|
29
|
+
|
30
|
+
# 通用请求接口
|
31
|
+
def request(action:, params: {}, opts: {})
|
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)])
|
44
|
+
|
45
|
+
# 转换为 query 样式
|
46
|
+
querystring = canonicalize(normalized)
|
47
|
+
|
48
|
+
# 特殊处理 POST
|
49
|
+
uri = opts[:method] == "POST" ? "/" : "/?#{querystring}"
|
50
|
+
|
51
|
+
# 初始化会话
|
52
|
+
response = connection.send(method.downcase, uri) do |request|
|
53
|
+
if opts[:method] == "POST"
|
54
|
+
request.headers["Content-Type"] = "application/x-www-form-urlencoded"
|
55
|
+
request.body = querystring
|
56
|
+
end
|
57
|
+
request.headers["User-Agent"] = DEFAULT_UA
|
58
|
+
end
|
59
|
+
|
60
|
+
# 解析接口响应
|
61
|
+
response_body = JSON.parse(response.body)
|
62
|
+
if response_body["Code"] && !response_body["Code"].to_s.empty? && !self.codes.include?(response_body["Code"])
|
63
|
+
raise StandardError, "Code: #{response_body['Code']}, Message: #{response_body['Message']}, URL: #{uri}"
|
64
|
+
end
|
65
|
+
|
66
|
+
response_body
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def connection(adapter = Faraday.default_adapter)
|
71
|
+
Faraday.new(url: self.endpoint) { |f| f.adapter adapter }
|
72
|
+
end
|
73
|
+
|
74
|
+
# 设置缺省参数
|
75
|
+
def default_params
|
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,
|
84
|
+
}
|
85
|
+
default_params["SecurityToken"] = self.security_token if self.security_token
|
86
|
+
default_params
|
87
|
+
end
|
88
|
+
|
89
|
+
# 消息签名需要
|
90
|
+
def encode(string)
|
91
|
+
ERB::Util.url_encode(string)
|
92
|
+
end
|
93
|
+
|
94
|
+
# 转换 HASH key 样式
|
95
|
+
def format_params(param_hash)
|
96
|
+
param_hash.keys.each { |key| param_hash[(key.to_s.upcase_first).to_sym] = param_hash.delete key }
|
97
|
+
param_hash
|
98
|
+
end
|
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
|
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
|
+
|
131
|
+
def validate(config = {})
|
132
|
+
config.with_indifferent_access
|
133
|
+
raise ArgumentError, 'must pass "config"' unless config
|
134
|
+
raise ArgumentError, 'must pass "config[:endpoint]"' unless config[:endpoint]
|
135
|
+
unless config[:endpoint].match?(/^http[s]?:/i)
|
136
|
+
raise ArgumentError, '"config.endpoint" must starts with \'https://\' or \'http://\'.'
|
137
|
+
end
|
138
|
+
raise ArgumentError, 'must pass "config[:api_version]"' unless config[:api_version]
|
139
|
+
unless config[:access_key_id] || Aliyun.access_key_id
|
140
|
+
raise ArgumentError, 'must pass "config[:access_key_id]" or define "Aliyun.access_key_id"'
|
141
|
+
end
|
142
|
+
unless config[:access_key_secret] || Aliyun.access_key_secret
|
143
|
+
raise ArgumentError, 'must pass "config[:access_key_secret]" or define "Aliyun.access_key_secret"'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/lib/aliyun/dysms.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Aliyun
|
4
|
-
class Dysms < Aliyun::Connector::RPCClient
|
5
|
-
# 本产品(Dysmsapi/2017-05-25)的OpenAPI采用RPC签名风格,签名细节参见签名机制说明。
|
6
|
-
# 我们已经为开发者封装了常见编程语言的SDK,开发者可通过下载SDK直接调用本产品OpenAPI而无需关心技术细节。
|
7
|
-
def initialize(config = {}, verbose = nil)
|
8
|
-
config[:endpoint] ||= "http://dysmsapi.aliyuncs.com"
|
9
|
-
config[:api_version] ||= "2017-05-25"
|
10
|
-
super(config, verbose)
|
11
|
-
end
|
12
|
-
|
13
|
-
# 发送短信,发送前要申请短信签名和短信模板,并确保签名和模板已审核通过。
|
14
|
-
def send_sms(phone_numbers, template_code, template_param, sign_name = "")
|
15
|
-
params = {
|
16
|
-
PhoneNumbers: phone_numbers,
|
17
|
-
SignName: sign_name,
|
18
|
-
TemplateCode: template_code,
|
19
|
-
TemplateParam: template_param.to_json
|
20
|
-
}
|
21
|
-
opts = { method: "POST", timeout: 15000 }
|
22
|
-
request(action: "SendSms", params: params, opts: opts)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aliyun
|
4
|
+
class Dysms < Aliyun::Connector::RPCClient
|
5
|
+
# 本产品(Dysmsapi/2017-05-25)的OpenAPI采用RPC签名风格,签名细节参见签名机制说明。
|
6
|
+
# 我们已经为开发者封装了常见编程语言的SDK,开发者可通过下载SDK直接调用本产品OpenAPI而无需关心技术细节。
|
7
|
+
def initialize(config = {}, verbose = nil)
|
8
|
+
config[:endpoint] ||= "http://dysmsapi.aliyuncs.com"
|
9
|
+
config[:api_version] ||= "2017-05-25"
|
10
|
+
super(config, verbose)
|
11
|
+
end
|
12
|
+
|
13
|
+
# 发送短信,发送前要申请短信签名和短信模板,并确保签名和模板已审核通过。
|
14
|
+
def send_sms(phone_numbers, template_code, template_param, sign_name = "")
|
15
|
+
params = {
|
16
|
+
PhoneNumbers: phone_numbers,
|
17
|
+
SignName: sign_name,
|
18
|
+
TemplateCode: template_code,
|
19
|
+
TemplateParam: template_param.to_json
|
20
|
+
}
|
21
|
+
opts = { method: "POST", timeout: 15000 }
|
22
|
+
request(action: "SendSms", params: params, opts: opts)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/aliyun/dyvms.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Aliyun
|
4
|
-
class Dyvms < Aliyun::Connector::RPCClient
|
5
|
-
# 本产品(Dyvmsapi/2017-05-25)的OpenAPI采用RPC签名风格,签名细节参见签名机制说明。
|
6
|
-
# 我们已经为开发者封装了常见编程语言的SDK,开发者可通过下载SDK直接调用本产品OpenAPI而无需关心技术细节。
|
7
|
-
def initialize(config = {}, verbose = nil)
|
8
|
-
config[:endpoint] ||= "http://dyvmsapi.aliyuncs.com"
|
9
|
-
config[:api_version] ||= "2017-05-25"
|
10
|
-
super(config, verbose)
|
11
|
-
end
|
12
|
-
|
13
|
-
# 调用SingleCallByTts接口向指定号码发送语音验证码和带参数变量的语音通知
|
14
|
-
def single_call_by_tts(called_show_number, called_number, tts_code, tts_param)
|
15
|
-
params = {
|
16
|
-
CalledShowNumber: called_show_number,
|
17
|
-
CalledNumber: called_number,
|
18
|
-
TtsCode: tts_code,
|
19
|
-
TtsParam: tts_param.to_json
|
20
|
-
}
|
21
|
-
opts = { method: "POST", timeout: 15000 }
|
22
|
-
request(action: "SendSms", params: params, opts: opts)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aliyun
|
4
|
+
class Dyvms < Aliyun::Connector::RPCClient
|
5
|
+
# 本产品(Dyvmsapi/2017-05-25)的OpenAPI采用RPC签名风格,签名细节参见签名机制说明。
|
6
|
+
# 我们已经为开发者封装了常见编程语言的SDK,开发者可通过下载SDK直接调用本产品OpenAPI而无需关心技术细节。
|
7
|
+
def initialize(config = {}, verbose = nil)
|
8
|
+
config[:endpoint] ||= "http://dyvmsapi.aliyuncs.com"
|
9
|
+
config[:api_version] ||= "2017-05-25"
|
10
|
+
super(config, verbose)
|
11
|
+
end
|
12
|
+
|
13
|
+
# 调用SingleCallByTts接口向指定号码发送语音验证码和带参数变量的语音通知
|
14
|
+
def single_call_by_tts(called_show_number, called_number, tts_code, tts_param)
|
15
|
+
params = {
|
16
|
+
CalledShowNumber: called_show_number,
|
17
|
+
CalledNumber: called_number,
|
18
|
+
TtsCode: tts_code,
|
19
|
+
TtsParam: tts_param.to_json
|
20
|
+
}
|
21
|
+
opts = { method: "POST", timeout: 15000 }
|
22
|
+
request(action: "SendSms", params: params, opts: opts)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/aliyun/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Aliyun
|
4
|
-
VERSION = "0.1.
|
5
|
-
DEFAULT_UA = "AlibabaCloud (#{Gem::Platform.local.os}; " +
|
6
|
-
"#{Gem::Platform.local.cpu}) Ruby/#{RUBY_VERSION} Core/#{VERSION}"
|
7
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aliyun
|
4
|
+
VERSION = "0.1.19"
|
5
|
+
DEFAULT_UA = "AlibabaCloud (#{Gem::Platform.local.os}; " +
|
6
|
+
"#{Gem::Platform.local.cpu}) Ruby/#{RUBY_VERSION} Core/#{VERSION}"
|
7
|
+
end
|
data/lib/aliyun-rails.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "aliyun/version"
|
4
|
-
require_relative "aliyun/connector/roa_client"
|
5
|
-
require_relative "aliyun/connector/rpc_client"
|
6
|
-
require_relative "aliyun/dysms"
|
7
|
-
require_relative "aliyun/dyvms"
|
8
|
-
|
9
|
-
module Aliyun
|
10
|
-
class Error < StandardError; end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Dyvms = Aliyun::Dyvms
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "aliyun/version"
|
4
|
+
require_relative "aliyun/connector/roa_client"
|
5
|
+
require_relative "aliyun/connector/rpc_client"
|
6
|
+
require_relative "aliyun/dysms"
|
7
|
+
require_relative "aliyun/dyvms"
|
8
|
+
|
9
|
+
module Aliyun
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
# 模块单例方法
|
13
|
+
class << self
|
14
|
+
attr_accessor :access_key_id, :access_key_secret
|
15
|
+
def config
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# 加载模块,自动初始化的常量
|
22
|
+
RPCClient = Aliyun::Connector::RPCClient
|
23
|
+
ROAClient = Aliyun::Connector::ROAClient
|
24
|
+
Dysms = Aliyun::Dysms
|
25
|
+
Dyvms = Aliyun::Dyvms
|
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.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WENWU.YAN
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -45,6 +45,10 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- CHANGELOG.md
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- CONTRIBUTING.md
|
51
|
+
- LICENSE.txt
|
48
52
|
- README.md
|
49
53
|
- Rakefile
|
50
54
|
- lib/aliyun-rails.rb
|
@@ -59,8 +63,8 @@ licenses:
|
|
59
63
|
metadata:
|
60
64
|
homepage_uri: https://github.com/ciscolive/aliyun-rails
|
61
65
|
source_code_uri: https://github.com/ciscolive/aliyun-rails
|
62
|
-
changelog_uri: https://github.com/ciscolive/aliyun-rails/blob/main/
|
63
|
-
post_install_message:
|
66
|
+
changelog_uri: https://github.com/ciscolive/aliyun-rails/blob/main/README.md
|
67
|
+
post_install_message:
|
64
68
|
rdoc_options: []
|
65
69
|
require_paths:
|
66
70
|
- lib
|
@@ -76,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
80
|
version: '0'
|
77
81
|
requirements: []
|
78
82
|
rubygems_version: 3.3.7
|
79
|
-
signing_key:
|
83
|
+
signing_key:
|
80
84
|
specification_version: 4
|
81
85
|
summary: 非阿里云官方SDK,本GEM主要实现RAILS项目轻松调用 ** aliyun ** 相关接口
|
82
86
|
test_files: []
|