ExAliyun.OpenAPI
Description
ExAliyun.OpenAPI provides Elixir clients for Aliyun (Alibaba Cloud) OpenAPI services:
- CPS (Cloud Push Service)
- STS (Security Token Service)
- SMS (Short Message Service)
- Captcha (验证码2.0 / Human Verification)
- CodeUp (DevOps Project Management)
- GeoIP (IP Geolocation)
Installation
Add ex_aliyun_openapi to your mix.exs:
def deps do
[
{:ex_aliyun_openapi, "~> 1.0"}
]
endRequirements
- Elixir 1.18+
- Erlang/OTP 27+
Configuration
Configure your Aliyun credentials per service:
config :ex_aliyun_openapi, :cps,
access_key_id: "YOUR ACCESS KEY ID",
access_key_secret: "YOUR ACCESS KEY SECRET"
config :ex_aliyun_openapi, :sts,
access_key_id: "YOUR ACCESS KEY ID",
access_key_secret: "YOUR ACCESS KEY SECRET"
Supported service keys: :cps, :sts, :sms, :global_sms, :captcha, :codeup, :geoip
Usage
Find the API parameters at Aliyun API Reference, then call the corresponding function:
# STS - AssumeRole
params = %{
"Action" => "AssumeRole",
"RoleArn" => "acs:ram::1234567890:role/your-role",
"RoleSessionName" => "default",
"DurationSeconds" => 3600
}
ExAliyun.OpenAPI.call_sts(params)
# Alternatively, pass credentials inline:
ExAliyun.OpenAPI.call_sts(params, access_key_id: "ID", access_key_secret: "SECRET")# CPS - Push Notification
params = %{
"Action" => "PushNoticeToAndroid",
"AppKey" => "YOUR_APP_KEY",
"Target" => "DEVICE",
"TargetValue" => "YOUR_DEVICE_ID",
"Title" => "Test Title",
"Body" => "Hello, this is the notice body"
}
ExAliyun.OpenAPI.call_cps(params)# CodeUp - Create Task
ExAliyun.OpenAPI.CodeUp.call_task(%{
"Action" => "CreateDevopsProjectTask",
"OrgId" => "your_org_id",
"ProjectId" => "your_project_id",
"Content" => "Task content"
})CI Pipeline
This project includes a mix ci alias that runs:
compile --all-warnings --warnings-as-errorsformat --check-formattedcredo --strictdeps.unlock --check-unuseddeps.audittest --exclude externalxref graph --label compile-connected --fail-above 0
Contributing
To add support for new Aliyun services:
-
Add a new
call_<service>function inlib/ex_aliyun_openapi.ex - Add corresponding tests
- Submit a pull request
License
MIT