mirror of
https://github.com/bsima/haskell-urbit-api.git
synced 2024-08-17 14:00:31 +03:00
Add example to readme
This commit is contained in:
parent
88072f53e3
commit
486c404c1f
42
README.md
42
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)
|
||||
|
Loading…
Reference in New Issue
Block a user