Closed vuinguyen closed 4 years ago
Udacity mentor Phuong recommended selecting an API that requires an API key (said not necessary but a good practice) and uses HTTPS
I plan to use weatherbit.io for the Weather API. To use this API, we'll need the following info:
location (either city, state or latitude and longitude)
date and time (if recording a past fishing trip, and not a current one happening now) -- This is not required to call the current weather API, but it will be needed to call the historical weather API, which is not what we're going to use for the MVP.
For now, I think the following use cases will need to be handled:
[ ] The weather API will be called when the user taps the "Get Weather" button in the journal editing window.
[ ] The weather API will need to use the date and time info, and the location info, from their respective fields in the journal editing window to make the API call, if possible
-- The current weather API does not need date and time info in the query parameters of the REST call, but it will still need location. This will still simplify calling the current weather API immensely.
[ ] If date and time is close to current time, use the current weather API: https://www.weatherbit.io/api/weather-current
[OBE] If date and time is in the past, use the historical daily weather API: https://www.weatherbit.io/api/weather-history-daily -- To simply things, we will use only the current weather API for now. We can use the historical data for a future feature.
[ ] If the location field was filled in manually by the user, use that location to call the weather API
[ ] If the location field was left blank, use geolocation (if turned on) to find the location, perhaps fill in the location field for the user, and use this location to call the weather API
[ ] If we cannot find the location either because geolocation was turned off and/or the user typed in an invalid location in the location field, then the call to the weather API will fail and display an error message to the user.
[ ] If the call to the weather API fails for any reason, the user still has the option to type into the weather field manually.
Below is an example of the Journal Editing window:
One thing I could do, which would be a great use of NSUserDefaults, issue #11, is store the use of Fahrenheit or Celsius for temperature, in user defaults.
I've modified the UI for the weather feature, in anticipation of displaying the weather data from Weatherbit.io . I've also been experimenting with the Weatherbit.io API in a separate playground. Getting ready to integrate that code into the app soon. Baby steps ...
Right now, the "Get Current Weather" button only works if you tap on "Get My Location" button first and get the location. Because the Weather API requires a location to work.
This is what it looks like when the "Get Current Weather" function is successfully called:
More testing will need to be done to ensure that all the CRUD operations for Weather, esp. with regards to Core Data, works correctly. Also, I haven't decided yet if I will implement other use cases to fill the Weather boxes (ie allow the weather feature to call geolocation as a nested asynchronous call with the weather API, instead of requiring that gelocation be called prior to the weather API call using the "Get My Location!" button) now or later after submitting my project for Udacity review.
Still, this progress was a long time coming, so I will take a break for now and briefly celebrate.
Example of JSON coming back from the Weatherbit.io API call:
When I'm ready to go back and work on the weather /location feature again, here are a couple of helpful links for reference: https://developer.apple.com/documentation/corelocation/converting_between_coordinates_and_user-friendly_place_names
https://developer.apple.com/documentation/corelocation/clgeocoder
I am calling this issue done for now. The other use cases / ways to implement Weather I may do after my project has been reviewed.
Here we grab data from a weather API.
If that is not possible, allow user to manually add weather data.