Crates.io | maxmind_geo_ip2 |
lib.rs | maxmind_geo_ip2 |
version | 0.2.5 |
source | src |
created_at | 2021-04-18 11:59:20.667402 |
updated_at | 2022-05-02 21:42:08.052228 |
description | a REST API client for the MaxMind GeoIP2 API |
homepage | https://github.com/mtphil/maxmind_geo_ip2 |
repository | https://github.com/mtphil/maxmind_geo_ip2 |
max_upload_size | |
id | 386111 |
size | 18,147 |
Full documentation here: https://docs.rs/maxmind_geo_ip2/
Crates.io page here: https://crates.io/crates/maxmind_geo_ip2
WARNING: This is still very much a work in progress - this should probably/definitely NOT BE USED IN PRODUCTION.
This is my first Rust crate, so any suggestion about improvements, etc are very welcome.
To-dos:
reqwest = { version = "0.11.3", features = ["rustls", "json"] }
serde = { version = "1.0.125", features = ["derive"] }
Import the api client from the crate:
use maxmind_geo_ip2::ApiClient;
Initialize the client with Maxmind API credentials:
let maxmind_client = ApiClient::new_client(String::from("user_id_here"), String::from("license_key_here"));
API endpoint:
https://geoip.maxmind.com/geoip/v2.1/country/{ip_address}
Method signature:
get_country(ip_address: &str) -> Result<CountryResponse, Box<dyn std::error::Error>>
Response:
pub struct CountryResponse {
pub continent: Continent,
pub maxmind: MaxMind,
pub traits: Traits,
pub represented_country: Option<RepresentedCountry>,
pub registered_country: RegisteredCountry,
pub country: Country,
}
API endpoint:
https://geoip.maxmind.com/geoip/v2.1/city/{ip_address}
Method signature:
get_city(ip_address: &str) -> Result<CityResponse, Box<dyn std::error::Error>>
Response:
pub struct CityResponse {
pub city: City,
pub continent: Continent,
pub country: Country,
pub location: Location,
pub postal: Postal,
pub represented_country: Option<RepresentedCountry>,
pub registered_country: RegisteredCountry,
pub subdivisions: Vec<Subdivision>,
pub traits: Traits,
pub maxmind: MaxMind,
}
API endpoint:
https://geoip.maxmind.com/geoip/v2.1/insights/{ip_address}
Method signature:
get_insights(ip_address: &str) -> Result<InsightsResponse, Box<dyn std::error::Error>>
Response:
pub struct InsightsResponse {
pub city: City,
pub continent: Continent,
pub country: Country,
pub location: Location,
pub postal: Postal,
pub represented_country: Option<RepresentedCountry>,
pub registered_country: RegisteredCountry,
pub subdivisions: Vec<Subdivision>,
pub traits: Traits,
pub maxmind: MaxMind,
}