Added API id & secret

This commit is contained in:
perp 2024-05-25 00:07:07 +01:00
parent 7cd9107838
commit 55af3e1455
3 changed files with 13 additions and 6 deletions

View File

@ -5,13 +5,19 @@ use crate::prelude::*;
/// Account endpoint group /// Account endpoint group
#[derive(Debug)] #[derive(Debug)]
pub struct AccountGroup { pub struct AccountGroup {
pub client: reqwest::Client, client: reqwest::Client,
api_id: String,
api_secret: String,
} }
impl AccountGroup { impl AccountGroup {
/// Return a new [`AccountGroup`] /// Return a new [`AccountGroup`]
pub fn new(client: reqwest::Client) -> Self { pub fn new(client: reqwest::Client, api_id: &str, api_secret: &str) -> Self {
Self { client } Self {
client,
api_id: api_id.to_string(),
api_secret: api_secret.to_string(),
}
} }
/// Return information about your account /// Return information about your account
@ -19,6 +25,7 @@ impl AccountGroup {
Ok(self Ok(self
.client .client
.get(format!("{}/v1/account", BASE_URL)) .get(format!("{}/v1/account", BASE_URL))
.basic_auth(&self.api_id, Some(&self.api_secret))
.send() .send()
.await? .await?
.process_error() .process_error()

View File

@ -8,7 +8,7 @@ pub struct Construct {
impl Construct { impl Construct {
/// Return a new [`Construct`] /// Return a new [`Construct`]
pub fn new() -> Self { pub fn new(api_id: &str, api_secret: &str) -> Self {
// Build HTTP client // Build HTTP client
let client = reqwest::ClientBuilder::new() let client = reqwest::ClientBuilder::new()
.user_agent(concat!("Construct", "/", env!("CARGO_PKG_VERSION"))) .user_agent(concat!("Construct", "/", env!("CARGO_PKG_VERSION")))
@ -16,7 +16,7 @@ impl Construct {
.unwrap(); .unwrap();
Self { Self {
account: AccountGroup::new(client), account: AccountGroup::new(client, api_id, api_secret),
} }
} }
} }

View File

@ -3,7 +3,7 @@ use construct::Construct;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
// Create new Construct // Create new Construct
let construct = Construct::new(); let construct = Construct::new("id", "secret");
// Fetch account information // Fetch account information
let account = construct.account.fetch().await.unwrap(); let account = construct.account.fetch().await.unwrap();