中文文档

Module Version Hex Docs Total Download Last Updated CI Coverage Status

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"}
  ]
end

Requirements

  • 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:

  1. compile --all-warnings --warnings-as-errors
  2. format --check-formatted
  3. credo --strict
  4. deps.unlock --check-unused
  5. deps.audit
  6. test --exclude external
  7. xref graph --label compile-connected --fail-above 0

Contributing

To add support for new Aliyun services:

  1. Add a new call_<service> function in lib/ex_aliyun_openapi.ex
  2. Add corresponding tests
  3. Submit a pull request

License

MIT