Created
July 25, 2013 01:19
-
-
Save aussiegeek/6076115 to your computer and use it in GitHub Desktop.
Job to get tram data for dashing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rexml/document" | |
SCHEDULER.every '1m', :first_in => 0 do |job| | |
stop_no = 1819 | |
url = URI.parse('http://ws.tramtracker.com.au/pidsservice/pids.asmx') | |
request =Net::HTTP::Post.new(url.path) | |
request.body = %Q{<?xml version="1.0" encoding="utf-8"?> | |
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> | |
<soap12:Header> | |
<PidsClientHeader xmlns="http://www.yarratrams.com.au/pidsservice/"> | |
<ClientGuid>391f09fd-3b98-44e0-b6cd-575ca2b97e2b</ClientGuid> | |
<ClientType>IPHONEPID</ClientType> | |
<ClientWebServiceVersion>6.4.0.0</ClientWebServiceVersion> | |
<ClientVersion>1.5</ClientVersion> | |
<OSVersion>7.0</OSVersion> | |
</PidsClientHeader> | |
</soap12:Header> | |
<soap12:Body> | |
<GetNextPredictedRoutesCollection xmlns="http://www.yarratrams.com.au/pidsservice/"> | |
<lowFloor>false</lowFloor> | |
<stopNo>#{stop_no}</stopNo> | |
<routeNo>0</routeNo> | |
</GetNextPredictedRoutesCollection> | |
</soap12:Body> | |
</soap12:Envelope> | |
} | |
request.add_field("Content-Type", "application/soap+xml; charset=utf-8") | |
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)} | |
services = [] | |
doc = REXML::Document.new response.body | |
REXML::XPath.each(doc, '//ToReturn').to_a.each do |toreturn| | |
data = {} | |
data[:value] = ((Time.parse(toreturn.elements['PredictedArrivalDateTime'].text).to_i - Time.now.to_i) / 60).to_s + " minutes" | |
data[:label] = toreturn.elements['RouteNo'].text | |
services << data | |
end | |
send_event('trams', {items: services }) | |
end |
Nice Alan, particularly now I'm working on a tram line again... are there any docs about the tram tracker API out there or did you just sniff enough to get this working? I'd like to write a little Mac app that sends OS X Notifications when it's time for me to get the tram home!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Alan, thats about the simpliest/smallest example for the tramtracker api that I've seen so far, gotta love SOAP :-)