geolocate 0.2.4

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(_) => return Err("Failed to build url".into()),
  };

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

      println!(
        "{}",
        to_string_pretty(&serialized).expect("Failed to prettify JSON")
      );

      return Ok(());
    }

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