Skip to content

Commit

Permalink
Add IPv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
talhahwahla committed Jan 8, 2024
1 parent bb42047 commit c690e4a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/ipinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -113,13 +113,28 @@ impl IpInfo {
/// let ipinfo = IpInfo::new(Default::default()).expect("should construct");
/// ```
pub fn new(config: IpInfoConfig) -> Result<Self, IpError> {
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, IpError> {
Self::base_request(config, "https://v6.ipinfo.io/")
}

fn base_request(config: IpInfoConfig, url: &str) -> Result<Self, IpError> {
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(
Expand Down

0 comments on commit c690e4a

Please sign in to comment.