From 42da0d9ee3a8fae50d4e70fc8c747eed45baf581 Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Sun, 24 May 2020 00:56:31 -0700 Subject: [PATCH] Some code cleanup --- src/js/store.js | 3 ++- src/js/subscription.js | 8 ------- urbit/app/bartinfo.hoon | 47 +++++++++++++++++------------------------ 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/js/store.js b/src/js/store.js index 50da21b..7b8b8de 100644 --- a/src/js/store.js +++ b/src/js/store.js @@ -22,6 +22,7 @@ class Store { handleEvent(data) { let json = data.data; + console.log("Storing event"); console.log(json); this.initialReducer.reduce(json, this.state); this.configReducer.reduce(json, this.state); @@ -32,4 +33,4 @@ class Store { } export let store = new Store(); -window.store = store; \ No newline at end of file +window.store = store; diff --git a/src/js/subscription.js b/src/js/subscription.js index c8d1158..646c6ef 100644 --- a/src/js/subscription.js +++ b/src/js/subscription.js @@ -6,9 +6,7 @@ import urbitOb from 'urbit-ob'; export class Subscription { start() { - console.log("Calling start()") if (api.authTokens) { - console.log("would initialize"); this.initializebartinfo(); } else { console.error("~~~ ERROR: Must set api.authTokens before operation ~~~"); @@ -16,7 +14,6 @@ export class Subscription { } initializebartinfo() { - console.log("Initialize bart info"); api.bind('/primary', 'PUT', api.authTokens.ship, 'bartinfo', this.handleEvent.bind(this), this.handleError.bind(this)); @@ -28,11 +25,6 @@ export class Subscription { handleError(err) { console.error(err); - /* - api.bind('/primary', '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 070a7ea..4db1e95 100644 --- a/urbit/app/bartinfo.hoon +++ b/urbit/app/bartinfo.hoon @@ -59,8 +59,6 @@ %print-chutney ~& "CHUTNEY" [~ this] %print-state ~& this [~ this] %give-number [[%give %fact ~[/primary] %json !>(*json)]~ this] - ::%yolo [[%give %fact ~ %noun [@ 299]]~ this] - ::%hella [[%give %fact ~ %json !>((bogus-json:cc))]~ this] == %handle-http-request =+ !<([eyre-id=@ta =inbound-request:eyre] vase) @@ -73,15 +71,15 @@ :: ++ on-watch |= =path - ^- (quip card:agent:gall _this) + ^- (quip card _this) ~& "on-watch path: {}" ?: ?=([%primary *] path) =/ initial-resp [%give %fact ~ %json !>((bogus-json:cc))] - =/ out *outbound-config:iris - =/ req request-bart-stations:cc - ::=/ bart-station-request [%pass /[(scot %da now.bol)] %arvo %i %request req out] - =/ bart-station-request [%pass /bartstationrequest %arvo %i %request req out] - [[initial-resp bart-station-request ~] this] + =/ bart-station-request + =/ out *outbound-config:iris + =/ req bart-api-request-stations:cc + [%pass /bartstationrequest %arvo %i %request req out] + [~[initial-resp bart-station-request] this] ?: ?=([%http-response *] path) `this ?. =(/ path) @@ -93,13 +91,14 @@ ++ on-arvo |= [=wire =sign-arvo] ^- (quip card _this) + ~& "on-arvo wire: {}" ?: ?=(%http-response +<.sign-arvo) - ~& "WIRE: {}" - ::~& "SIGN ARVO: {}" - =/ value %- pairs:enjs:format - :~ fulltext+s+(crip "{}") - == - [[%give %fact ~[/primary] %json !>(value)]~ this] + =/ http-moves=(list card) + =/ value %- pairs:enjs:format + :~ fulltext+s+(crip "{}") + == + [%give %fact ~[/primary] %json !>(value)]~ + [http-moves this] ?. ?=(%bound +<.sign-arvo) (on-arvo:def wire sign-arvo) [~ this] @@ -116,9 +115,14 @@ :: :: request to http://api.bart.gov/api/stn.aspx?cmd=stns&key=Q5RQ-PUEB-999T-DWEI&json=y :: get .root | .stations | .station for list of stations - ++ bart-api-key "Q5RQ-PUEB-999T-DWEI" ++ bart-api-url-base "http://api.bart.gov/api" +++ bart-api-request-stations + ^- 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)] +:: ++ poke-handle-http-request |= =inbound-request:eyre ^- simple-payload:http @@ -145,17 +149,4 @@ :~ success+b+%.y == -++ request-bart-stations - ^- 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)] -::;++ request-darksky -:: |= location=@t -:: ^- request:http -:: =/ base 'https://api.darksky.net/forecast/634639c10670c7376dc66b6692fe57ca/' -:: =/ url=@t (cat 3 (cat 3 base location) '?units=auto') -:: =/ hed [['Accept' 'application/json']]~ -:: [%'GET' url hed *(unit octs)] -:: --