35 个版本
0.7.0 | 2023 年 7 月 19 日 |
---|---|
0.4.0 | 2023 年 3 月 31 日 |
0.3.1 | 2022 年 11 月 18 日 |
0.2.9 | 2022 年 7 月 28 日 |
0.1.22 | 2021 年 7 月 9 日 |
#1 in #ramp
每月 95 次下载
190KB
4.5K SLoC
ramp-api
Ramp 的完全自动生成且具有意见的 API 客户端库。
API 详细信息
Ramp 的开发者 API 使公司能够以编程方式设置和管理其卡计划。
它提供自动化卡片发行的能力,并能够与其他软件平台集成功能,如报告。
客户端详细信息
此客户端基于 API 规范版本 1.0
从 Ramp OpenAPI 规范 生成。这样,当添加新功能时,它将保持最新。该软件包的文档与代码一起生成,以便轻松使用此库。
要安装库,请将以下内容添加到您的 Cargo.toml
文件中。
[dependencies]
ramp-api = "0.7.0"
基本示例
典型使用将需要初始化一个 Client
。这需要一个用户代理字符串和一组凭证。
use ramp_api::Client;
let ramp = Client::new(
String::from("client-id"),
String::from("client-secret"),
String::from("redirect-uri"),
String::from("token"),
String::from("refresh-token")
);
或者,库可以在环境中搜索客户端所需的多数变量
RAMP_CLIENT_ID
RAMP_CLIENT_SECRET
RAMP_REDIRECT_URI
然后您可以从环境中创建一个客户端。
use ramp_api::Client;
let ramp = Client::new_from_env(
String::from("token"),
String::from("refresh-token")
);
对于 token
和 refresh_token
可以传递空值。在客户端的初始状态下,您将不知道这些值。
要启动一个全新的客户端并获取 token
和 refresh_token
,请使用以下内容。
use ramp_api::Client;
async fn do_call() {
let mut ramp = Client::new_from_env("", "");
// Get the URL to request consent from the user.
// You can optionally pass in scopes. If none are provided, then the
// resulting URL will not have any scopes.
let user_consent_url = ramp.user_consent_url(&["some-scope".to_string()]);
// In your redirect URL capture the code sent and our state.
// Send it along to the request for the token.
let code = "thing-from-redirect-url";
let state = "state-from-redirect-url";
let mut access_token = ramp.get_access_token(code, state).await.unwrap();
// You can additionally refresh the access token with the following.
// You must have a refresh token to be able to call this function.
access_token = ramp.refresh_access_token().await.unwrap();
}
依赖项
~16–32MB
~619K SLoC