mirror of
https://github.com/tribufu/sdk-rust
synced 2025-06-16 11:14:17 +00:00
Add oauth2 client
This commit is contained in:
@ -1,2 +0,0 @@
|
|||||||
[build]
|
|
||||||
target-dir = "Intermediate/Target"
|
|
38
.gitignore
vendored
38
.gitignore
vendored
@ -1,6 +1,40 @@
|
|||||||
[Bb]inaries/
|
__pycache__/
|
||||||
[Ii]ntermediate/
|
.gradle/
|
||||||
|
.idea/
|
||||||
|
.metals/
|
||||||
|
.next/
|
||||||
|
.parcel-cache/
|
||||||
|
.vs/
|
||||||
|
.vscode/
|
||||||
|
bin/
|
||||||
|
binaries/
|
||||||
|
build/
|
||||||
|
node_modules/
|
||||||
|
obj/
|
||||||
|
saved/
|
||||||
|
target/
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.env
|
||||||
|
*.crt
|
||||||
|
*.csproj
|
||||||
|
*.filters
|
||||||
|
*.fsproj
|
||||||
|
*.key
|
||||||
|
*.log
|
||||||
|
*.make
|
||||||
|
*.mwb.bak
|
||||||
|
*.pem
|
||||||
|
*.sln
|
||||||
|
*.user
|
||||||
|
*.vcxproj
|
||||||
|
*.vpp.*
|
||||||
|
*.wasm
|
||||||
|
*.xcodeproj
|
||||||
|
*.xcworkspace
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
desktop.ini
|
desktop.ini
|
||||||
|
keystore.jks
|
||||||
|
local.properties
|
||||||
|
Makefile
|
||||||
|
next-env.d.ts
|
||||||
|
28
Cargo.toml
28
Cargo.toml
@ -1,24 +1,28 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tribufu"
|
name = "tribufu"
|
||||||
version = "0.0.3"
|
version = "0.0.4"
|
||||||
description = "TribuFu SDK"
|
description = "Tribufu SDK"
|
||||||
repository = "https://github.com/TribuFu/SDK-RS"
|
repository = "https://github.com/Tribufu/SDK-Rust"
|
||||||
authors = ["TribuFu <contact@tribufu.com>"]
|
authors = ["Tribufu <contact@tribufu.com>"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = true
|
publish = true
|
||||||
|
|
||||||
exclude = [
|
exclude = [".github/", ".vscode/", ".editorconfig", ".gitattributes"]
|
||||||
".github/",
|
|
||||||
".vscode/",
|
|
||||||
".editorconfig",
|
|
||||||
".gitattributes",
|
|
||||||
]
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "TribuFu"
|
name = "tribufu"
|
||||||
crate-type = ["rlib"]
|
crate-type = ["rlib"]
|
||||||
path = "Source/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
alnilam-consts = { version = "0.0.4" }
|
||||||
|
anyhow = "1.0.75"
|
||||||
|
derive_more = "0.99.17"
|
||||||
|
reqwest = { version = "0.11.18", features = ["json", "stream"] }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = { version = "1.0", features = ["raw_value"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
@ -186,7 +186,7 @@
|
|||||||
same "printed page" as the copyright notice for easier
|
same "printed page" as the copyright notice for easier
|
||||||
identification within third-party archives.
|
identification within third-party archives.
|
||||||
|
|
||||||
Copyright (c) TribuFu. All Rights Reserved
|
Copyright (c) Tribufu. All Rights Reserved
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
// Copyright (c) TribuFu. All Rights Reserved
|
|
||||||
|
|
||||||
#![allow(non_snake_case)]
|
|
||||||
|
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
11
examples/client.rs
Normal file
11
examples/client.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (c) Tribufu. All Rights Reserved
|
||||||
|
|
||||||
|
use tribufu::*;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
match TribufuClient::new(0, "client_secret") {
|
||||||
|
Ok(client) => println!("client_id: {}", client.id()),
|
||||||
|
Err(e) => println!("error: {:?}", e),
|
||||||
|
}
|
||||||
|
}
|
58
src/lib.rs
Normal file
58
src/lib.rs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// Copyright (c) Tribufu. All Rights Reserved.
|
||||||
|
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use alnilam_consts::TARGET_TRIPLE;
|
||||||
|
use anyhow::Result;
|
||||||
|
use reqwest::header::{HeaderMap, HeaderValue};
|
||||||
|
use reqwest::Client;
|
||||||
|
|
||||||
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct TribufuClient {
|
||||||
|
client_id: u64,
|
||||||
|
client_secret: String,
|
||||||
|
http: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TribufuClient {
|
||||||
|
const BASE_URL: &'static str = "https://api.tribufu.com";
|
||||||
|
|
||||||
|
pub fn new(id: u64, secret: impl Into<String>) -> Result<TribufuClient> {
|
||||||
|
let user_agent = format!(
|
||||||
|
"Tribufu/{} (+https://api.tribufu.com; {})",
|
||||||
|
VERSION, TARGET_TRIPLE
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut headers = HeaderMap::new();
|
||||||
|
headers.insert("X-Tribufu-Language", HeaderValue::from_static("rust"));
|
||||||
|
headers.insert("X-Tribufu-Version", HeaderValue::from_static(VERSION));
|
||||||
|
|
||||||
|
let http = Client::builder()
|
||||||
|
.default_headers(headers)
|
||||||
|
.user_agent(user_agent)
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
Ok(TribufuClient {
|
||||||
|
client_id: id,
|
||||||
|
client_secret: secret.into(),
|
||||||
|
http,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> u64 {
|
||||||
|
self.client_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_client() {
|
||||||
|
let client = TribufuClient::new(0, "client_secret").unwrap();
|
||||||
|
assert_eq!(client.id(), 0);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user