# HG changeset patch # User Mike Pavone # Date 1376186344 25200 # Node ID 3690601c8c70713341768462e8bbb3f570750b62 # Parent 6384e577842d59fbfa8992a54a51662e14cac37f# Parent 18a043613daebc9a6cba245de8501083f36dbfdf Merge diff -r 6384e577842d -r 3690601c8c70 src/requests.tp --- a/src/requests.tp Sat Aug 10 18:35:10 2013 -0700 +++ b/src/requests.tp Sat Aug 10 18:59:04 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"