Skip to content
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

Expose serde errors, and account for certain fields not existing #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openweather"
version = "0.0.1"
version = "0.0.2"
authors = ["Broderick Carlin <broderick.carlin@gmail.com>"]
description = "A rust crate wrapping openweather's API into a simple easy to use interface"
repository = "https://github.com/BroderickCarlin/openweather"
Expand All @@ -15,9 +15,9 @@ name = "openweather"
path = "src/lib.rs"

[dependencies]
reqwest = "0.8.6"
reqwest = "0.9"
serde_json = "1.0"
serde = "1.0.70"
serde_derive = "1.0.70"
time = "0.1.40"
url = "1.5.1"
url = "1.5.1"
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ fn get<T>(url: &str) -> Result<T, ErrorReport> where T: serde::de::DeserializeOw
Err(_) => {
let err_report: ErrorReport = match serde_json::from_str(res.as_str()) {
Ok(report) => {report},
Err(_) => {
return Err(ErrorReport{cod: 0, message: format!("Got unexpected response: {:?}", res)});
Err(serde_error) => {
return Err(ErrorReport{cod: 0, message: format!("Parsing error {}\n\nResponse: {}", serde_error, res)});
}
};
return Err(err_report);
Expand Down Expand Up @@ -202,4 +202,4 @@ pub fn get_historical_uv_index(location: LocationSpecifier, key: &str, start: ti

let url = Url::parse_with_params(&base, params).unwrap();
get(&url.as_str())
}
}
4 changes: 3 additions & 1 deletion src/weather_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Coordinates {

#[derive(Serialize, Deserialize, Debug)]
pub struct CityShort {
#[serde(default)]
pub id: u32,
pub name: String,
pub coord: Coordinates,
Expand Down Expand Up @@ -57,7 +58,7 @@ pub struct Wind {
pub gust: Option<f32>,
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Default,Serialize, Deserialize, Debug)]
pub struct Rain {
#[serde(rename="3h")]
pub three_h: Option<f32>,
Expand Down Expand Up @@ -85,6 +86,7 @@ pub struct TimeSliceHourly {
pub weather: Vec<Weather>,
pub clouds: Clouds,
pub wind: Wind,
#[serde(default)]
pub rain: Rain,
pub sys: System,
pub dt_txt: String
Expand Down