coinpaprika_api/key/
mod.rs

1use crate::client::{Client, Response};
2use crate::error::Error;
3use reqwest_middleware::RequestBuilder;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Serialize, Deserialize)]
7/// Requests made and left stats
8pub struct CurrentMonthUsage {
9    /// Number of requests made in the current month. If a plan has no limit on the number of
10    /// requests, e.g., `Enterprise` plan, then the value of `requests_made` is -1
11    pub requests_made: i32,
12
13    /// Number of requests left in the current month. If a plan has no limit on the number of
14    /// requests, e.g., `Enterprise` plan, then the value of `requests_left` is -1
15    pub requests_left: i32,
16}
17
18#[derive(Debug, Serialize, Deserialize)]
19/// Monthly usage for the API key
20pub struct KeyUsage {
21    /// `limited plan` if the number of requests is limited in the current plan or `unlimited plan`
22    /// if there is no limit on the number of requests
23    pub message: String,
24
25    /// Requests made and left stats
26    pub current_month: CurrentMonthUsage,
27}
28
29#[derive(Debug, Serialize, Deserialize)]
30/// API key information
31pub struct KeyInfo {
32    /// Name of the API plan
33    pub plan: String,
34
35    /// A date when the plan started in RFC3999 (ISO-8601) format
36    pub plan_started_at: String,
37
38    /// Status of the plan. There are 3 possible statuses: `active` - the subscription is active;
39    /// `past_due` - the subscription payment failed. If payment is not made within 7 days, then
40    /// the subscription will expire; `inactive` - the subscription is inactive.
41    pub plan_status: String,
42
43    /// API Customer Portal URL
44    pub portal_url: String,
45
46    /// Monthly usage for the API key
47    pub usage: KeyUsage,
48}
49
50/// Request for getting API key information
51/// [/key/info](https://api.coinpaprika.com/#tag/Key/paths/~1key~1info/get)
52pub struct GetKeyInfoRequest<'a> {
53    client: &'a Client,
54}
55
56impl<'a> GetKeyInfoRequest<'a> {
57    pub fn new(client: &'a Client) -> Self {
58        Self { client }
59    }
60
61    pub async fn send(&self) -> Result<KeyInfo, Error> {
62        let request: RequestBuilder = self
63            .client
64            .client
65            .get(format!("{}/key/info", self.client.api_url));
66
67        let response: Response = self.client.request(request).await?;
68
69        let data: KeyInfo = response.response.json().await?;
70
71        Ok(data)
72    }
73}