-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline json files #43
Conversation
$ cargo run --example get_map <TOKEN>
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/examples/get_map <TOKEN>`
Map URL: https://ipinfo.io/tools/map/1bd73045-32e1-47e7-9b21-0578414bb6a8
$ cargo run --example lookup <TOKEN>
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/examples/lookup <TOKEN>`
8.8.8.8 lookup result: IpDetails { ip: "8.8.8.8", hostname: Some("dns.google"), city: "Mountain View", region: "California", country: "US", country_name: Some("North America"), is_eu: Some(false), country_flag: Some(CountryFlag { emoji: "🇺🇸", unicode: "U+1F1FA U+1F1F8" }), country_flag_url: Some("https://cdn.ipinfo.io/static/images/countries-flags/US.svg"), country_currency: Some(CountryCurrency { code: "USD", symbol: "$" }), continent: Some(Continent { code: "NA", name: "North America" }), loc: "37.4056,-122.0775", org: Some("AS15169 Google LLC"), postal: Some("94043"), timezone: Some("America/Los_Angeles"), asn: Some(AsnDetails { asn: "AS15169", name: "Google LLC", domain: "google.com", route: "8.8.8.0/24", asn_type: "hosting" }), company: Some(CompanyDetails { name: "Google LLC", domain: "google.com", company_type: "hosting" }), carrier: None, privacy: Some(PrivacyDetails { vpn: false, proxy: false, tor: false, relay: false, hosting: true, service: "" }), abuse: Some(AbuseDetails { address: "US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043", country: "US", email: "[email protected]", name: "Abuse", network: "8.8.8.0/24", phone: "+1-650-253-0000" }), domains: Some(DomainsDetails { ip: Some("8.8.8.8"), total: 9307, domains: ["wsyybbs.com", "musicool.cn", "kagou.vip", "nmgk2.com", "bits-hyderabad.ac.in"] }), bogon: None, extra: {"anycast": Bool(true)} }
$ cargo run --example lookup_batch <TOKEN>
Compiling ipinfo v2.2.0 (/home/talha/Desktop/rust)
Finished dev [unoptimized + debuginfo] target(s) in 2.72s
Running `target/debug/examples/lookup_batch <TOKEN>`
8.8.8.8: IpDetails { ip: "8.8.8.8", hostname: Some("dns.google"), city: "Mountain View", region: "California", country: "US", country_name: Some("North America"), is_eu: Some(false), country_flag: Some(CountryFlag { emoji: "🇺🇸", unicode: "U+1F1FA U+1F1F8" }), country_flag_url: Some("https://cdn.ipinfo.io/static/images/countries-flags/US.svg"), country_currency: Some(CountryCurrency { code: "USD", symbol: "$" }), continent: Some(Continent { code: "NA", name: "North America" }), loc: "37.4056,-122.0775", org: Some("AS15169 Google LLC"), postal: Some("94043"), timezone: Some("America/Los_Angeles"), asn: Some(AsnDetails { asn: "AS15169", name: "Google LLC", domain: "google.com", route: "8.8.8.0/24", asn_type: "hosting" }), company: Some(CompanyDetails { name: "Google LLC", domain: "google.com", company_type: "hosting" }), carrier: None, privacy: Some(PrivacyDetails { vpn: false, proxy: false, tor: false, relay: false, hosting: true, service: "" }), abuse: Some(AbuseDetails { address: "US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043", country: "US", email: "[email protected]", name: "Abuse", network: "8.8.8.0/24", phone: "+1-650-253-0000" }), domains: Some(DomainsDetails { ip: Some("8.8.8.8"), total: 9307, domains: ["wsyybbs.com", "musicool.cn", "kagou.vip", "nmgk2.com", "bits-hyderabad.ac.in"] }), bogon: None, extra: {"anycast": Bool(true)} }
4.2.2.4: IpDetails { ip: "4.2.2.4", hostname: Some("d.resolvers.level3.net"), city: "Monroe", region: "Louisiana", country: "US", country_name: Some("North America"), is_eu: Some(false), country_flag: Some(CountryFlag { emoji: "🇺🇸", unicode: "U+1F1FA U+1F1F8" }), country_flag_url: Some("https://cdn.ipinfo.io/static/images/countries-flags/US.svg"), country_currency: Some(CountryCurrency { code: "USD", symbol: "$" }), continent: Some(Continent { code: "NA", name: "North America" }), loc: "32.5530,-92.0422", org: Some("AS3356 Level 3 Parent, LLC"), postal: Some("71203"), timezone: Some("America/Chicago"), asn: Some(AsnDetails { asn: "AS3356", name: "Level 3 Parent, LLC", domain: "lumen.com", route: "4.0.0.0/9", asn_type: "isp" }), company: Some(CompanyDetails { name: "Level 3 Parent, LLC", domain: "lumen.com", company_type: "isp" }), carrier: None, privacy: Some(PrivacyDetails { vpn: false, proxy: false, tor: false, relay: false, hosting: false, service: "" }), abuse: Some(AbuseDetails { address: "US, LA, Monroe, 100 CenturyLink Drive, 71203", country: "US", email: "[email protected]", name: "L3 Abuse Contact", network: "4.0.0.0/9", phone: "+1-877-453-8353" }), domains: Some(DomainsDetails { ip: Some("4.2.2.4"), total: 5, domains: ["pcdownload.link", "magnolya.ir", "mr-rataa.site", "pwn3r.zone", "neutrongroupltd.hk"] }), bogon: None, extra: {"anycast": Bool(true)} }
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to now support allowing the override
2f3aa9b
to
374ca8a
Compare
0e5d485
to
d026a86
Compare
$ grep '\"US\"' *.json
continents.json: "US": {"code": "NA", "name": "_North_America"},
countries.json: "US": "US of A",
currency.json: "US" : { "code": "USD" ,"symbol": "$$$$"},
flag.json: "US": {"emoji": "🇺🇸","unicode": "---NA--"}, $ cat examples/lookup.rs
use ipinfo::{IpInfo, IpInfoConfig};
use std::env;
#[tokio::main]
async fn main() {
let token = env::args().skip(1).next();
let config = IpInfoConfig {
token,
continents_file_path: Some("continents.json".to_string()),
countries_file_path: Some("countries.json".to_string()),
country_currencies_file_path: Some("currency.json".to_string()),
country_flags_file_path: Some("flag.json".to_string()),
eu_file_path: Some("eu.json".to_string()),
..Default::default()
};
let mut ipinfo = IpInfo::new(config).expect("should construct");
let res = ipinfo.lookup("9.8.8.8").await;
match res {
Ok(r) => {
println!("{} lookup result: {:?}", "9.8.8.8", r);
}
Err(e) => println!("error occurred: {}", &e.to_string()),
}
} $ cargo run --example lookup <TOKEN>
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/examples/lookup <TOKEN>`
9.8.8.8 lookup result: IpDetails { ip: "9.8.8.8", hostname: None, city: "Durham", region: "North Carolina", country: "US", country_name: Some("US of A"), is_eu: Some(false), country_flag: Some(CountryFlag { emoji: "🇺🇸", unicode: "---NA--" }), country_flag_url: Some("https://cdn.ipinfo.io/static/images/countries-flags/US.svg"), country_currency: Some(CountryCurrency { code: "USD", symbol: "$$$$" }), continent: Some(Continent { code: "NA", name: "_North_America" }), loc: "36.0512,-78.8577", org: None, postal: Some("27709"), timezone: Some("America/New_York"), asn: None, company: Some(CompanyDetails { name: "IBM", domain: "ibm.com", company_type: "business" }), carrier: None, privacy: Some(PrivacyDetails { vpn: false, proxy: false, tor: false, relay: false, hosting: false, service: "" }), abuse: Some(AbuseDetails { address: "US, NC, Research Triangle Park, 3039 Cornwallis Road, 27709-2195", country: "US", email: "[email protected]", name: "Registrar Authority, Internet numbers", network: "9.0.0.0-9.9.8.255", phone: "+1-512-308-4534" }), domains: Some(DomainsDetails { ip: None, total: 0, domains: [] }), bogon: None, extra: {} } Retaining the existing interface for overriding via passing file path. |
@talhahwahla all the other SDKs have broken the interface to expect an in-memory map. Don't forget that this data could come from anywhere, not just a JSON file. Now we're forcing a specific input format at the file level, which is more problematic than letting it come in as a map, since it's easier to create an in-memory map from anything else. |
c481b21
to
bbce3ee
Compare
$ cat examples/lookup.rs
use ipinfo::{IpInfo, IpInfoConfig};
use std::env;
#[tokio::main]
async fn main() {
let token = env::args().skip(2).next();
let user_countries = {
let json_data = r#"
{
"US": "US of A"
}
"#;
serde_json::from_str(json_data).expect("error parsing user-defined JSON!")
};
let user_continents = {
let json_data = r#"
{
"US": {"code": "_US", "name": "_North_America"}
}
"#;
serde_json::from_str(json_data).expect("error parsing user-defined JSON!")
};
let user_currencies = {
let json_data = r#"
{
"US" : { "code": "_USD" ,"symbol": "_$" }
}
"#;
serde_json::from_str(json_data).expect("error parsing user-defined JSON!")
};
let config = IpInfoConfig {
token,
defaut_countries: user_countries,
default_currencies: user_currencies,
default_continents: user_continents,
..Default::default()
};
let mut ipinfo = IpInfo::new(config).expect("should construct");
let res = ipinfo.lookup("9.8.8.8").await;
match res {
Ok(r) => {
println!("{} lookup result: {:?}", "9.8.8.8", r);
}
Err(e) => println!("error occurred: {}", &e.to_string()),
}
}
$ cargo run --example lookup -- <TOKEN>
Compiling ipinfo v2.2.0 (/home/talha/Desktop/rust)
Finished dev [unoptimized + debuginfo] target(s) in 2.35s
Running `target/debug/examples/lookup <TOKEN>`
9.8.8.8 lookup result: IpDetails { ip: "9.8.8.8", hostname: None, city: "Durham", region: "North Carolina", country: "US", country_name: Some("US of A"), is_eu: Some(false), country_flag: Some(CountryFlag { emoji: "🇺🇸", unicode: "U+1F1FA U+1F1F8" }), country_flag_url: Some("https://cdn.ipinfo.io/static/images/countries-flags/US.svg"), country_currency: Some(CountryCurrency { code: "_USD", symbol: "_$" }), continent: Some(Continent { code: "_US", name: "_North_America" }), loc: "36.0512,-78.8577", org: None, postal: Some("27709"), timezone: Some("America/New_York"), asn: None, company: None, carrier: None, privacy: None, abuse: None, domains: None, bogon: None, extra: {"readme": String("https://ipinfo.io/missingauth")} }
|
No description provided.