Skip to content

ciscolive/aliyun-rails

Repository files navigation

English | 简体中文

非官方SDK套件-用于RAILS项目管理阿里云相关资源,已集成接口鉴权、短信服务、和语音服务功能

Gem Version Build Status Build status codecov

  • 支持 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 之前请阅读贡献指南

许可证

MIT

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published