geolocate 0.2.5

A CLI for geolocation data providers
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(unused_imports)]

mod geolocation;

use clap::Parser;
use geolocation::{construct_url, Geolocation};
use serde_json::map::Map;
use serde_json::{from_str, to_string_pretty, Value};
use std::{error::Error, fmt::format};

fn main() -> Result<(), Box<dyn Error>> {
  let url = match construct_url() {
    Ok(url) => url,
    Err(err) => return Err(err),
  };

  match reqwest::blocking::get(url)?.text() {
    Ok(response) => {
      let serialized = from_str::<Map<String, Value>>(&response)?;

      println!("{}", to_string_pretty(&serialized)?);

      return Ok(());
    }

    Err(err) => {
      eprintln!("{err}");
      return Ok(());
    }
  }
}