roctogen 0.50.0

Github API and models generated from the official swagger OpenAPI specification
Documentation
//! Method, error and parameter types for the Emojis endpoint.
#![allow(
    clippy::all
)]
/* 
 * GitHub v3 REST API
 *
 * GitHub's v3 REST API.
 *
 * OpenAPI spec version: 1.1.4
 * 
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 */

use serde::Deserialize;

use roctokit::adapters::{AdapterError, Client, GitHubRequest, GitHubResponseExt};
use crate::models::*;

use super::PerPage;

use std::collections::HashMap;
use serde_json::value::Value;

pub struct Emojis<'api, C: Client> where AdapterError: From<<C as Client>::Err> {
    client: &'api C
}

pub fn new<C: Client>(client: &C) -> Emojis<C> where AdapterError: From<<C as Client>::Err> {
    Emojis { client }
}

/// Errors for the [Get emojis](Emojis::get_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum EmojisGetError {
    #[error("Not modified")]
    Status304,
    #[error("Status code: {}", code)]
    Generic { code: u16 },
}

impl From<EmojisGetError> for AdapterError {
    fn from(err: EmojisGetError) -> Self {
        let (description, status_code) = match err {
            EmojisGetError::Status304 => (String::from("Not modified"), 304),
            EmojisGetError::Generic { code } => (String::from("Generic"), code)
        };

        Self::Endpoint {
            description,
            status_code,
            source: Some(Box::new(err))
        }
    }
}



impl<'api, C: Client> Emojis<'api, C> where AdapterError: From<<C as Client>::Err> {
    /// ---
    ///
    /// # Get emojis
    ///
    /// Lists all the emojis available to use on GitHub.
    ///
    /// [GitHub API docs for get](https://docs.github.com/rest/emojis/emojis#get-emojis)
    ///
    /// ---
    pub async fn get_async(&self) -> Result<HashMap<String, String>, AdapterError> {

        let request_uri = format!("{}/emojis", super::GITHUB_BASE_API_URL);


        let req = GitHubRequest {
            uri: request_uri,
            body: None::<C::Body>,
            method: "GET",
            headers: vec![]
        };

        let request = self.client.build(req)?;

        // --

        let github_response = self.client.fetch_async(request).await?;

        // --

        if github_response.is_success() {
            Ok(github_response.to_json_async().await?)
        } else {
            match github_response.status_code() {
                304 => Err(EmojisGetError::Status304.into()),
                code => Err(EmojisGetError::Generic { code }.into()),
            }
        }
    }

    /// ---
    ///
    /// # Get emojis
    ///
    /// Lists all the emojis available to use on GitHub.
    ///
    /// [GitHub API docs for get](https://docs.github.com/rest/emojis/emojis#get-emojis)
    ///
    /// ---
    #[cfg(not(target_arch = "wasm32"))]
    pub fn get(&self) -> Result<HashMap<String, String>, AdapterError> {

        let request_uri = format!("{}/emojis", super::GITHUB_BASE_API_URL);


        let req = GitHubRequest {
            uri: request_uri,
            body: None,
            method: "GET",
            headers: vec![]
        };

        let request = self.client.build(req)?;

        // --

        let github_response = self.client.fetch(request)?;

        // --

        if github_response.is_success() {
            Ok(github_response.to_json()?)
        } else {
            match github_response.status_code() {
                304 => Err(EmojisGetError::Status304.into()),
                code => Err(EmojisGetError::Generic { code }.into()),
            }
        }
    }

}