scaleway-rs 0.2.1

A pure Rust scaleway API binding.
Documentation
use crate::ScalewayApi;
use crate::ScalewayError;
use crate::data::project::ScalewayProject;
use serde::Serialize;

#[derive(Serialize, Debug)]
struct CreateProjectConfig {
    name: String,
    organization_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    description: Option<String>,
}

pub struct ScalewayCreateProjectBuilder {
    api: ScalewayApi,
    config: CreateProjectConfig,
}

impl ScalewayCreateProjectBuilder {
    pub fn new(api: ScalewayApi, name: &str, organization_id: &str) -> Self {
        ScalewayCreateProjectBuilder {
            api,
            config: CreateProjectConfig {
                name: name.to_string(),
                organization_id: organization_id.to_string(),
                description: None,
            },
        }
    }

    pub fn description(mut self, description: &str) -> ScalewayCreateProjectBuilder {
        self.config.description = Some(description.to_string());
        self
    }

    #[cfg(feature = "blocking")]
    pub fn run(self) -> Result<ScalewayProject, ScalewayError> {
        Ok(self
            .api
            .post("https://api.scaleway.com/account/v3/projects", self.config)?
            .json::<ScalewayProject>()?)
    }

    pub async fn run_async(self) -> Result<ScalewayProject, ScalewayError> {
        Ok(self
            .api
            .post_async("https://api.scaleway.com/account/v3/projects", self.config)
            .await?
            .json::<ScalewayProject>()
            .await?)
    }
}