-
Notifications
You must be signed in to change notification settings - Fork 16
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
Update weather API to Tomorrowio #689
Conversation
backend/Gemfile
Outdated
# wrapper for forecast.io API, Dark Sky | ||
gem "forecast_io" | ||
# wrapper for tomorrow.io API | ||
gem "tomorrowio_rb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice parallelism
@@ -1,6 +1,6 @@ | |||
class WeatherRetriever | |||
class << self | |||
def get(date, postal_code) | |||
def get(date, latitude, longitude) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ncie to not have to go thru postal code for this api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this break the code below? the method expects postal_code
in a few places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, yeah I meant to remove postal_code
in those places and replace it with coordinates.
|
||
if the_day.blank? | ||
Rails.logger.warn "No forecast found for position #{position.inspect}: #{forecast.inspect}" | ||
if forecast.status != 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense 200
forecast | ||
end | ||
|
||
def create_weather(the_day, position_id) | ||
def create_weather(forecast, position_id) | ||
today = forecast.body["timelines"]["daily"][0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe use "dig" for json safety?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'm pretty unfamiliar with Ruby and did not know about dig, I will look into that further and make some changes.
) | ||
end | ||
|
||
def get_icon_legacy(today) | ||
# Our icons do not coverage their full range of weather codes. We could pull in their icons (linked below) on the frontend to expand options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
Postal code is non nullable in the DB
I am excited for this to go thru! |
Resolves #535
Context
The Dark Sky API has been completely shut down for some time now so we are migrating to Tomorrow.io to bring back weather data for users.
Approach
I first wrote a small wrapper for the API in Ruby and created a gem for that. This PR removes the old Dark Sky gem and adds my new gem and refactors the weather retriever service to use the new API. By and large the data is mostly backwards compatible with a few exceptions noted below. Notably, it was not necessary to change the Geolocation API since that is still in use. There were some previous reports of getting the wrong weather data for a given location, so it's possible we may still want to replace the Geolocation API (possibly with the browser geolocation API if that continues to be a problem.
Exceptions to backwards compatibility
Tests
Tests to follow, I need to familiarize myself with the VCR package being used here as well as generate the requisite API data for that. Just want to put up an initial draft PR to get some feedback on this so far.
Other resources
Expand for API translations that I came up with