7Grabbing JSON from some url is very easy.
9`strandio` includes the `fetch-json` function which will handle the http request and response parsing and just return unformatted json data.
11Here's a simple thread that will:
12- grab JSON of the latest base-hash from https://www.whatsthelatestbasehash.com/latesthash.json
13- grab JSON of a list of all base-hashes with version info from https://www.whatsthelatestbasehash.com/all.json
15- check `all.json` includes the latest base-hash
16- print the details of the latest base-hash to the dojo
23=, strand=strand:spider
26++ url-1 "https://www.whatsthelatestbasehash.com/latesthash.json"
27++ url-2 "https://www.whatsthelatestbasehash.com/all.json"
62;< js-latest=json bind:m (fetch-json url-1)
63;< js-all=json bind:m (fetch-json url-2)
64=/ latest `latest-sur`(latest-format js-latest)
65=/ all `(list all-sur)`(all-format js-all)
66=/ res (skim all |=(a=all-sur =(hash.a hash.latest)))
68 %- (slog leaf+"Not Found" ~) (pure:m !>(~))
69%- (slog leaf+"Hash: {(trip hash.i.res)}" ~)
70%- (slog leaf+"Pill? {?:(pill.i.res "Yes" "No")}" ~)
71%- (slog leaf+"Version: {(trip version.i.res)}" ~)
72%- (slog leaf+"Published: {(trip published.i.res)}" ~)
73%- (slog leaf+"Release: {(trip release.i.res)}" ~)
77Save it as `/ted/latest-hash.hoon`, `|commit %home` and run it with `-latest-hash`. You should see something like:
81Hash: 0vj.dqqil.77m3k.a7v8d.mvrmi.8mavk.0a2nl.te6i6.cstfa.1ko6e.872gd
84Published: ~2021.3.10..02.20.48
85Release: https://github.com/urbit/urbit/releases/tag/urbit-os-v2.39
91`fetch-json` takes a url as a tape, so we've added a core with the urls like:
96++ url-1 "https://www.whatsthelatestbasehash.com/latesthash.json"
97++ url-2 "https://www.whatsthelatestbasehash.com/all.json"
101...then just called `fetch-json` like:
104;< js-latest=json bind:m (fetch-json url-1)
107We've added formatting and structure arms like:
124...to turn it from `json` to a noun with faces. You can have a look at the JSON formatting functions under `dejs:format` in `zuse.hoon` for how to deal with the various json types.
126After that it's just some ordinary list logic and printing.
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list