From 6c7c334ede1b58d7c142db068914ac40a76d2bae Mon Sep 17 00:00:00 2001 From: MedzikUser Date: Wed, 2 Mar 2022 22:16:44 +0100 Subject: [PATCH] update --- .github/workflows/build.yml | 6 ++++++ CHANGELOG.md | 1 + README.md | 8 +++++++- src/api/image_type.rs | 4 ++-- src/api/mod.rs | 33 +++++++++++++++++++++++++++++++-- src/api/send_request.rs | 33 --------------------------------- 6 files changed, 47 insertions(+), 38 deletions(-) delete mode 100644 src/api/send_request.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 124a745..f179e04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,3 +43,9 @@ jobs: with: command: clippy args: -- -D warnings + + - name: rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -all --check diff --git a/CHANGELOG.md b/CHANGELOG.md index f84a919..f300777 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Library - added Clone derive +- if body length is > 30 return body is too length ## [0.3.0] - 2022-01-28 ### CLI diff --git a/README.md b/README.md index 7a1e264..e747fc0 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,12 @@ imgurs completions zsh > /usr/local/share/zsh/site-functions/_imgurs imgurs completions fish > ~/.config/fish/completions/imgurs.fish ``` +## Man page + +Generate manpage + + imgurs manpage | gzip > /usr/share/man/man1/imgurs.1.gz + ## Dependencies - support clipboard on Linux - **xsel** @@ -38,7 +44,7 @@ Using yay ([AUR](https://aur.archlinux.org/packages/imgurs)) yay -S imgurs -If you are using arch linux you can add [this repo](https://github.com/archlinux-pkg/packages) and run +or can add [this repo](https://github.com/archlinux-pkg/packages) and run sudo pacman -Sy imgurs diff --git a/src/api/image_type.rs b/src/api/image_type.rs index e3ea0f3..8d53d68 100644 --- a/src/api/image_type.rs +++ b/src/api/image_type.rs @@ -1,13 +1,13 @@ use serde_derive::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub struct ImageInfo { pub data: ImageInfoData, pub success: bool, pub status: i32, } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub struct ImageInfoData { pub id: String, pub title: Option, diff --git a/src/api/mod.rs b/src/api/mod.rs index cb55b3b..2fc1525 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,5 +1,4 @@ mod image_type; -mod send_request; pub mod configuration; pub mod delete_image; @@ -9,4 +8,34 @@ pub mod upload_image; pub use configuration::ImgurClient; pub use image_type::*; -pub use send_request::send_api_request; + +use reqwest::Method; +use std::collections::HashMap; + +pub async fn send_api_request( + config: &ImgurClient, + method: Method, + uri: String, + form: Option>, +) -> Result { + let client = &config.client; + + let mut req = client.request(method, uri.as_str()); + + const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION"); + + req = req + .header("Authorization", format!("Client-ID {}", config.client_id)) + .header( + "User-Agent", + format!("Imgur/{:?}", VERSION.unwrap_or("unknown")), + ); + + if form != None { + req = req.form(&form.unwrap()) + } + + let req = req.build()?; + + client.execute(req).await.map_err(anyhow::Error::from) +} diff --git a/src/api/send_request.rs b/src/api/send_request.rs deleted file mode 100644 index cf8497f..0000000 --- a/src/api/send_request.rs +++ /dev/null @@ -1,33 +0,0 @@ -use super::ImgurClient; - -use anyhow::Error; -use reqwest::Method; -use std::collections::HashMap; - -pub async fn send_api_request( - config: &ImgurClient, - method: Method, - uri: String, - form: Option>, -) -> Result { - let client = &config.client; - - let mut req = client.request(method, uri.as_str()); - - const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION"); - - req = req - .header("Authorization", format!("Client-ID {}", config.client_id)) - .header( - "User-Agent", - format!("Imgur/{:?}", VERSION.unwrap_or("unknown")), - ); - - if form != None { - req = req.form(&form.unwrap()) - } - - let req = req.build()?; - - client.execute(req).await.map_err(Error::from) -}