pub struct LcuClient { /* private fields */ }
Expand description
Struct representing a connection to the LCU
Implementations§
Source§impl LcuClient
impl LcuClient
Sourcepub async fn batched<'a, R>(
&self,
requests: &[Request<'a>],
buffer_size: usize,
request_client: &RequestClient,
) -> Vec<Result<Option<R>, Error>>where
R: DeserializeOwned,
pub async fn batched<'a, R>(
&self,
requests: &[Request<'a>],
buffer_size: usize,
request_client: &RequestClient,
) -> Vec<Result<Option<R>, Error>>where
R: DeserializeOwned,
System for batching requests to the LCU by sending a slice The buffer size is how many requests can be operated on at the same time, returns a vector with all the replies
§Errors
The value will be an error if the provided type is invalid, or the LCU API is not running
Source§impl LcuClient
impl LcuClient
Sourcepub fn new(force_lock_file: bool) -> Result<Self, Error>
pub fn new(force_lock_file: bool) -> Result<Self, Error>
Attempts to create a connection to the LCU, errors if it fails to spin up the child process, or fails to get data from the client.
force_lock_file will read the lock file regardless of whether the client or the game is running at the time
§Errors
This will return an error if the LCU API is not running, this can include the client being down, the lock file being unable to be opened, or the LCU not running at all
Sourcepub fn new_with_credentials(auth: &str, port: u16) -> LcuClient
pub fn new_with_credentials(auth: &str, port: u16) -> LcuClient
Creates a new LCU Client that implicitly trusts the port and auth string given, Encoding them in a URL and header respectively
Sourcepub fn reconnect(&mut self, force_lock_file: bool) -> Result<(), Error>
pub fn reconnect(&mut self, force_lock_file: bool) -> Result<(), Error>
Queries the client or lock file, getting a new url and auth header
§Errors
This will return an error if the lock file is inaccessible, or if the LCU is not running
Sourcepub fn reconnect_with_credentials(&mut self, auth: &str, port: u16)
pub fn reconnect_with_credentials(&mut self, auth: &str, port: u16)
Sets the url and auth header according to the auth and port provided
Sourcepub fn auth_header(&self) -> &str
pub fn auth_header(&self) -> &str
Returns a reference to the auth header in use
Sourcepub async fn delete<R: DeserializeOwned>(
&self,
endpoint: impl AsRef<str>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>
pub async fn delete<R: DeserializeOwned>( &self, endpoint: impl AsRef<str>, request_client: &RequestClient, ) -> Result<Option<R>, Error>
Sends a delete request to the LCU
§Errors
This will return an error if the LCU API is not running, or the provided type is invalid
Sourcepub async fn get<R: DeserializeOwned>(
&self,
endpoint: impl AsRef<str>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>
pub async fn get<R: DeserializeOwned>( &self, endpoint: impl AsRef<str>, request_client: &RequestClient, ) -> Result<Option<R>, Error>
Sends a get request to the LCU
let request_client = irelia::RequestClient::new();
let lcu_client = irelia::rest::LcuClient::new(false)?;
let response: Option<serde_json::Value> = lcu_client.get("/example/endpoint/", &request_client)?;
§Errors
This will return an error if the LCU API is not running, or the provided type is invalid
Sourcepub async fn head<S>(
&self,
endpoint: impl AsRef<str>,
request_client: &RequestClient,
) -> Result<Response<Incoming>, Error>
pub async fn head<S>( &self, endpoint: impl AsRef<str>, request_client: &RequestClient, ) -> Result<Response<Incoming>, Error>
Sourcepub async fn patch<T, R>(
&self,
endpoint: impl AsRef<str>,
body: Option<T>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>where
T: Serialize,
R: DeserializeOwned,
pub async fn patch<T, R>(
&self,
endpoint: impl AsRef<str>,
body: Option<T>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>where
T: Serialize,
R: DeserializeOwned,
Sends a patch request to the LCU
§Errors
This will return an error if the LCU API is not running, or the provided type or body is invalid
Sourcepub async fn post<T, R>(
&self,
endpoint: impl AsRef<str>,
body: Option<T>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>where
T: Serialize,
R: DeserializeOwned,
pub async fn post<T, R>(
&self,
endpoint: impl AsRef<str>,
body: Option<T>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>where
T: Serialize,
R: DeserializeOwned,
Sends a post request to the LCU
§Errors
This will return an error if the LCU API is not running, or the provided type or body is invalid
Sourcepub async fn put<T, R>(
&self,
endpoint: impl AsRef<str>,
body: Option<T>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>where
T: Serialize,
R: DeserializeOwned,
pub async fn put<T, R>(
&self,
endpoint: impl AsRef<str>,
body: Option<T>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>where
T: Serialize,
R: DeserializeOwned,
Sends a put request to the LCU
§Errors
This will return an error if the LCU API is not running, or the provided type or body is invalid
Sourcepub async fn schema(remote: &'static str) -> Result<Schema, Error>
pub async fn schema(remote: &'static str) -> Result<Schema, Error>
Fetches the schema from a remote endpoint, for example:
<https://raw.githubusercontent.com/dysolix/hasagi-types/main/swagger.json/
>
§Errors
This function will error if it fails to connect to the given remote,
or if the given remote cannot be deserialized to match the Schema
type
Sourcepub async fn lcu_request<T: Serialize, R: DeserializeOwned>(
&self,
endpoint: &str,
method: &str,
body: Option<T>,
request_client: &RequestClient,
) -> Result<Option<R>, Error>
pub async fn lcu_request<T: Serialize, R: DeserializeOwned>( &self, endpoint: &str, method: &str, body: Option<T>, request_client: &RequestClient, ) -> Result<Option<R>, Error>
Makes a request to the LCU with an unspecified method, valid options being “PUT”, “GET”, “POST”, “HEAD”, “DELETE”
§Errors
This will return an error if the LCU API is not running, or the provided type or body is invalid