Skip to content

Commit

Permalink
Merge pull request #52 from Alextopher/revert-51-talhahwahla/ipv6-sup…
Browse files Browse the repository at this point in the history
…port

Revert "Add IPv6 support"
  • Loading branch information
talhahwahla authored Jan 18, 2024
2 parents 8a54272 + bd0eb5d commit e085dd3
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/ipinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ use tokio::time::timeout;

const COUNTRY_FLAG_URL: &str =
"https://cdn.ipinfo.io/static/images/countries-flags/";

const BASE_URL: &str = "https://ipinfo.io";
const BASE_URL_V6: &str = "https://v6.ipinfo.io";

/// IpInfo structure configuration.
pub struct IpInfoConfig {
/// IPinfo access token.
Expand Down Expand Up @@ -79,6 +75,7 @@ impl Default for IpInfoConfig {

/// IPinfo requests context structure.
pub struct IpInfo {
url: String,
token: Option<String>,
client: reqwest::Client,
cache: LruCache<String, IpDetails>,
Expand Down Expand Up @@ -119,7 +116,10 @@ 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(
Expand Down Expand Up @@ -260,7 +260,7 @@ impl IpInfo {
) -> Result<HashMap<String, IpDetails>, IpError> {
// Lookup cache misses which are not bogon
let response = client
.post(&format!("{}/batch", BASE_URL))
.post(&format!("{}/batch", self.url))
.headers(Self::construct_headers())
.bearer_auth(self.token.as_deref().unwrap_or_default())
.json(&json!(ips))
Expand Down Expand Up @@ -303,18 +303,6 @@ impl IpInfo {
/// }
/// ```
pub async fn lookup(&mut self, ip: &str) -> Result<IpDetails, IpError> {
self._lookup(ip, BASE_URL).await
}

pub async fn lookup_v6(&mut self, ip: &str) -> Result<IpDetails, IpError> {
self._lookup(ip, BASE_URL_V6).await
}

async fn _lookup(
&mut self,
ip: &str,
base_url: &str,
) -> Result<IpDetails, IpError> {
if is_bogon(ip) {
return Ok(IpDetails {
ip: ip.to_string(),
Expand All @@ -333,7 +321,7 @@ impl IpInfo {
// lookup in case of a cache miss
let response = self
.client
.get(&format!("{}/{}", base_url, ip))
.get(&format!("{}/{}", self.url, ip))
.headers(Self::construct_headers())
.bearer_auth(self.token.as_deref().unwrap_or_default())
.send()
Expand Down Expand Up @@ -382,7 +370,7 @@ impl IpInfo {
return Err(err!(MapLimitError));
}

let map_url = &format!("{}/tools/map?cli=1", BASE_URL);
let map_url = &format!("{}/tools/map?cli=1", self.url);
let client = self.client.clone();
let json_ips = serde_json::json!(ips);

Expand Down

0 comments on commit e085dd3

Please sign in to comment.