Skip to content
An integration between Automatic API and the Forecast Weather API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bin
config
db
lib
log
public
vendor/assets
.bowerrc
.buildpacks
.env.sample
.gitignore
Gemfile
Gemfile.lock
LICENSE.md
Procfile
README.md
Rakefile
bower.json
config.ru
package.json

README.md

Automatic Trip Weather

This joins the Automatic API and the Forecast.io API to show weather information for your last week trips.

You can see it in action at: https://automatic-weather.herokuapp.com

Getting Started

You need to register an Automatic Client Application, register for Forecast.io API access, and register for a Mapbox Token.

Once you have access to these, you will want to add your credentials to the .env file.

cp .env.sample .env

And fill in your credentials for each of those services.

Developing with this locally will require you to be able to Sign in with Automatic. In order to achieve this, you can use ngrok to specify your Automatic Client URLs.

Next you will want to:

# Install application dependencies
bundle install 

# Install ui dependencies
bundle exec rake bower:install

Now your application should be ready to boot up:

# Start it with Unicorn
bundle exec foreman start

# Start it with Rails
bundle exec rails server

If you are using ngrok, you can start that up with:

ngrok 3000

Specify the port your application runs on

Now you should be able to view your application in the browser, sign in with Automatic, and see your trips.

I also keep my Forecast.io developer page up to ensure I am not exceeding my daily limits. You can see this in their Developer console or by viewing your HTTP requests in the log to see their X-Forecast-API-Calls header.

Overview

In order to view this application you need to register for a Dark Sky Forecast API account and get your API Key.

Next you need to ensure you have an Automatic API Client setup and have a CLIENT_KEY and CLIENT_SECRET.

How does it work

The application utilizes the OmniAuth Automatic rubygem, Automatic Client rubygem, and the Forecast.io API to stitch together trip data and weather data.

The application currently only shows your last week's worth of trip data. We leave it as an exercise to the reader to allow pagination back through more data. We achieve this by using Automatic's filtering on Trips, and specifying a started_at__gte to 1.week.ago.

Once we have the trips, we focus in on the data we want to render to the interface.

Often times shorter trips have both a start and end in the same city, and within the same hour. In this case we didn't want to make duplicate calls to the Forecast.io API. We create a simple CacheStore that only needs to geocode and request if we don't already have a stored key for the city, state, and datetime. We compute a checksum from those values to reference as our cache key.

The simple CacheStore is single request based only. It does not keep a memory cache. This is an exercise left to the reader.

We wanted to show trips grouped by their day. Our Trip records have a start_location and end_location, and we wanted the weather for both of those points. A trip could span over the time of 2 days or multiple timezones. Our first iteration groups all of the trips by their timestamp of YYYY-MM-DD.

Once we have iterated through our trips, we push them into a new data structure and Presenter that is then passed on to the Interface.

Icons

The beautiful weather icons are provided by Erik Flowers

Homework

Here are some other things that could be done to enhance the application.

  • Extract the coordinates from the polyline and plot out the weather for the entire trip.
  • Show other pieces of weather information
  • Allow you to paginate by days of trips, to keep going back in time.
  • Integrate the weather with the Automatic webhooks data to show weather for a given event.
  • Cache the weather data in a database or memory store to prevent API calls to the Forecast.io service.

License

This project is licensed under the terms of the Apache 2.0 license.

You can’t perform that action at this time.