1
2
3
4
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! Aliyun OpenAPI POP core SDK for Rust.
//!
//! # Notes
//!
//! You must know your `AK`(`accessKeyId/accessKeySecret`), and the aliyun product's `endpoint` and `apiVersion`.
//!
//! For example, The ECS OpenAPI(https://help.aliyun.com/document_detail/25490.html), the API version is `2014-05-26`.
//!
//! And the endpoint list can be found at [here](https://help.aliyun.com/document_detail/25489.html), the center endpoint is ecs.aliyuncs.com. Add http protocol `http` or `https`, should be `http://ecs.aliyuncs.com/`.
//!
//! # Usage
//!
//! The RPC style client:
//!
//! ```no_run
//! use aliyun_openapi_core_rust_sdk::client::rpc::RPClient;
//! use std::error::Error;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//!     // create rpc style api client.
//!     let aliyun_openapi_client = RPClient::new(
//!         "<access_key_id>",
//!         "<access_key_secret>",
//!         "<endpoint>",
//!     );
//!
//!     // call `DescribeInstances` with queries.
//!     let response = aliyun_openapi_client
//!         .get("DescribeInstances")
//!         .query([("RegionId", "cn-hangzhou")])
//!         .text().await?;
//!
//!     println!("DescribeInstances response: {response}");
//!
//!     Ok(())
//! }
//! ```
//!
//! The ROA style client:
//!
//! ```no_run
//! use aliyun_openapi_core_rust_sdk::client::roa::ROAClient;
//! use serde_json::json;
//! use std::collections::HashMap;
//! use std::env;
//! use std::error::Error;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//!     // create roa style api client.
//!     let aliyun_openapi_client = ROAClient::new(
//!         env::var("ACCESS_KEY_ID")?,
//!         env::var("ACCESS_KEY_SECRET")?,
//!         "http://mt.aliyuncs.com",
//!     );
//!
//!     // create params.
//!     let mut params = HashMap::new();
//!     params.insert("SourceText", "你好");
//!     params.insert("SourceLanguage", "zh");
//!     params.insert("TargetLanguage", "en");
//!     params.insert("FormatType", "text");
//!     params.insert("Scene", "general");
//!
//!     // call `Translate` with json params.
//!     let response = aliyun_openapi_client
//!         .version("2018-04-08")
//!         .post("/api/translate/web/general")
//!         .header([("Content-Type".to_string(), "application/json".to_string())])?
//!         .body(json!(params).to_string())?
//!         .text()
//!         .await?;
//!
//!     println!("Translate response: {response}");
//!
//!     Ok(())
//! }
//! ```
//! # Examples
//!
//! Export AK info to env, then run `cargo run --example <NAME>`:
//!
//! ```sh
//! export ACCESS_KEY_ID=<access_key_id>
//! export ACCESS_KEY_SECRET=<access_key_secret>
//!
//! # ecs example
//! cargo run --example ecs
//!
//! # rds example
//! cargo run --example rds
//!
//! # slb example
//! cargo run --example slb
//!
//! # vpc example
//! cargo run --example vpc
//! ```
#![allow(deprecated)]

mod roa;
mod rpc;

#[deprecated(
    since = "1.0.0",
    note = "Please use the `aliyun_openapi_core_rust_sdk::client::roa::ROAClient` instead"
)]
pub use crate::roa::Client as ROAClient;

#[deprecated(
    since = "1.0.0",
    note = "Please use the `aliyun_openapi_core_rust_sdk::client::rpc::RPClient` instead"
)]
pub use crate::rpc::Client as RPClient;

pub mod client;

pub trait OpenAPI<'a> {
    type Output: 'a;

    /// Create a `GET` request with the `uri`.
    ///
    /// Returns a `RequestBuilder` for send request.
    fn get(&'a self, uri: &str) -> Self::Output {
        self.execute("GET", uri)
    }

    /// Create a `POST` request with the `uri`.
    ///
    /// Returns a `RequestBuilder` for send request.
    fn post(&'a self, uri: &str) -> Self::Output {
        self.execute("POST", uri)
    }

    /// Create a `PUT` request with the `uri`.
    ///
    /// Returns a `RequestBuilder` for send request.
    fn put(&'a self, uri: &str) -> Self::Output {
        self.execute("PUT", uri)
    }

    /// Create a request with the `method` and `uri`.
    ///
    /// Returns a `RequestBuilder` for send request.
    fn execute(&'a self, method: &str, uri: &str) -> Self::Output;
}