Cleaning up a bunch of json-parsing
This commit is contained in:
parent
f10946b96d
commit
0293b9c6ee
@ -160,23 +160,15 @@
|
|||||||
|= response=client-response:iris
|
|= response=client-response:iris
|
||||||
^- json
|
^- json
|
||||||
=, format
|
=, format
|
||||||
=/ handler |= parsed-json=json
|
=/ handler |= jon=json
|
||||||
?> ?=(%o -.parsed-json)
|
=/ root ((ot:dejs ~[['root' same]]) jon)
|
||||||
=/ root=json (~(got by p.parsed-json) 'root')
|
=/ stations ((ot:dejs ~[['stations' same]]) root)
|
||||||
?> ?=(%o -.root)
|
=/ station ((ot:dejs ~[['station' (ar:dejs same)]]) stations)
|
||||||
=/ stations (~(got by p.root) 'stations')
|
=/ abbr-and-name %- turn :- station |= item=json
|
||||||
?> ?=(%o -.stations)
|
|
||||||
=/ station=json (~(got by p.stations) 'station')
|
|
||||||
?> ?=(%a -.station)
|
|
||||||
=/ inner p.station
|
|
||||||
=/ abbr-and-name %- turn :- inner |= item=json
|
|
||||||
^- json
|
^- json
|
||||||
?> ?=(%o -.item)
|
=/ [name=tape abbr=tape]
|
||||||
=/ name (~(got by p.item) 'name')
|
((ot:dejs ~[['name' sa:dejs] ['abbr' sa:dejs]]) item)
|
||||||
?> ?=(%s -.name)
|
(pairs:enjs ~[name+(tape:enjs name) abbr+(tape:enjs abbr)])
|
||||||
=/ abbr (~(got by p.item) 'abbr')
|
|
||||||
?> ?=(%s -.abbr)
|
|
||||||
(pairs:enjs [name+s+p.name abbr+s+p.abbr ~])
|
|
||||||
(pairs:enjs [[%stations %a abbr-and-name] ~])
|
(pairs:enjs [[%stations %a abbr-and-name] ~])
|
||||||
(with-json-handler response handler)
|
(with-json-handler response handler)
|
||||||
::
|
::
|
||||||
@ -190,10 +182,8 @@
|
|||||||
^- json
|
^- json
|
||||||
=, format
|
=, format
|
||||||
=/ handler |= jon=json
|
=/ handler |= jon=json
|
||||||
?> ?=(%o -.jon)
|
=/ root=json ((ot:dejs ~[['root' same]]) jon)
|
||||||
=/ root=json (~(got by p.jon) 'root')
|
=/ bsa=json ((ot:dejs ~[['bsa' same]]) root)
|
||||||
?> ?=(%o -.root)
|
|
||||||
=/ bsa=json (~(got by p.root) 'bsa')
|
|
||||||
?> ?=(%a -.bsa)
|
?> ?=(%a -.bsa)
|
||||||
~& -.bsa
|
~& -.bsa
|
||||||
(pairs:enjs [[%elevators %a p.bsa] ~])
|
(pairs:enjs [[%elevators %a p.bsa] ~])
|
||||||
@ -207,7 +197,7 @@
|
|||||||
=/ meridian ?:(ispm "pm" "am")
|
=/ meridian ?:(ispm "pm" "am")
|
||||||
=/ time "{<hour>}:{<min>}{meridian}"
|
=/ time "{<hour>}:{<min>}{meridian}"
|
||||||
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&time={time}&key={bart-api-key}&json=y")
|
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&time={time}&key={bart-api-key}&json=y")
|
||||||
~& url
|
~& "Making BART API request to {<url>}"
|
||||||
=/ headers [['Accept' 'application/json']]~
|
=/ headers [['Accept' 'application/json']]~
|
||||||
[%'GET' url headers *(unit octs)]
|
[%'GET' url headers *(unit octs)]
|
||||||
++ parse-routeplan-response
|
++ parse-routeplan-response
|
||||||
@ -216,7 +206,6 @@
|
|||||||
=, format
|
=, format
|
||||||
=/ handler
|
=/ handler
|
||||||
|= jon=json
|
|= jon=json
|
||||||
~& jon
|
|
||||||
=/ root=json ((ot:dejs [['root' same] ~]) jon)
|
=/ root=json ((ot:dejs [['root' same] ~]) jon)
|
||||||
root
|
root
|
||||||
(with-json-handler response handler)
|
(with-json-handler response handler)
|
||||||
|
Loading…
Reference in New Issue
Block a user