Hoon101/201/week5/poke.hoon
2019-10-16 15:00:42 +13:00

54 lines
1.1 KiB
Plaintext

/+ tapp, stdio
::
=>
|%
+$ state
$: pokedex=(map cord json)
==
+$ peek-data _!!
+$ in-poke-data [%noun =cord]
+$ out-poke-data ~
+$ in-peer-data ~
+$ out-peer-data
$% [%pokemon json]
==
++ tapp (^tapp state peek-data in-poke-data out-poke-data in-peer-data out-peer-data)
++ stdio (^stdio out-poke-data out-peer-data)
--
=>
|%
++ comment-to-tang
|= =tape
^- tang
%+ welp
%+ turn (rip 10 (crip tape))
|= line=cord
leaf+(trip line)
[leaf+""]~
++ urls
=/ base "https://pokeapi.co/api/v2/"
:* pokemon=(weld base "pokemon/")
==
--
=, async=async:tapp
=, tapp-async=tapp-async:tapp
=, stdio
::
%- create-tapp-poke-peer-take:tapp
^- tapp-core-poke-peer-take:tapp
|_ [=bowl:gall state]
::
++ handle-poke
|= =in-poke-data
=/ m tapp-async
=/ pokename cord.in-poke-data
^- form:m
::
?: (~(has by state) pokename)
~& 'pokemon already caught'
(pure:m (~(got by state) pokename))
=/ pokeurl (weld pokemon:urls (trip pokename))
%+ (set-timeout _json) (add now.bowl ~s15)
;< =json bind:m (fetch-json pokeurl)