mirror of
https://github.com/MedzikUser/imgurs
synced 2024-08-15 00:03:19 +00:00
chore: change Result to anyhow::Result
This commit is contained in:
parent
58acb3df50
commit
9b7705ed26
6 changed files with 6 additions and 11 deletions
|
@ -1,11 +1,10 @@
|
|||
use std::io;
|
||||
|
||||
use anyhow::Error;
|
||||
use reqwest::Method;
|
||||
|
||||
use super::{client::api_url, send_api_request, ImgurClient};
|
||||
|
||||
pub async fn delete_image(client: &ImgurClient, delete_hash: &str) -> Result<(), Error> {
|
||||
pub async fn delete_image(client: &ImgurClient, delete_hash: &str) -> anyhow::Result<()> {
|
||||
// get imgur api url
|
||||
let uri = api_url!(format!("image/{delete_hash}"));
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use std::io;
|
||||
|
||||
use anyhow::Error;
|
||||
use reqwest::Method;
|
||||
|
||||
use super::{client::api_url, send_api_request, ImageInfo, ImgurClient};
|
||||
|
||||
pub async fn get_image(client: &ImgurClient, image: &str) -> Result<ImageInfo, Error> {
|
||||
pub async fn get_image(client: &ImgurClient, image: &str) -> anyhow::Result<ImageInfo> {
|
||||
// get imgur api url
|
||||
let uri = api_url!(format!("image/{image}"));
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ pub use upload_image::*;
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Error;
|
||||
use reqwest::{Method, Response};
|
||||
|
||||
// send request to imgur api
|
||||
|
@ -24,7 +23,7 @@ pub async fn send_api_request(
|
|||
method: Method,
|
||||
uri: String,
|
||||
form: Option<HashMap<&str, String>>,
|
||||
) -> Result<Response, Error> {
|
||||
) -> anyhow::Result<Response> {
|
||||
// get request client
|
||||
let client = &config.client;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::io;
|
||||
|
||||
use anyhow::Error;
|
||||
use reqwest::Method;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -27,7 +26,7 @@ pub struct RateLimitData {
|
|||
pub client_remaining: i32,
|
||||
}
|
||||
|
||||
pub async fn rate_limit(client: &ImgurClient) -> Result<RateLimitInfo, Error> {
|
||||
pub async fn rate_limit(client: &ImgurClient) -> anyhow::Result<RateLimitInfo> {
|
||||
// get imgur api url
|
||||
let uri = api_url!("credits");
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use std::{collections::HashMap, io};
|
||||
|
||||
use anyhow::Error;
|
||||
use reqwest::Method;
|
||||
|
||||
use super::{client::api_url, send_api_request, ImageInfo, ImgurClient};
|
||||
|
||||
pub async fn upload_image(client: &ImgurClient, image: String) -> Result<ImageInfo, Error> {
|
||||
pub async fn upload_image(client: &ImgurClient, image: String) -> anyhow::Result<ImageInfo> {
|
||||
// create http form (hashmap)
|
||||
let mut form = HashMap::new();
|
||||
// insert image to form
|
||||
|
|
|
@ -50,7 +50,7 @@ pub fn parse() -> Config {
|
|||
})
|
||||
}
|
||||
|
||||
fn toml() -> Result<Config, Error> {
|
||||
fn toml() -> anyhow::Result<Config> {
|
||||
let config_dir = config_dir().unwrap();
|
||||
let file_dir = format!("{}{CONFIG_DIR}", config_dir.to_string_lossy());
|
||||
let toml_str = read_to_string(file_dir).map_err(Error::new)?;
|
||||
|
|
Loading…
Reference in a new issue