# HG changeset patch # User William Morgan # Date 1376185185 25200 # Node ID 18a043613daebc9a6cba245de8501083f36dbfdf # Parent bb80f86c5048ff63bdddd8d834a6b8f25ea9496a added guess response. diff -r bb80f86c5048 -r 18a043613dae src/requests.tp --- a/src/requests.tp Sat Aug 10 16:31:48 2013 -0700 +++ b/src/requests.tp Sat Aug 10 18:39:45 2013 -0700 @@ -21,9 +21,6 @@ print: str . "\n" } - - - evalId <- :id args { #{ string <- { @@ -73,7 +70,7 @@ if: _code = 200 { _status <- decoded get: "status" withDefault: "error" } else: { - print: "bad status" + print: "http response gave error!, code was: " . _code } if: _status = "ok" { _outputs <- (decoded get: "outputs" withDefault: #[]) map: :num { @@ -108,6 +105,60 @@ } } + guessResponse <- :httpResp { + _code <- httpResp statusCode + bod <- httpResp body + print: "Response code: " . (string: _code) . "\n" + print: bod . "\n" + decoded <- json decode: bod + _status <- "error" + if: _code = 200 { + _status <- decoded get: "status" withDefault: "error" + } else: { + print: "http response gave error!, code was: " . _code + } + if: _status = "win" { + #{ + status <- { "win" } + string <- { "OK: win" } + print <- { + print: string . "\n" + } + } + } else: { if: _status = "mismatch" { + + _values <- (decoded get: "values" withDefault: #[]) map: :num { + (num from: 2) parseHex64 + } + #{ + status <- { "mismatch" } + values <- { _values } + string <- { + str <- "OK:" + foreach: _values :idx val { + str <- str . "\n" . (string: idx) . ": 0x" . (hex: val) + } + str + } + print <- { + print: string . "\n" + } + } + } else: { + _message <- decoded get: "message" withDefault: "" + #{ + status <- { "error" } + message <- { _message } + string <- { + "Error: " . _message + } + print <- { + print: string . "\n" + } + } + }} // end if + } + main <- :args { print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n" print: ((guessRequest: "someId" "someProg") string) . "\n"