From 486c404c1f14e512cbfe5a481b21606e48509207 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 13 Nov 2020 14:52:04 -0500 Subject: [PATCH] Add example to readme --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index f055599..1255a06 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,48 @@ for more details. This library is built on req, conduit, and aeson, all of which are very stable and usable libraries for working with HTTP requests and web data. +## Example usage + +```haskell +import qualified Data.Aeson as Aeson +import Data.Aeson ((.=)) +import qualified Data.Text as Text +import qualified Data.UUID.V4 as UUID + +import Urbit.Airlock + +main :: IO () +main = do + let fakezod = Ship + { uid = "0123456789abcdef", + name = "zod", + lastEventId = 1, + url = "http://localhost:8081", + code = "lidlut-tabwed-pillex-ridrup" + } + + -- Establish connection + sess <- connect ship + + -- Send a message by poking the chat-hook + uuid <- UUID.nextRandom + poke sess ship "zod" "chat-hook" "json" $ + Aeson.object + [ "message" + .= Aeson.object + [ "path" .= Text.pack "/~/~zod/mc", + "envelope" + .= Aeson.object + [ "uid" .= UUID.toText uuid, + "number" .= (1 :: Int), + "author" .= Text.pack "~zod", + "when" .= (1602118786225 :: Int), + "letter" .= Aeson.object ["text" .= Text.pack "hello world from haskell!"] + ] + ] + ] +``` + ## TODO - fix test suite on travis (OOM when trying to compile urbit)