Moon data from US Naval Observatory with Reqwest and Serde_json#22
Moon data from US Naval Observatory with Reqwest and Serde_json#22robbystk wants to merge 13 commits into
Conversation
Reqwest includes the `json()` method on a response which uses Serde's `DeserializeOwned` trait on whatever type you want to deserialize to. So we make up some structs and an enum to hold the data from the json. The enum is problematic because the moon phases in the json have spaces in them, and enum variants are not allowed to contain spaces. Manually implementing `Deserialize` for the enum seems to be the most-elegant way around that.
|
I realized there is an easier, more-elegant way to process the json data. Instead of making custom data structures to hold all the data, we can parse the json with serde_json::from_str(), then just pick out what we need. This will also remove serde as a dependency. Therefore, I will close this PR for now, and re-open it when the alternate solution is complete. |
|
I've streamlined the json parsing and removed a lot of extraneous stuff. This still has a test that hits USNO's API but it's ignored. A solution to that would be to use the |
Reqwest and serde_json
Reqwest and serde_json|
The test suite now uses a stub to avoid hitting USNO's API. There is still an ignored test that does hit it, which you may remove if you wish. I just realized that there's another way to do this. The way I did it was to create a |
Here is a function that fetches data on the moon phase from USNO and returns the raw json.