pub struct WallhavenClient { /* private fields */ }Expand description
A wallhaven api client.
There are two ways of constructing this object, with or without an api key,
see WallhavenClient::new and WallhavenClient::with_key for more details
§Examples
client.wallpaper("someid").await?;
client.search(None).await?;
let req = SearchRequestBuilder::default().build()?;
client.search(Some(req)).await?;And so on! Check out each methods/models for more informations
Implementations§
Source§impl WallhavenClient
impl WallhavenClient
Sourcepub fn with_key(api_key: impl AsRef<str>) -> Result<Self, Error>
pub fn with_key(api_key: impl AsRef<str>) -> Result<Self, Error>
Constructs WallhavenClient with an api key
Check out WallhavenClient::new to construct an instance without an api key.
The api key will be passed to the X-API-Key headers.
§Errors
Error::InvalidApiKeywhen an invalid api key is passed as argumentError::BuildingClientwhen something went wrong with the Client builder, this shouldn’t happen and you probably should file an issue
Sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Constructs WallhavenClient without an api key.
Check out WallhavenClient::with_key to construct an instance with an api key.
§Errors
Error::BuildingClientwhen something went wrong with the Client builder, this shouldn’t happen and you probably should file an issue
Sourcepub async fn wallpaper(
&self,
id: impl AsRef<str>,
) -> Result<WallpaperDetails, Error>
pub async fn wallpaper( &self, id: impl AsRef<str>, ) -> Result<WallpaperDetails, Error>
Fetches a wallpaper by id
§Errors
Error::UrlParsingErrorwhen the URL cannot be parsedError::SendingRequestan error while sending the request, you can get more details with the underlying errorError::DecodingJsonan error decoding the JSON, either wallhaven sent a wrong json, or we wrote a bad modelError::UnknownRequestError- an unknown error when sending/receiving the request, you can match further the underlying error
Sourcepub async fn search(
&self,
params: Option<SearchRequest>,
) -> Result<SearchResult, Error>
pub async fn search( &self, params: Option<SearchRequest>, ) -> Result<SearchResult, Error>
Searches for wallpapers matching the request
§Errors
Error::UrlParsingErrorwhen the URL cannot be parsedError::SendingRequestan error while sending the request, you can get more details with the underlying errorError::DecodingJsonan error decoding the JSON, either wallhaven sent a wrong json, or we wrote a bad modelError::UnknownRequestError- an unknown error when sending/receiving the request, you can match further the underlying error
Sourcepub async fn collections(
&self,
username: impl Into<Option<String>>,
) -> Result<Vec<UserCollection>, Error>
pub async fn collections( &self, username: impl Into<Option<String>>, ) -> Result<Vec<UserCollection>, Error>
Fetches all the UserCollection of a certain user
Defaults to the current if no username is provided and an api key is used
§Errors
Error::UrlParsingErrorwhen the URL cannot be parsedError::SendingRequestan error while sending the request, you can get more details with the underlying errorError::DecodingJsonan error decoding the JSON, either wallhaven sent a wrong json, or we wrote a bad modelError::UnknownRequestError- an unknown error when sending/receiving the request, you can match further the underlying error
Sourcepub async fn collection_items(
&self,
username: impl AsRef<str>,
id: u64,
params: Option<CollectionItemsRequest>,
) -> Result<SearchResult, Error>
pub async fn collection_items( &self, username: impl AsRef<str>, id: u64, params: Option<CollectionItemsRequest>, ) -> Result<SearchResult, Error>
Gets the collection’s wallpapers.
§Errors
Error::UrlParsingErrorwhen the URL cannot be parsedError::SendingRequestan error while sending the request, you can get more details with the underlying errorError::DecodingJsonan error decoding the JSON, either wallhaven sent a wrong json, or we wrote a bad modelError::UnknownRequestError- an unknown error when sending/receiving the request, you can match further the underlying error
Sourcepub async fn tag(&self, id: u64) -> Result<Tag, Error>
pub async fn tag(&self, id: u64) -> Result<Tag, Error>
Fetches a Tag by its id
§Errors
Error::UrlParsingErrorwhen the URL cannot be parsedError::SendingRequestan error while sending the request, you can get more details with the underlying errorError::DecodingJsonan error decoding the JSON, either wallhaven sent a wrong json, or we wrote a bad modelError::UnknownRequestError- an unknown error when sending/receiving the request, you can match further the underlying error
Sourcepub async fn user_settings(&self) -> Result<UserSettings, Error>
pub async fn user_settings(&self) -> Result<UserSettings, Error>
Fetches the UserSettings of the current user. Only works if the api key was provided.
§Errors
Error::UrlParsingErrorwhen the URL cannot be parsedError::SendingRequestan error while sending the request, you can get more details with the underlying errorError::DecodingJsonan error decoding the JSON, either wallhaven sent a wrong json, or we wrote a bad modelError::UnknownRequestError- an unknown error when sending/receiving the request, you can match further the underlying error
Sourcepub async fn download_wallpaper(
&self,
wallpaper: &impl HasPath,
) -> Result<impl Stream<Item = Result<Bytes>>, Error>
pub async fn download_wallpaper( &self, wallpaper: &impl HasPath, ) -> Result<impl Stream<Item = Result<Bytes>>, Error>
Downloads a any wallpaper type (e.g. WallhavenDetails or WallhavenSummary)
§Errors
Error::SendingRequestan error while sending the request, you can get more details with the underlying errorError::UnknownRequestError- an unknown error when sending/receiving the request, you can match further the underlying error
Sourcepub async fn download_thumbnail(
&self,
thumbnail: &Thumbnails,
resolution: ThumbnailResolution,
) -> Result<impl Stream<Item = Result<Bytes>>, Error>
pub async fn download_thumbnail( &self, thumbnail: &Thumbnails, resolution: ThumbnailResolution, ) -> Result<impl Stream<Item = Result<Bytes>>, Error>
Downloads a Thumbnails
§Errors
Error::SendingRequestan error while sending the request, you can get more details with the underlying errorError::UnknownRequestError- an unknown error when sending/receiving the request, you can match further the underlying error
Trait Implementations§
Source§impl Clone for WallhavenClient
impl Clone for WallhavenClient
Source§fn clone(&self) -> WallhavenClient
fn clone(&self) -> WallhavenClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more