pub struct Client { /* private fields */ }Expand description
An HTTP client for making authenticated requests to the GitHub API.
Wraps a reqwest::blocking::Client and automatically attaches
the appropriate Authorization header and Accept header.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(hostname: &str) -> Result<Self, GorError>
pub fn new(hostname: &str) -> Result<Self, GorError>
Create a new Client for the given host.
Attempts to load a stored token from the OS keyring. If no token is found, the client is created in an unauthenticated state.
§Examples
use gor::client::Client;
let client = Client::new("github.com").unwrap();§Errors
Returns an error if the reqwest client cannot be created.
Sourcepub const fn is_authenticated(&self) -> bool
pub const fn is_authenticated(&self) -> bool
Returns true if the client has an auth token.
Sourcepub fn get(&self, path: &str) -> Result<Response, GorError>
pub fn get(&self, path: &str) -> Result<Response, GorError>
Make a GET request to the given API path.
The path should start with /, e.g. /user.
§Errors
Returns an error if the HTTP request fails.
Sourcepub fn get_absolute(&self, url: &str) -> Result<Response, GorError>
pub fn get_absolute(&self, url: &str) -> Result<Response, GorError>
Make a GET request to an absolute URL (not API-path-based).
Used for downloading release assets from the GitHub CDN.
§Errors
Returns an error if the HTTP request fails.
Sourcepub fn request(
&self,
method: &str,
path: &str,
headers: &[String],
body: Option<Vec<u8>>,
) -> Result<Response, GorError>
pub fn request( &self, method: &str, path: &str, headers: &[String], body: Option<Vec<u8>>, ) -> Result<Response, GorError>
Make a request with an arbitrary HTTP method, headers, and optional body.
The path should start with /, e.g. /repos/owner/repo.
headers is a slice of “Key: Value” strings.
body is an optional raw byte vector for the request body.
§Errors
Returns an error if the HTTP request fails.
Sourcepub fn post<T: Serialize>(
&self,
path: &str,
body: &T,
) -> Result<Response, GorError>
pub fn post<T: Serialize>( &self, path: &str, body: &T, ) -> Result<Response, GorError>
Make a POST request to the given API path with a JSON body.
§Errors
Returns an error if the HTTP request fails.
Sourcepub fn post_form_url(
&self,
url: &str,
form: &HashMap<&str, &str>,
) -> Result<Response, GorError>
pub fn post_form_url( &self, url: &str, form: &HashMap<&str, &str>, ) -> Result<Response, GorError>
Make a POST request to an absolute URL (not API-path-based) with form data.
Used for OAuth device flow endpoints which live on the main host, not the API subdomain.
§Errors
Returns an error if the HTTP request fails.
Sourcepub fn graphql(
&self,
query: &str,
variables: Option<Value>,
) -> Result<Value, GorError>
pub fn graphql( &self, query: &str, variables: Option<Value>, ) -> Result<Value, GorError>
Make a GraphQL API request.
Sends a POST request to the GraphQL endpoint with the given query and optional variables.
§Errors
Returns an error if the HTTP request fails.
Sourcepub fn upload_asset(
&self,
upload_url: &str,
data: &[u8],
content_type: &str,
) -> Result<Response, GorError>
pub fn upload_asset( &self, upload_url: &str, data: &[u8], content_type: &str, ) -> Result<Response, GorError>
Upload a release asset to the given upload URL.
GitHub release asset uploads use a separate domain (uploads.github.com) and require the content type to be set explicitly.
§Errors
Returns an error if the HTTP request fails.