README.md

# UrbitEx

UrbitEx is an Elixir package to connect to a running Urbit instance.

## Installation
The package is published at Hex, please look at https://hex.pm/packages/urbit_ex.

The package can be installed by adding `urbit_ex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:urbit_ex, "~> 0.3.5"}
  ]
end
```

## Use
After adding it to your dependencies, connect to an Urbit ship by running: 
`{:ok, pid} = UrbitEx.start(url, code)`
e.g. `{:ok, pid} = UrbitEx.start("http://localhost", "sampel-sampel-sampel-sampel")`

This will start your Urbit ship as a GenServer and start the EventSource pipeline.
You will need to subscribe to gall apps in order to your Urbit ship to start sending any events. You can do so by running:
UrbitEx.subscribe/2.
To react to events, set up your own function to react to received events and pass it to UrbitEx.recv/1.
e.g. 
       ```
       function = fn
         %{"json" => json} -> 
           case json |> Maps.keys() do
             ["graph-update"] -> IO.inspect(:chat_message)
             _ -> IO.inspect(:some_other_app)
           end
         _message -> IO.inspect(:other_message)
       end
       UrbitEx.recv(function)
       ```

You can query the GenServer state for debug purposes by running:
`GenServer.call(pid, {:get})`.

For more documentation (still rudimentary), look inside the repo or at https://hexdocs.pm/urbit_ex/0.2.0/UrbitEx.API.html#content.