Add example to readme

This commit is contained in:
Ben Sima 2020-11-13 14:52:04 -05:00
parent 88072f53e3
commit 486c404c1f

View File

@ -28,6 +28,48 @@ for more details.
This library is built on req, conduit, and aeson, all of which are very stable 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. 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 ## TODO
- fix test suite on travis (OOM when trying to compile urbit) - fix test suite on travis (OOM when trying to compile urbit)