pub struct GitHubClient { /* private fields */ }Expand description
GitHub API client for authenticated operations.
The main client for interacting with GitHub’s REST API. Handles authentication, rate limiting, retries, and provides both app-level and installation-level operations.
§Examples
let client = GitHubClient::builder(auth)
.config(ClientConfig::default())
.build()?;
// Get app information
let app = client.get_app().await?;
println!("App: {}", app.name);Implementations§
Source§impl GitHubClient
impl GitHubClient
Sourcepub async fn installation_by_id(
&self,
installation_id: InstallationId,
) -> Result<InstallationClient, ApiError>
pub async fn installation_by_id( &self, installation_id: InstallationId, ) -> Result<InstallationClient, ApiError>
Source§impl GitHubClient
impl GitHubClient
Sourcepub fn builder(
auth: impl AuthenticationProvider + 'static,
) -> GitHubClientBuilder
pub fn builder( auth: impl AuthenticationProvider + 'static, ) -> GitHubClientBuilder
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Get the client configuration.
Sourcepub fn auth_provider(&self) -> &dyn AuthenticationProvider
pub fn auth_provider(&self) -> &dyn AuthenticationProvider
Get the authentication provider.
Sourcepub async fn get_app(&self) -> Result<App, ApiError>
pub async fn get_app(&self) -> Result<App, ApiError>
Get details about the authenticated GitHub App.
Fetches metadata about the app including ID, name, owner, and permissions.
§Authentication
Requires app-level JWT authentication.
§Examples
let app = client.get_app().await?;
println!("App: {} (ID: {})", app.name, app.id);§Errors
Returns ApiError if:
- JWT generation fails
- HTTP request fails
- Response cannot be parsed
Sourcepub async fn list_installations(&self) -> Result<Vec<Installation>, ApiError>
pub async fn list_installations(&self) -> Result<Vec<Installation>, ApiError>
List all installations for the authenticated GitHub App.
Fetches all installations where this app is installed, including organizations and user accounts.
§Authentication
Requires app-level JWT authentication.
§Examples
let installations = client.list_installations().await?;
for installation in installations {
println!("Installation ID: {} for {}", installation.id.as_u64(), installation.account.login);
}§Errors
Returns ApiError if:
- JWT generation fails
- HTTP request fails
- Response cannot be parsed
Sourcepub async fn get_installation(
&self,
installation_id: InstallationId,
) -> Result<Installation, ApiError>
pub async fn get_installation( &self, installation_id: InstallationId, ) -> Result<Installation, ApiError>
Get a specific installation by ID.
Fetches detailed information about a specific installation of this GitHub App.
§Authentication
Requires app-level JWT authentication.
§Arguments
installation_id- The unique identifier for the installation
§Examples
let installation_id = InstallationId::new(12345);
let installation = client.get_installation(installation_id).await?;
println!("Installation for: {}", installation.account.login);§Errors
Returns ApiError if:
- JWT generation fails
- HTTP request fails
- Installation not found (404)
- Response cannot be parsed
Sourcepub async fn get_as_app(&self, path: &str) -> Result<Response, ApiError>
pub async fn get_as_app(&self, path: &str) -> Result<Response, ApiError>
Make a raw authenticated GET request as the GitHub App.
This is a generic method for making custom API requests that aren’t covered by the specific methods. Returns the raw response for flexible handling by the caller.
§Authentication
Requires app-level JWT authentication.
§Arguments
path- The API path (e.g., “/app/installations” or “app/installations”)
§Examples
// Make a custom GET request
let response = client.get_as_app("/app/hook/config").await?;
if response.status().is_success() {
let data: serde_json::Value = response.json().await?;
println!("Response: {:?}", data);
}§Errors
Returns ApiError if:
- JWT generation fails
- HTTP request fails (network error, timeout, etc.)
Note: Does NOT return an error for non-2xx status codes. The caller is responsible for checking the response status.
Sourcepub async fn post_as_app(
&self,
path: &str,
body: &impl Serialize,
) -> Result<Response, ApiError>
pub async fn post_as_app( &self, path: &str, body: &impl Serialize, ) -> Result<Response, ApiError>
Make a raw authenticated POST request as the GitHub App.
This is a generic method for making custom API requests that aren’t covered by the specific methods. Returns the raw response for flexible handling by the caller.
§Authentication
Requires app-level JWT authentication.
§Arguments
path- The API path (e.g., “/app/installations/{id}/suspended”)body- The request body to serialize as JSON
§Examples
// Make a custom POST request
let body = serde_json::json!({"reason": "Violation of terms"});
let response = client.post_as_app("/app/installations/123/suspended", &body).await?;
if response.status().is_success() {
println!("Installation suspended");
}§Errors
Returns ApiError if:
- JWT generation fails
- Body serialization fails
- HTTP request fails (network error, timeout, etc.)
Note: Does NOT return an error for non-2xx status codes. The caller is responsible for checking the response status.
Trait Implementations§
Source§impl Clone for GitHubClient
impl Clone for GitHubClient
Source§fn clone(&self) -> GitHubClient
fn clone(&self) -> GitHubClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more