scaleway-rs 0.2.7

A pure Rust scaleway API binding.
Documentation
use crate::ScalewayApi;
use crate::ScalewayError;
use crate::data::ssh_key::ScalewaySSHKey;

/// Builder for fetching a single SSH key.
///
/// Created by [`ScalewayApi::get_ssh_key`](crate::ScalewayApi::get_ssh_key).
/// Call [`run`](Self::run) or [`run_async`](Self::run_async) to execute.
pub struct ScalewayGetSSHKeyBuilder {
    api: ScalewayApi,
    ssh_key_id: String,
}

impl ScalewayGetSSHKeyBuilder {
    pub fn new(api: ScalewayApi, ssh_key_id: &str) -> Self {
        ScalewayGetSSHKeyBuilder {
            api,
            ssh_key_id: ssh_key_id.to_string(),
        }
    }

    /// Fetches the SSH key (blocking).
    #[cfg(feature = "blocking")]
    pub fn run(self) -> Result<ScalewaySSHKey, ScalewayError> {
        Ok(self
            .api
            .get(
                &format!(
                    "https://api.scaleway.com/iam/v1alpha1/ssh-keys/{ssh_key_id}",
                    ssh_key_id = self.ssh_key_id
                ),
                vec![],
            )?
            .json::<ScalewaySSHKey>()?)
    }

    /// Fetches the SSH key.
    pub async fn run_async(self) -> Result<ScalewaySSHKey, ScalewayError> {
        Ok(self
            .api
            .get_async(
                &format!(
                    "https://api.scaleway.com/iam/v1alpha1/ssh-keys/{ssh_key_id}",
                    ssh_key_id = self.ssh_key_id
                ),
                vec![],
            )
            .await?
            .json::<ScalewaySSHKey>()
            .await?)
    }
}