srecord GitterREST(S personalAccessToken) { L listRooms() { ret jsonDecodeList(loadPageAuthed("https://api.gitter.im/v1/rooms")); } S loadPageAuthed(S url) { temp tempSetTL(loadPage_extraHeaders, litmap("Authorization", "Bearer " + assertNempty(personalAccessToken))); ret loadPage(url); } S postPageAuthed(S url, O... params) { temp tempSetTL(doPost_extraHeaders, litmap("Authorization", "Bearer " + assertNempty(personalAccessToken))); ret postPage(url, params); } L listMessages(S roomId, int limit) { ret jsonDecodeList(loadPageAuthed("https://api.gitter.im/v1/rooms/" + roomId + "/chatMessages?limit=" + limit); } Map sendMessage(S roomId, S text) { ret jsonDecodeMap(postPageAuthed("https://api.gitter.im/v1/rooms/" + roomId + "/chatMessages", +text)); } // TODO: restart on close CloseableIterableIterator streamMessages(S roomId) { temp tempSetTL(readHttpPageLinewise_extraHeaders, litmap("Authorization", "Bearer " + assertNempty(personalAccessToken))); ret mapI_notNulls_closeable jsonDecodeMapOrNull(readHttpPageLinewise("https://stream.gitter.im/v1/rooms/" + roomId + "/chatMessages")); } }