diff --git a/src/ipinfo.rs b/src/ipinfo.rs index a0b358b..7fed77b 100644 --- a/src/ipinfo.rs +++ b/src/ipinfo.rs @@ -103,7 +103,7 @@ impl Default for BatchReqOpts { } impl IpInfo { - /// Construct a new IpInfo structure. + /// Construct a new IpInfo structure with the default URL "https://ipinfo.io". /// /// # Examples /// @@ -113,13 +113,28 @@ impl IpInfo { /// let ipinfo = IpInfo::new(Default::default()).expect("should construct"); /// ``` pub fn new(config: IpInfoConfig) -> Result { + Self::base_request(config, "https://ipinfo.io") + } + + /// Construct a new IpInfo structure with the URL "https://v6.ipinfo.io/". + /// + /// # Examples + /// + /// ``` + /// use ipinfo::IpInfo; + /// + /// let ipinfo = IpInfo::new(Default::default()).expect("should construct"); + /// ``` + pub fn new_v6(config: IpInfoConfig) -> Result { + Self::base_request(config, "https://v6.ipinfo.io/") + } + + fn base_request(config: IpInfoConfig, url: &str) -> Result { let client = reqwest::Client::builder().timeout(config.timeout).build()?; - let url = "https://ipinfo.io".to_owned(); - let mut ipinfo_obj = Self { - url, + url: url.to_owned(), client, token: config.token, cache: LruCache::new(