https://github.com/straylittlepunk/tencent3
https://github.com/straylittlepunk/tencent3
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/straylittlepunk/tencent3
- Owner: StrayLittlePunk
- License: apache-2.0
- Created: 2023-02-22T16:43:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-22T17:01:49.000Z (over 3 years ago)
- Last Synced: 2025-04-14T12:50:55.592Z (about 1 year ago)
- Language: Rust
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Overview
A Rusty Tencent Api Client with v3 authorization. Only machine translation api is supported now, other apis are not supported at present
## Example
```rust
fn build_client() -> TencentClient> {
let client = TencentClient::native(client::Credential {
key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".to_string(),
id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".to_string(),
});
client
}
fn main() {
let client = build_client();
let call = client
.translate()
.text_translate()
.source("it") // Italy
.target("zh")
.project_id(PROJECT_ID)
.region("REGION")
.source_text("Credere è destino")
.build()
.unwrap();
// {"Response":{"RequestId":"38b2df48-48e6-4aa5-ace4-xxxxxxxxx","Source":"it","Target":"zh","TargetText":"相信就是命运"}}
let result = call
.doit(|body| {
let string = String::from_utf8(body).unwrap();
let value = serde_json::from_str::(&string).unwrap();
let text = value
.get("Response")
.and_then(|res| res.get("TargetText"))
.and_then(|e| e.as_str())
.unwrap();
assert_eq!(text, "相信就是命运");
})
.await;
}
```
## The API is structured into the following primary items:
### Client
- a central object to maintain state and allow accessing all Activities
- creates Method Builders which in turn allow access to individual Call Builders
### Resources
- primary types that you can apply Activities to
- a collection of properties and Parts
### Parts
- a collection of properties never directly used in Activities
### Activities
- operations to apply to Resources