ubi-rs 0.1.3

A Rust cli and library for ubicloud API
Documentation
use crate::client::{HTTPClient, encode_param};
use crate::errors::UbiClientError;
use crate::{make_json_request, make_request};
use serde::Deserialize;
use serde::Serialize;
use std::sync::Arc;

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct ProjectList {
    pub count: u32,
    pub items: Vec<UserProject>,
}

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct UserProject {
    pub credit: f64,
    pub discount: u32,
    pub id: String,
    pub name: String,
}

pub struct Project {
    http_client: Arc<HTTPClient>,
}
impl Project {
    pub fn new(http_client: Arc<HTTPClient>) -> Self {
        Project { http_client }
    }

    /// List all projects visible to the logged in user.
    /// https://api.ubicloud.com/project
    ///
    pub async fn list_projects(&self) -> Result<ProjectList, UbiClientError> {
        let url = "project";
        make_request!(self, reqwest::Method::GET, url)
    }

    /// Create a new project
    /// https://api.ubicloud.com/project
    /// # Arguments:
    /// * `name` - The name of the project to create.
    pub async fn create_project(&self, name: &str) -> Result<UserProject, UbiClientError> {
        let url = "project";
        let body = serde_json::json!({
            "name": name,
        });
        let query = [(); 0];
        make_json_request!(self, reqwest::Method::POST, url, body, query, UserProject)
    }

    /// Delete a project
    /// https://api.ubicloud.com/project/{project_id}
    /// # Arguments:
    /// * `project_id` - The ID of the project to delete.
    pub async fn delete_project(&self, project_id: &str) -> Result<(), UbiClientError> {
        let url = format!("project/{}", encode_param(project_id));
        make_request!(self, reqwest::Method::DELETE, &url)
    }
}