#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct ResponseMeta {
pub request_id: Option<String>,
pub credits_used: Option<i64>,
pub credits_remaining: Option<i64>,
pub rate_limit_limit: Option<u32>,
pub rate_limit_remaining: Option<u32>,
pub rate_limit_reset: Option<u64>,
pub data_source: Option<String>,
}
#[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),
}
}
}