space-traders 0.1.1

Async SpaceTraders API client for Rust.
Documentation
//! API endpoints for SpaceTraders.
//!
//! Generated by: <https://openapi-generator.tech>
//!
//! Version of specification: `2.0.0`

/// Content of a response.
#[derive(Debug, Clone)]
pub struct ResponseContent<T> {
    /// The status of the response.
    ///
    /// The response enums for each endpoint function are already split up
    /// by status code so this shouldn't really be needed in practice.
    pub status: reqwest::StatusCode,

    /// The raw response body as text.
    ///
    /// This can be used to extract information from the response if the schema
    /// does not include the data.
    pub response_body: String,

    /// The deserialized content of the response.
    pub content: T,
}

/// Error from interacting with an API endpoint.
#[derive(thiserror::Error, Debug)]
pub enum Error<T> {
    /// Error from `request`.
    #[error("error performing request: {0}")]
    Reqwest(#[from] reqwest::Error),

    /// Error from `serde_json`.
    #[error("error deserializing: {0}")]
    Serde(#[from] serde_json::Error),

    /// Error response from the endpoint.
    #[error("got error response: {} - {}", .0.status, .0.response_body)]
    ResponseError(ResponseContent<T>),

    /// An unknown response was received.
    ///
    /// This response was not defined by the schema.
    #[error("got unknown response: {status} - {response_body}")]
    UnknownResponse {
        is_error: bool,
        status: reqwest::StatusCode,
        response_body: String,
    },
}

fn urlencode<T: AsRef<str>>(s: T) -> String {
    ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
}

pub mod agents_api;
pub mod contracts_api;
pub mod default_api;
pub mod factions_api;
pub mod fleet_api;
pub mod systems_api;

mod configuration;
pub use configuration::*;