Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using the metra Rail-Time Tracker API
(ns metra
(:require [cheshire.core :refer [generate-string parse-string]
[clj-http.client :as http]))
(defn get-trains []
(let [timestamp (str "/Date(" (.getTime (java.util.Date.)) "-0000)/")
body {:stationRequest {:Corridor "MD-N", :Destination "LIBERTYVIL", :Origin "CUS", :timestamp timestamp}}
response (http/post "" {:body (generate-string body) :content-type :json})
resp-body (parse-string ((parse-string (response :body) true) :d) true)]

This comment has been minimized.

Copy link
Owner Author

@robertjlooby robertjlooby commented Oct 16, 2013

(def lines {:mdnl {:name "Milwaukee District / North Line"
                         :code "MD-N"}})
(def stations {:union {:name "Chicago Union Station"
                               :code "CUS"}
                    :libertyville {:name "Libertyville"
                                     :code "LIBERTYVIL"}})

;to get a title
(str (get-in stations [:union :name]) " to " (get-in stations [:libertyville :name]))

;to get request body
{:stationRequest {:Corridor (get-in lines [:mdnl code]), :Destination (get-in stations [:libertyville :code]), :Origin (get-in stations [:libertyville :code]), :timestamp timestamp}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment