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/jsonheader. - 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
delete(path, headers \\ [], opts \\ [])
get(path, headers \\ [], opts \\ [])
merge(a_bin, b_bin)
Merges 2 URIs including their query parameters
patch(path, body, headers \\ [], opts \\ [])
post(path, body, headers \\ [], opts \\ [])
put(path, body, headers \\ [], opts \\ [])
request(method, path, body \\ "", headers \\ [], options \\ [])
split_stream_lines(stream)
Splits lines in a stream containing string chunks
stream!(method \\ :get, path, body \\ "", headers \\ [], opts \\ [])
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.
ws_link(uri, opts \\ [])
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.