From 452ab5e1898fdcc62b0da9921bbbdfd788a63005 Mon Sep 17 00:00:00 2001 From: talhahwahla Date: Mon, 22 Jan 2024 06:10:46 +0500 Subject: [PATCH 1/4] rename to `lookup_self_v6` --- src/ipinfo.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ipinfo.rs b/src/ipinfo.rs index 170abac..a2870f4 100644 --- a/src/ipinfo.rs +++ b/src/ipinfo.rs @@ -306,8 +306,9 @@ impl IpInfo { self._lookup(ip, BASE_URL).await } - pub async fn lookup_v6(&mut self, ip: &str) -> Result { - self._lookup(ip, BASE_URL_V6).await + // Lookup your own v6 IP + pub async fn lookup_self_v6(&mut self) -> Result { + self._lookup("", BASE_URL_V6).await } async fn _lookup( From 492a6926d85369e19aa2bcfe8da0a4bbb6145138 Mon Sep 17 00:00:00 2001 From: talhahwahla Date: Mon, 22 Jan 2024 06:20:50 +0500 Subject: [PATCH 2/4] fixes --- src/ipinfo.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ipinfo.rs b/src/ipinfo.rs index a9a3189..a2870f4 100644 --- a/src/ipinfo.rs +++ b/src/ipinfo.rs @@ -79,7 +79,6 @@ impl Default for IpInfoConfig { /// IPinfo requests context structure. pub struct IpInfo { - url: String, token: Option, client: reqwest::Client, cache: LruCache, @@ -120,10 +119,7 @@ impl IpInfo { let client = reqwest::Client::builder().timeout(config.timeout).build()?; - let url = "https://ipinfo.io".to_owned(); - let mut ipinfo_obj = Self { - url, client, token: config.token, cache: LruCache::new( From 52f06685fcc9918ffe40ba1c3858d925f3983533 Mon Sep 17 00:00:00 2001 From: talhahwahla Date: Mon, 22 Jan 2024 06:41:07 +0500 Subject: [PATCH 3/4] doc comment --- src/ipinfo.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ipinfo.rs b/src/ipinfo.rs index a2870f4..4235c0a 100644 --- a/src/ipinfo.rs +++ b/src/ipinfo.rs @@ -306,7 +306,19 @@ impl IpInfo { self._lookup(ip, BASE_URL).await } - // Lookup your own v6 IP + /// looks up IPDetails of your own v6 IP + /// + /// # Example + /// + /// ```no_run + /// use ipinfo::IpInfo; + /// + /// #[tokio::main] + /// async fn main() { + /// let mut ipinfo = IpInfo::new(Default::default()).expect("should construct"); + /// let res = ipinfo.lookup_self_v6().await.expect("should run"); + /// } + /// ``` pub async fn lookup_self_v6(&mut self) -> Result { self._lookup("", BASE_URL_V6).await } From 5752b5e5d745ec88235f66ce3d6d8ff48e995955 Mon Sep 17 00:00:00 2001 From: talhahwahla Date: Mon, 22 Jan 2024 06:42:59 +0500 Subject: [PATCH 4/4] add `lookup_self_v4` --- src/ipinfo.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ipinfo.rs b/src/ipinfo.rs index 4235c0a..a905bda 100644 --- a/src/ipinfo.rs +++ b/src/ipinfo.rs @@ -306,6 +306,23 @@ impl IpInfo { self._lookup(ip, BASE_URL).await } + /// looks up IPDetails of your own v4 IP + /// + /// # Example + /// + /// ```no_run + /// use ipinfo::IpInfo; + /// + /// #[tokio::main] + /// async fn main() { + /// let mut ipinfo = IpInfo::new(Default::default()).expect("should construct"); + /// let res = ipinfo.lookup_self_v4().await.expect("should run"); + /// } + /// ``` + pub async fn lookup_self_v4(&mut self) -> Result { + self._lookup("", BASE_URL).await + } + /// looks up IPDetails of your own v6 IP /// /// # Example