mirror of
https://github.com/tribufu/sdk-rust
synced 2025-06-15 18:54:19 +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/
|
||||
[Ii]ntermediate/
|
||||
__pycache__/
|
||||
.gradle/
|
||||
.idea/
|
||||
.metals/
|
||||
.next/
|
||||
.parcel-cache/
|
||||
.vs/
|
||||
.vscode/
|
||||
bin/
|
||||
binaries/
|
||||
build/
|
||||
node_modules/
|
||||
obj/
|
||||
saved/
|
||||
target/
|
||||
|
||||
.DS_Store
|
||||
.env
|
||||
*.crt
|
||||
*.csproj
|
||||
*.filters
|
||||
*.fsproj
|
||||
*.key
|
||||
*.log
|
||||
*.make
|
||||
*.mwb.bak
|
||||
*.pem
|
||||
*.sln
|
||||
*.user
|
||||
*.vcxproj
|
||||
*.vpp.*
|
||||
*.wasm
|
||||
*.xcodeproj
|
||||
*.xcworkspace
|
||||
Cargo.lock
|
||||
desktop.ini
|
||||
keystore.jks
|
||||
local.properties
|
||||
Makefile
|
||||
next-env.d.ts
|
||||
|
28
Cargo.toml
28
Cargo.toml
@ -1,24 +1,28 @@
|
||||
[package]
|
||||
name = "tribufu"
|
||||
version = "0.0.3"
|
||||
description = "TribuFu SDK"
|
||||
repository = "https://github.com/TribuFu/SDK-RS"
|
||||
authors = ["TribuFu <contact@tribufu.com>"]
|
||||
version = "0.0.4"
|
||||
description = "Tribufu SDK"
|
||||
repository = "https://github.com/Tribufu/SDK-Rust"
|
||||
authors = ["Tribufu <contact@tribufu.com>"]
|
||||
license = "Apache-2.0"
|
||||
readme = "README.md"
|
||||
edition = "2021"
|
||||
publish = true
|
||||
|
||||
exclude = [
|
||||
".github/",
|
||||
".vscode/",
|
||||
".editorconfig",
|
||||
".gitattributes",
|
||||
]
|
||||
exclude = [".github/", ".vscode/", ".editorconfig", ".gitattributes"]
|
||||
|
||||
[lib]
|
||||
name = "TribuFu"
|
||||
name = "tribufu"
|
||||
crate-type = ["rlib"]
|
||||
path = "Source/lib.rs"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[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
|
||||
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");
|
||||
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