English | 简体中文
- 支持 Rails 轻松访问阿里云服务,例如:弹性云主机(ECS)、负载均衡(SLB)、云监控(CloudMonitor)等。
- 已集成阿里云短信服务和语音服务,满足日常短信和电话告警需求。
本文档介绍如何安装和使用 aliyun-rails
Troubleshoot 提供 OpenAPI 使用诊断服务,通过 RequestID
或 报错信息
,帮助开发者快速定位,为开发者提供解决方案。
$ gem install aliyun-rails
- 加载模块自动挂载几个常量:Dysms、Dyvms、RPCClient和ROAClient
CALL_TTS 实例:
require "aliyun-rails"
client = Aliyun::Dyvms.new(
access_key_id: ENV['ACCESS_KEY_ID'],
access_key_secret: ENV['ACCESS_KEY_SECRET'],
)
# 可以直接将API参数放到RAILS项目 * config/initializers *下
# Aliyun.config do |aliyun|
# aliyun.access_key_id = "XXX"
# aliyun.access_key_secret = "YYY"
# end
# 随后直接初始化
# client = Aliyun::Dyvms.new
# 调用语音方法 single_call_by_tts method
response = client.single_call_by_tts("075566668888", "13900001234", "TTS_CODE", { TTS_PARAM: 2022 })
puts response
SEND_SMS 示例:
require "aliyun-rails"
client = Aliyun::Dysms.new(
access_key_id: ENV['ACCESS_KEY_ID'],
access_key_secret: ENV['ACCESS_KEY_SECRET'],
)
# 可以直接将API参数放到RAILS项目 * config/initializers *下
# Aliyun.config do |aliyun|
# aliyun.access_key_id = "XXX"
# aliyun.access_key_secret = "YYY"
# end
# 随后直接初始化
# client = Dysms.new
# 调用短信方法 send_sms method
response = client.send_sms("1380000000", "SMS_10010", { param1: "11" }, "SIGN_NAME")
puts response
RPC 示例:
require 'aliyun-rails'
# 实例化对象
client = RPCClient.new(
endpoint: 'http://ros.aliyuncs.com',
api_version: '2015-09-01',
access_key_id: ENV['ACCESS_KEY_ID'],
access_key_secret: ENV['ACCESS_KEY_SECRET'],
security_token: 'TOKEN_KEY'
)
# 请求接口查询
params = { key: (1..11).to_a.map(&:to_s) }
request_option = { method: 'POST', timeout: 15000 }
response = client.request(
action: 'DescribeRegions',
params: params,
opts: request_option
)
puts response
ROA 示例:
require 'aliyun-rails'
# 初始化对象
client = ROAClient.new(
endpoint: 'http://ros.aliyuncs.com',
api_version: '2015-09-01',
access_key_id: ENV['ACCESS_KEY_ID'],
access_key_secret: ENV['ACCESS_KEY_SECRET'],
)
# 请求接口查询
response = client.request(
method: 'GET',
uri: '/regions',
options: {
timeout: 15000
}
)
puts response.body
提交 Issue,不符合指南的问题可能会立即关闭。
每个版本的详细更改记录在发行说明中。
提交 Pull Request 之前请阅读贡献指南。