My solution for a weather report programming challenge. Try it out here
- Accept an address as input
- Retrieve forecast data for the given address. This should include, at minimum, the current temperature (Bonus points - Retrieve high/low and/or extended forecast)
- Display the requested forecast details to the user
- Cache the forecast details for 30 minutes for all subsequent requests by zip codes.
- Display indicator if result is pulled from cache.
As the prompt requires, once the service is running you can enter:
- an address
- city & state
- city & country
... and the app will return:
- current temperature
- high/low
- extended forcast
It will also cache responses for 30 mins per zip code.
- openweathermap - Provides a clean way to get forecast data from OpenWeatherMap's API. OpenWeatherMap's call limits on the free tier are very flexible
- geocoder - I'll ensure the address passed in is valid before I make the call to OpenWeatherMap. I'll be using the lat/long in the response in my OpenWeatherMap call.
- rspec-rails - RSpec has become a standard in the Rails community and is my favoritee unit testing library
- webmock - Webmock ensures that no network requests are allowed during test runs.
- timecop - "A gem providing "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code." ~Timecop repository.
- pry-byebug - Helpful for setting breakpoints while building the solution
- foreman - Useful to manage both my Puma web server and my webpacker server.
** I have
Procfile
for Heroku andProcfile.dev
for my local environment. - dotenv-rails - Useful to load environment variables from my .env file.
- redis - Using Redis to store my cached weather calls. Redis' TTL method allows me to easily get the expiration time of the cached data.
- Install Ruby 3.x
- I'm using the latest version of Ruby, but any version of Ruby 3 should work.
- Install Redis
- Required for caching
- Install Bundler
gem install bundler
- Run
bundle install
- This will install all required gems for the app.
-
Copy the .env-sample and save it as
.env
. You'll need to get an API key for OpenWeatherMap for this solution to work. TheRaygun
API key is a nice to have for error reporting that isn't a necessity. -
Run
foreman start -f Procfile.dev
After running installing Ruby & Bundler as outlined in the Get started
section above, run bundle exec rspec
to run the suite of tests I wrote for this project.
If you'd like you can also run bundle exec rubocop
to see how I've stayed in Ruby best practices. Adjustments I've made to Rubocop can be found here