From df066c54473c805fb27ca9c883c2f9542bc0588a Mon Sep 17 00:00:00 2001 From: Ollivier Robert Date: Mon, 8 Nov 2021 14:59:48 +0100 Subject: [PATCH 1/5] clippy: remove fn main() from all examples. --- src/lib.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 14d86d0..36e0a8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,9 +8,7 @@ //! ``` //! use ipify_rs::myip; //! -//! fn main() { -//! println!("My IP is: {}", myip()); -//! } +//! println!("My IP is: {}", myip()); //! ``` //! //! The full API is described below. @@ -30,9 +28,7 @@ const ENDPOINT6J: &str = "https://api64.ipify.org?format=json"; /// ``` /// use ipify_rs::myip; /// -/// fn main() { -/// println!("{}", myip()) -/// } +/// println!("{}", myip()) /// ``` /// pub fn myip() -> String { @@ -76,15 +72,13 @@ pub struct Ipify<'a> { impl<'a> Ipify<'a> { /// Create a new API instance client with the defaults /// - /// Examples: + /// Example: /// ``` /// use ipify_rs::*; /// - /// fn main() { - /// let mut a = Ipify::new(); + /// let mut a = Ipify::new(); /// - /// println!("{}", a.call()); - /// } + /// println!("{}", a.call()); /// ``` /// pub fn new() -> Self { @@ -120,12 +114,10 @@ impl<'a> Ipify<'a> { /// ``` /// use ipify_rs::{Ipify, Op}; /// - /// fn main() { - /// let mut a = Ipify::new(); - /// a.set(Op::IPv6J); + /// let mut a = Ipify::new(); + /// a.set(Op::IPv6J); /// - /// println!("{}", a.call()); - /// } + /// println!("{}", a.call()); /// ``` /// pub fn set(mut self, op: Op) -> Self { @@ -140,6 +132,16 @@ impl<'a> Ipify<'a> { } /// Actually perform the API call + /// + /// Example: + /// ``` + /// use ipify_rs::Ipify; + /// + /// let r = Ipify::new().call(); + /// + /// println!("my ip = {}", r); + /// ``` + /// pub fn call(self) -> String { match self.e { Engine::Ureq => { From 375557fbea550c6a6731eab42e03d0675ca3fe9c Mon Sep 17 00:00:00 2001 From: Ollivier Robert Date: Mon, 8 Nov 2021 15:01:21 +0100 Subject: [PATCH 2/5] clippy: Add Default impl for Ipify. --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 36e0a8e..f7a82e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,13 @@ pub struct Ipify<'a> { pub endp: &'a str, } +/// Impl. default values. +impl<'a> Default for Ipify<'a> { + fn default() -> Self { + Self::new() + } +} + /// API Implementation impl<'a> Ipify<'a> { /// Create a new API instance client with the defaults From 0f7d36e0f14660305c5ad8220b9ee073c89ddb3a Mon Sep 17 00:00:00 2001 From: Ollivier Robert Date: Mon, 8 Nov 2021 15:01:57 +0100 Subject: [PATCH 3/5] Remove support for ureq: proxy support too complicated. --- Cargo.toml | 1 - examples/showall.rs | 11 ++----- src/bin/ipify-cli/main.rs | 12 ++------ src/lib.rs | 64 +++++---------------------------------- 4 files changed, 12 insertions(+), 76 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c9bbb06..512388a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,5 @@ documentation = "https://docs.rs/ipify-rs" [dependencies] clap = "3.0.0-beta.5" log = "0.4" -ureq = { version = "2", features = ["socks-proxy"] } reqwest = { version = "0.11.6", features = ["blocking"] } stderrlog = "0.5.1" diff --git a/examples/showall.rs b/examples/showall.rs index 2e45926..ae2ddc1 100644 --- a/examples/showall.rs +++ b/examples/showall.rs @@ -1,9 +1,8 @@ use ipify_rs::*; use log::info; -fn doit(e: Engine) { +fn doit() { let ip = Ipify::new(); - ip.with(e); println!("IP4={:?}", ip.set(Op::IPv4).call()); println!("IP6={:?}", ip.set(Op::IPv6).call()); @@ -20,15 +19,11 @@ fn main() { info!("Using default, minimal API"); println!("IP={}", myip()); - info!("Using defaults (ureq, ipv6)"); + info!("Using defaults (ipv6)"); println!("IP={}", Ipify::new().call()); info!("Using defaults, get json"); println!("IP={}", Ipify::new().set(Op::IPv6J).call()); - info!("Using ureq"); - doit(Engine::Reqw); - - info!("Using reqwest"); - doit(Engine::Reqw); + doit(); } diff --git a/src/bin/ipify-cli/main.rs b/src/bin/ipify-cli/main.rs index 1160764..0b21da6 100644 --- a/src/bin/ipify-cli/main.rs +++ b/src/bin/ipify-cli/main.rs @@ -1,5 +1,5 @@ use clap::{crate_authors, crate_name, crate_version, AppSettings, Parser}; -use ipify_rs::{Engine, Ipify, Op}; +use ipify_rs::{Ipify, Op}; /// Binary name pub(crate) const NAME: &str = "ipify-cli"; @@ -27,9 +27,6 @@ struct Opts { /// Request JSON output #[clap(short = 'J', long = "json")] json: bool, - /// Request other engine - #[clap(short = 'E', long = "engine", default_value = "ureq")] - engine: String, } fn banner() -> String { @@ -57,7 +54,6 @@ fn main() { // Start with defaults let mut op = Op::IPv6; - let mut e = Engine::Ureq; if opts.ipv4 { op = Op::IPv4; @@ -74,12 +70,8 @@ fn main() { }; } - if opts.engine == "reqw" { - e = Engine::Reqw; - } - let c = Ipify::new(); - let r = c.set(op).with(e).call(); + let r = c.set(op).call(); if v { println!("My IP = {}", r); } else { diff --git a/src/lib.rs b/src/lib.rs index f7a82e0..a5c54bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,15 +35,6 @@ pub fn myip() -> String { Ipify::new().call() } -/// Describe the available HTTP engines -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum Engine { - // ureq - Ureq, - // reqwest - Reqw, -} - /// The current set of operations #[derive(Clone, Copy, Debug, PartialEq)] pub enum Op { @@ -60,8 +51,6 @@ pub enum Op { /// The main API struct #[derive(Clone, Copy, Debug)] pub struct Ipify<'a> { - /// HTTP Engine - pub e: Engine, /// Current type of operation pub t: Op, /// Endpoint, different for every operation @@ -90,31 +79,11 @@ impl<'a> Ipify<'a> { /// pub fn new() -> Self { Ipify { - e: Engine::Ureq, t: Op::IPv6, endp: ENDPOINT6, } } - /// Use the specified HTTP engine - /// - /// Examples: - /// ``` - /// use ipify_rs::{Ipify, Engine}; - /// - /// fn main() { - /// let mut a = Ipify::new(); - /// a.with(Engine::Reqw); - /// - /// println!("{}", a.call()); - /// } - /// ``` - /// - pub fn with(mut self, e: Engine) -> Self { - self.e = e; - self - } - /// Specify the subsequent operation to perform on `call()` /// /// Examples: @@ -150,24 +119,11 @@ impl<'a> Ipify<'a> { /// ``` /// pub fn call(self) -> String { - match self.e { - Engine::Ureq => { - let pe = env!("http_proxy"); - let p = ureq::Proxy::new(pe).unwrap(); - let c = ureq::AgentBuilder::new() - .user_agent("ipify-cli/1.0.0") - .proxy(p) - .build(); - return c.get(&self.endp).call().unwrap().into_string().unwrap(); - } - Engine::Reqw => { - let c = reqwest::blocking::ClientBuilder::new() - .user_agent("ipify-cli/1.0.0") - .build() - .unwrap(); - return c.get(self.endp).send().unwrap().text().unwrap(); - } - } + let c = reqwest::blocking::ClientBuilder::new() + .user_agent("ipify-cli/1.0.0") + .build() + .unwrap(); + c.get(self.endp).send().unwrap().text().unwrap() } } @@ -197,10 +153,6 @@ mod tests { let c = Ipify::new(); assert_eq!(Op::IPv6, c.t); - let c = c.with(Engine::Reqw); - assert_eq!(Engine::Reqw, c.e); - let c = c.with(Engine::Ureq); - assert_eq!(Engine::Ureq, c.e); } #[test] @@ -208,12 +160,10 @@ mod tests { let c = Ipify::new(); assert_eq!(Op::IPv6, c.t); - let c = c.with(Engine::Reqw).set(Op::IPv4); - assert_eq!(Engine::Reqw, c.e); + let c = c.set(Op::IPv4); assert_eq!(Op::IPv4, c.t); - let c = c.set(Op::IPv4J).with(Engine::Ureq); - assert_eq!(Engine::Ureq, c.e); + let c = c.set(Op::IPv4J); assert_eq!(Op::IPv4J, c.t); } } From 05dcef47c8fcc8f480656b86b465b96fdd05ede1 Mon Sep 17 00:00:00 2001 From: Ollivier Robert Date: Mon, 8 Nov 2021 15:08:37 +0100 Subject: [PATCH 4/5] Update README with Engine/ureq removal. --- README.md | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index f11b3f6..e5c13e9 100644 --- a/README.md +++ b/README.md @@ -32,21 +32,6 @@ The four operations are specified as below: - `OP::IPv4J` (json output) - `Op::IPv6J` (json output) -## HTTP engine - -This API can use either [ureq] or [reqwest] as HTTP client. You can select the engine with the `with()` method. The current version of `Ipify` only support the *blocking* client though. - -```rs - use ipify_rs::{Engine, Ipify, Op}; - - let c = Ipify::new().with(Engine::Reqw).set(Op::IPv4); - - println!("My IP is {}", c.call()); -``` - -[ureq]: https://docs.rs/crate/ureq/ -[reqwest]: https://docs.rs/crate/reqwest/ - ## Minimalistic API If you only care about the default (plain text, IPv6 query) and don't want to reuse anything later, then `myip()` is what you want: @@ -84,7 +69,8 @@ There is a CLI utility bundled with the API called `ipify-cli`. You can see both API & CLI versions: ``` $ ipify-cli -V - Running API ipify-rs/0.2.0 CLI ipify-cli/0.1.0 +CLI ipify-cli/0.1.0 using API ipify-rs/0.2.0 + ``` ## Example @@ -96,14 +82,10 @@ The file `showall.rs` inside `examples` show almost all parameters for the API. INFO - Start INFO - Using default, minimal API IP=aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh - INFO - Using defaults (ureq, ipv6) + INFO - Using defaults (ipv6) IP=aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh INFO - Using defaults, get json IP={"ip":"aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh"} - INFO - Using ureq - IP4="A.B.C.D" - IP6="aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh" - INFO - Using reqwest IP4="A.B.C.D" IP6="aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh" ``` From acd2b2d303c6265f6b165041aa285dd5d1ab96b3 Mon Sep 17 00:00:00 2001 From: Ollivier Robert Date: Mon, 8 Nov 2021 15:17:21 +0100 Subject: [PATCH 5/5] Welcome v0.5.0; only reqwest now supported. --- Cargo.toml | 2 +- README.md | 6 +++--- src/bin/ipify-cli/main.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 512388a..15c94a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ipify-rs" -version = "0.4.0" +version = "0.5.0" edition = "2021" authors = ["Ollivier Robert "] keywords = ["ipify", "api", "client"] diff --git a/README.md b/README.md index e5c13e9..df0cd25 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ fn main() { There is a CLI utility bundled with the API called `ipify-cli`. ``` - ipify-cli 0.2.0 + ipify-cli 0.4.0 Ollivier Robert @@ -69,7 +69,7 @@ There is a CLI utility bundled with the API called `ipify-cli`. You can see both API & CLI versions: ``` $ ipify-cli -V -CLI ipify-cli/0.1.0 using API ipify-rs/0.2.0 +CLI ipify-cli/0.4.0 using API ipify-rs/0.5.0 ``` @@ -97,7 +97,7 @@ to your `Cargo.toml`: ``` toml [dependencies] -ipify-rs = "0.2.0" +ipify-rs = "0.5.0" ``` then you can use it in your own crates. diff --git a/src/bin/ipify-cli/main.rs b/src/bin/ipify-cli/main.rs index 0b21da6..3ce99c7 100644 --- a/src/bin/ipify-cli/main.rs +++ b/src/bin/ipify-cli/main.rs @@ -4,7 +4,7 @@ use ipify_rs::{Ipify, Op}; /// Binary name pub(crate) const NAME: &str = "ipify-cli"; /// Binary version, different from the API itself represented the crate. -pub(crate) const VERSION: &str = "0.3.0"; +pub(crate) const VERSION: &str = "0.4.0"; /// Help message #[derive(Debug, Parser)]