nwslib/geocode.rs
1// nws-cli, a CLI application that gets the forecast or current conditions from the National Weather Service
2// Copyright (C) 2024 Margaret Joan Miller
3
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>
16
17
18pub mod geocode {
19
20
21 use reqwest::Client;
22
23 use crate::grid_json::grid_json::GridJson;
24
25 pub async fn get_grids(lat: f32, long: f32) -> anyhow::Result<GridJson> {
26 let builder = reqwest::Client::builder()
27 .user_agent("nws-cli-0.1")
28 .build();
29
30 let client:Client = match builder {
31 Ok(cl) => cl,
32 Err(err) => panic!("Couldn't create client! {err}")
33 };
34
35 let echo_json_result = client
36 .get(format!("https://api.weather.gov/points/{lat},{long}"))
37 .send()
38 .await?
39 .json::<GridJson>()
40 .await?;
41 Ok(echo_json_result)
42 }
43}