<file_sep>class ApplicationController < ActionController::Base
  protect_from_forgery
  # def mapquest_api
  #   directions = Typhoeus.get(
  #     "http://www.mapquestapi.com/directions/v2/route?key=Fmjtd%7Cluubn90z29%2Cr0%3Do5-902wda&from=San+Diego,CA&to=Los+Angeles,CA"
  #   )

  #   @results = JSON.parse(directions.body)
  #   return @results
  # end

  def fiveoneone_api(origin, destination)
    url = "http://services.my511.org/traffic/getpathlist.aspx?token=<PASSWORD>?&o=#{origin}&d=#{destination}"
    @results = Nokogiri::XML(open(url))
    return @results
  end
end
<file_sep>TrafficEstimatorApp::Application.routes.draw do
  root to: "home#index"
  get "/cities/:id", to: "cities#show"
end
<file_sep>class CitiesController < ApplicationController
  def show
    require 'nokogiri'
    require 'open-uri'
    @traveltimes = []
    @origin = City.find(params[:id])
    @cities = City.all
    @cities.each do |city|
      drive_time = fiveoneone_api(@origin.node, city.node)
      current_traffic = @results.xpath("/paths/path[1]/currentTravelTime").text
      normal_traffic = @results.xpath("/paths/path[1]/typicalTravelTime").text
      @traveltimes << [current_traffic, normal_traffic]
    end
  end
end
<file_sep># This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)

City.create( name: "San Jose", node: 347 )
City.create( name: "San Francisco", node: 780 )
City.create( name: "Oakland", node: 1279 )
City.create( name: "Fremont", node: 44 )
City.create( name: "Santa Rosa", node: 274 )
City.create( name: "Hayward", node: 800 )
City.create( name: "Sunnyvale", node: 276 )
City.create( name: "Concord", node: 696 )
City.create( name: "Santa Clara", node: 366 )
City.create( name: "Vallejo", node: 712 )
City.create( name: "Berkeley", node: 1222 )
City.create( name: "Fairfield", node: 1200 )
City.create( name: "Richmond", node: 1230 )
City.create( name: "Antioch", node: 723 )
City.create( name: "Daly City", node: 88 )<file_sep>class HomeController < ApplicationController
  include HomeHelper
  def index
    ## FOR MAPQUEST
    # drive_time = mapquest_api
    # @current_condition = drive_time["route"]["realTime"]/60
    # @normal_condition = drive_time["route"]["time"]/60
  end

  def show

  end
end
<file_sep>module HomeHelper
  # def mapquest_api
  #   directions = Typhoeus.get(
  #     "http://www.mapquestapi.com/directions/v2/route?key=<KEY>&from=San+Diego,CA&to=Los+Angeles,CA"
  #   )

  #   @results = JSON.parse(directions.body)
  #   return @results
  # end
  # mapquest_api(origin, dest)
end
<file_sep>class City < ActiveRecord::Base
  attr_accessible :name, :node
end
