Adrian Perez de Castro 58ff794d92 Improve loading of HTTP client factories
This introduces a get_http_factory() function which will try to load
a HTTP client library according to the following logic:

1. If the MATRIX_API_HTTP_CLIENT environment variable is defined, it is
   taken as the name of a HTTP client library.
2. Otherwise, if the function paramter is non-nil it is used as the name
   of the HTTP client library to load.
3. Otherwise, the available HTTP client libraries are tried in order,
   and the first one which can be require()'d successfully will be
   used. For now this has only the "chttp" client.
2016-06-28 23:44:20 +03:00
2016-06-23 13:41:41 +03:00
2016-06-23 13:40:38 +03:00

Matrix Client-Server API for Lua

This is closely modelled after the official matrix-python-sdk.

Requirements

  • Lua 5.1, 5.2, 5.3, or LuaJIT — development and testing is only being done with 5.3, YMMV!
  • The cjson module.
  • Daurnimator's excellent, cqueues-based http module.

If you use LuaRocks, you can get the dependencies installed using the following commands:

luarocks install --server=http://luarocks.org/dev http
luarocks install lua-cjson

Self-promotion bit: If you use the Z shell and want something like virtualenv for Lua, please do try RockZ.

Usage

The library provides two levels of abstraction. The low-level layer wraps the raw HTTP API. The high-level layer wraps the low-level layer and provides an object model to perform actions on.

High-level matrix.client interface:

local client = require("matrix").client("http://localhost:8008")
local token = client:register_with_password("jdoe", "sup3rsecr1t")
local room = client:create_room("my_room_alias")
room:send_text("Hello!")

Low-level matrix.api interface:

local matrix_api = require("matrix.api")
local api = matrix_api("http://localhost:8080")
local response = api:register("m.login.password",
  { user = "jdoe", password = "sup3rsecr1t" })
api.token = response.token
handle_events(api:initial_sync(1))
response = api:create_room({ alias = "my_room_alias" })
api:send_text(response.room_id, "Hello!")
Description
Fork of diggers-mt/lua-matrix with some additional features
Readme 132 KiB
Languages
Lua 100%