element_kit v0.5.0 ElementKit.API

Offers convenience functions that call ELEMENT IoT API endpoints

Example:

API.get("/api/v1/streams?mandate_id=MANDATE_ID")

will expand to

HTTPoison.get("https://element-iot.com/api/v1/streams?auth=API_KEY&mandate_id=MANDATE_ID")

Convenience functionality:

  • HTTP methods with body automatically render JSON with Jason and add a content-type: application/json header.
  • The response will be parsed using Jason.

Link to this section Summary

Functions

Merges 2 URIs including their query parameters

Splits lines in a stream containing string chunks

Opens a HTTP request but returns a stream instead of the whole response at once.

Opens a WebSocket connection to the given url. An additional process is used to manage the connection. New messages will be sent to the process that called this function in this format

Link to this section Functions

Link to this function

delete(path, headers \\ [], opts \\ [])

Link to this function

get(path, headers \\ [], opts \\ [])

Link to this function

merge(a_bin, b_bin)

Merges 2 URIs including their query parameters

Link to this function

patch(path, body, headers \\ [], opts \\ [])

Link to this function

post(path, body, headers \\ [], opts \\ [])

Link to this function

put(path, body, headers \\ [], opts \\ [])

Link to this function

request(method, path, body \\ "", headers \\ [], options \\ [])

Link to this function

split_stream_lines(stream)

Splits lines in a stream containing string chunks

Link to this function

stream!(method \\ :get, path, body \\ "", headers \\ [], opts \\ [])

stream!(
  HTTPoison.method(),
  path :: binary(),
  body :: any(),
  headers :: keyword(),
  opts :: keyword()
) :: Stream.t()

Opens a HTTP request but returns a stream instead of the whole response at once.

This is useful for all /stream endpoints since they can theoretically enumerate the entire database which would make ordinary HTTP clients consume a lot of memory.

Takes the same arguments as request/5, except for the opts argument:

The options async and stream_to are always overwritten. An additional option decode_stream (bool, default true) will automatically split the received chunks by and parse each line as JSON. To disable this behaviour, pass decode_stream: false as opts.

Link to this function

ws_link(uri, opts \\ [])

ws_link(URI.t() | binary(), keyword()) :: {:ok, pid()} | {:error, any()}

Opens a WebSocket connection to the given url. An additional process is used to manage the connection. New messages will be sent to the process that called this function in this format:

{:ws, :text, message} - message will be the result of decoding then json.