1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//! Method, error and parameter types for the RateLimit 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 RateLimit<'api, C: Client> where AdapterError: From<<C as Client>::Err> {
client: &'api C
}
pub fn new<C: Client>(client: &C) -> RateLimit<C> where AdapterError: From<<C as Client>::Err> {
RateLimit { client }
}
/// Errors for the [Get rate limit status for the authenticated user](RateLimit::get_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum RateLimitGetError {
#[error("Not modified")]
Status304,
#[error("Resource not found")]
Status404(BasicError),
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<RateLimitGetError> for AdapterError {
fn from(err: RateLimitGetError) -> Self {
let (description, status_code) = match err {
RateLimitGetError::Status304 => (String::from("Not modified"), 304),
RateLimitGetError::Status404(_) => (String::from("Resource not found"), 404),
RateLimitGetError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
impl<'api, C: Client> RateLimit<'api, C> where AdapterError: From<<C as Client>::Err> {
/// ---
///
/// # Get rate limit status for the authenticated user
///
/// > [!NOTE]
/// > Accessing this endpoint does not count against your REST API rate limit.
///
/// Some categories of endpoints have custom rate limits that are separate from the rate limit governing the other REST API endpoints. For this reason, the API response categorizes your rate limit. Under `resources`, you'll see objects relating to different categories:
/// * The `core` object provides your rate limit status for all non-search-related resources in the REST API.
/// * The `search` object provides your rate limit status for the REST API for searching (excluding code searches). For more information, see "[Search](https://docs.github.com/rest/search/search)."
/// * The `code_search` object provides your rate limit status for the REST API for searching code. For more information, see "[Search code](https://docs.github.com/rest/search/search#search-code)."
/// * The `graphql` object provides your rate limit status for the GraphQL API. For more information, see "[Resource limitations](https://docs.github.com/graphql/overview/resource-limitations#rate-limit)."
/// * The `integration_manifest` object provides your rate limit status for the `POST /app-manifests/{code}/conversions` operation. For more information, see "[Creating a GitHub App from a manifest](https://docs.github.com/apps/creating-github-apps/setting-up-a-github-app/creating-a-github-app-from-a-manifest#3-you-exchange-the-temporary-code-to-retrieve-the-app-configuration)."
/// * The `dependency_snapshots` object provides your rate limit status for submitting snapshots to the dependency graph. For more information, see "[Dependency graph](https://docs.github.com/rest/dependency-graph)."
/// * The `dependency_sbom` object provides your rate limit status for requesting SBOMs from the dependency graph. For more information, see "[Dependency graph](https://docs.github.com/rest/dependency-graph)."
/// * The `code_scanning_upload` object provides your rate limit status for uploading SARIF results to code scanning. For more information, see "[Uploading a SARIF file to GitHub](https://docs.github.com/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github)."
/// * The `actions_runner_registration` object provides your rate limit status for registering self-hosted runners in GitHub Actions. For more information, see "[Self-hosted runners](https://docs.github.com/rest/actions/self-hosted-runners)."
/// * The `source_import` object is no longer in use for any API endpoints, and it will be removed in the next API version. For more information about API versions, see "[API Versions](https://docs.github.com/rest/about-the-rest-api/api-versions)."
///
/// > [!NOTE]
/// > The `rate` object is closing down. If you're writing new API client code or updating existing code, you should use the `core` object instead of the `rate` object. The `core` object contains the same information that is present in the `rate` object.
///
/// [GitHub API docs for get](https://docs.github.com/rest/rate-limit/rate-limit#get-rate-limit-status-for-the-authenticated-user)
///
/// ---
pub async fn get_async(&self) -> Result<RateLimitOverview, AdapterError> {
let request_uri = format!("{}/rate_limit", 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(RateLimitGetError::Status304.into()),
404 => Err(RateLimitGetError::Status404(github_response.to_json_async().await?).into()),
code => Err(RateLimitGetError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get rate limit status for the authenticated user
///
/// > [!NOTE]
/// > Accessing this endpoint does not count against your REST API rate limit.
///
/// Some categories of endpoints have custom rate limits that are separate from the rate limit governing the other REST API endpoints. For this reason, the API response categorizes your rate limit. Under `resources`, you'll see objects relating to different categories:
/// * The `core` object provides your rate limit status for all non-search-related resources in the REST API.
/// * The `search` object provides your rate limit status for the REST API for searching (excluding code searches). For more information, see "[Search](https://docs.github.com/rest/search/search)."
/// * The `code_search` object provides your rate limit status for the REST API for searching code. For more information, see "[Search code](https://docs.github.com/rest/search/search#search-code)."
/// * The `graphql` object provides your rate limit status for the GraphQL API. For more information, see "[Resource limitations](https://docs.github.com/graphql/overview/resource-limitations#rate-limit)."
/// * The `integration_manifest` object provides your rate limit status for the `POST /app-manifests/{code}/conversions` operation. For more information, see "[Creating a GitHub App from a manifest](https://docs.github.com/apps/creating-github-apps/setting-up-a-github-app/creating-a-github-app-from-a-manifest#3-you-exchange-the-temporary-code-to-retrieve-the-app-configuration)."
/// * The `dependency_snapshots` object provides your rate limit status for submitting snapshots to the dependency graph. For more information, see "[Dependency graph](https://docs.github.com/rest/dependency-graph)."
/// * The `dependency_sbom` object provides your rate limit status for requesting SBOMs from the dependency graph. For more information, see "[Dependency graph](https://docs.github.com/rest/dependency-graph)."
/// * The `code_scanning_upload` object provides your rate limit status for uploading SARIF results to code scanning. For more information, see "[Uploading a SARIF file to GitHub](https://docs.github.com/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github)."
/// * The `actions_runner_registration` object provides your rate limit status for registering self-hosted runners in GitHub Actions. For more information, see "[Self-hosted runners](https://docs.github.com/rest/actions/self-hosted-runners)."
/// * The `source_import` object is no longer in use for any API endpoints, and it will be removed in the next API version. For more information about API versions, see "[API Versions](https://docs.github.com/rest/about-the-rest-api/api-versions)."
///
/// > [!NOTE]
/// > The `rate` object is closing down. If you're writing new API client code or updating existing code, you should use the `core` object instead of the `rate` object. The `core` object contains the same information that is present in the `rate` object.
///
/// [GitHub API docs for get](https://docs.github.com/rest/rate-limit/rate-limit#get-rate-limit-status-for-the-authenticated-user)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get(&self) -> Result<RateLimitOverview, AdapterError> {
let request_uri = format!("{}/rate_limit", 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(RateLimitGetError::Status304.into()),
404 => Err(RateLimitGetError::Status404(github_response.to_json()?).into()),
code => Err(RateLimitGetError::Generic { code }.into()),
}
}
}
}