From ed15a2a5a7770c13a6aeb27e5d946f4146b28a8b Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Mon, 1 Jun 2020 00:24:08 -0700 Subject: [PATCH] Basic infrastructure for elevators --- src/js/subscription.js | 6 +++++- urbit/app/bartinfo.hoon | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/js/subscription.js b/src/js/subscription.js index 863c5db..8dcd03f 100644 --- a/src/js/subscription.js +++ b/src/js/subscription.js @@ -20,7 +20,11 @@ export class Subscription { this.handleError.bind(this)); */ - api.bind('/bartstations', 'PUT', api.authTokens.ship, 'bartinfo', + api.bind("/elevators", "PUT", api.authTokens.ship, "bartinfo", + this.handleEvent.bind(this), + this.handleError.bind(this)); + + api.bind("/bartstations", "PUT", api.authTokens.ship, 'bartinfo', this.handleEvent.bind(this), this.handleError.bind(this)); diff --git a/urbit/app/bartinfo.hoon b/urbit/app/bartinfo.hoon index 4dac133..6bb38d5 100644 --- a/urbit/app/bartinfo.hoon +++ b/urbit/app/bartinfo.hoon @@ -79,6 +79,12 @@ =/ req bart-api-request-stations:cc [%pass /bartstationrequest %arvo %i %request req out] [~[bart-station-request] this] + ?: ?=([%elevators *] path) + =/ elevator-status-request + =/ out *outbound-config:iris + =/ req bart-api-elevator-status:cc + [%pass /elevators %arvo %i %request req out] + [~[elevator-status-request] this] ?: ?=([%http-response *] path) `this ?. =(/ path) @@ -99,6 +105,12 @@ ?> ?=(%o -.value) =/ update=json (pairs:enjs:format [update+o+p.value ~]) [%give %fact ~[/bartstations] %json !>(update)]~ +:: + [%elevators *] + =/ value=json (parse-elevator-status-response:cc client-response.sign-arvo) + ?> ?=(%o -.value) + =/ update=json (pairs:enjs:format [update+o+p.value ~]) + [%give %fact ~[/elevators] %json !>(update)]~ == [http-moves this] ?. ?=(%bound +<.sign-arvo) @@ -154,6 +166,17 @@ (pairs:enjs [name+s+p.name abbr+s+p.abbr ~]) (pairs:enjs [[%stations %a abbr-and-name] ~]) :: +++ bart-api-elevator-status + ^- request:http + =/ url (crip "{bart-api-url-base}/stn.aspx?cmd=stns&key={bart-api-key}&json=y") + =/ headers [['Accept' 'application/json']]~ + [%'GET' url headers *(unit octs)] +++ parse-elevator-status-response + |= response=client-response:iris + ^- json + =, format + (pairs:enjs [[%yolo %b %.y] ~]) +:: ++ poke-handle-http-request |= =inbound-request:eyre ^- simple-payload:http