vynco 2.0.0

Rust SDK for the VynCo Swiss Corporate Intelligence API
Documentation
/// Metadata extracted from VynCo API response headers.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct ResponseMeta {
    /// Unique request identifier for tracing (`X-Request-Id`).
    pub request_id: Option<String>,
    /// Credits consumed by this request (`X-Credits-Used`).
    pub credits_used: Option<i64>,
    /// Remaining credit balance after this request (`X-Credits-Remaining`).
    pub credits_remaining: Option<i64>,
    /// Maximum requests per minute for the current tier (`X-RateLimit-Limit`).
    pub rate_limit_limit: Option<u32>,
    /// Remaining requests in the current rate limit window (`X-RateLimit-Remaining`).
    pub rate_limit_remaining: Option<u32>,
    /// Unix timestamp when the rate limit window resets (`X-RateLimit-Reset`).
    pub rate_limit_reset: Option<u64>,
    /// Data source attribution (`X-Data-Source`).
    pub data_source: Option<String>,
}

/// A response from the VynCo API, containing both the deserialized body and header metadata.
#[derive(Debug)]
pub struct Response<T> {
    pub data: T,
    pub meta: ResponseMeta,
}

impl ResponseMeta {
    pub(crate) fn from_headers(headers: &reqwest::header::HeaderMap) -> Self {
        Self {
            request_id: headers
                .get("X-Request-Id")
                .and_then(|v| v.to_str().ok())
                .map(String::from),
            credits_used: headers
                .get("X-Credits-Used")
                .and_then(|v| v.to_str().ok())
                .and_then(|v| v.parse().ok()),
            credits_remaining: headers
                .get("X-Credits-Remaining")
                .and_then(|v| v.to_str().ok())
                .and_then(|v| v.parse().ok()),
            rate_limit_limit: headers
                .get("X-RateLimit-Limit")
                .and_then(|v| v.to_str().ok())
                .and_then(|v| v.parse().ok()),
            rate_limit_remaining: headers
                .get("X-RateLimit-Remaining")
                .and_then(|v| v.to_str().ok())
                .and_then(|v| v.parse().ok()),
            rate_limit_reset: headers
                .get("X-RateLimit-Reset")
                .and_then(|v| v.to_str().ok())
                .and_then(|v| v.parse().ok()),
            data_source: headers
                .get("X-Data-Source")
                .and_then(|v| v.to_str().ok())
                .map(String::from),
        }
    }
}