Added API id & secret
This commit is contained in:
parent
7cd9107838
commit
55af3e1455
|
@ -5,13 +5,19 @@ use crate::prelude::*;
|
|||
/// Account endpoint group
|
||||
#[derive(Debug)]
|
||||
pub struct AccountGroup {
|
||||
pub client: reqwest::Client,
|
||||
client: reqwest::Client,
|
||||
api_id: String,
|
||||
api_secret: String,
|
||||
}
|
||||
|
||||
impl AccountGroup {
|
||||
/// Return a new [`AccountGroup`]
|
||||
pub fn new(client: reqwest::Client) -> Self {
|
||||
Self { client }
|
||||
pub fn new(client: reqwest::Client, api_id: &str, api_secret: &str) -> Self {
|
||||
Self {
|
||||
client,
|
||||
api_id: api_id.to_string(),
|
||||
api_secret: api_secret.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return information about your account
|
||||
|
@ -19,6 +25,7 @@ impl AccountGroup {
|
|||
Ok(self
|
||||
.client
|
||||
.get(format!("{}/v1/account", BASE_URL))
|
||||
.basic_auth(&self.api_id, Some(&self.api_secret))
|
||||
.send()
|
||||
.await?
|
||||
.process_error()
|
||||
|
|
|
@ -8,7 +8,7 @@ pub struct Construct {
|
|||
|
||||
impl Construct {
|
||||
/// Return a new [`Construct`]
|
||||
pub fn new() -> Self {
|
||||
pub fn new(api_id: &str, api_secret: &str) -> Self {
|
||||
// Build HTTP client
|
||||
let client = reqwest::ClientBuilder::new()
|
||||
.user_agent(concat!("Construct", "/", env!("CARGO_PKG_VERSION")))
|
||||
|
@ -16,7 +16,7 @@ impl Construct {
|
|||
.unwrap();
|
||||
|
||||
Self {
|
||||
account: AccountGroup::new(client),
|
||||
account: AccountGroup::new(client, api_id, api_secret),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use construct::Construct;
|
|||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Create new Construct
|
||||
let construct = Construct::new();
|
||||
let construct = Construct::new("id", "secret");
|
||||
|
||||
// Fetch account information
|
||||
let account = construct.account.fetch().await.unwrap();
|
||||
|
|
Loading…
Reference in New Issue