Commit Graph

22 Commits

Author SHA1 Message Date
Adrian Perez de Castro
bd811c859e Rename matrix.factory.* -> matrix.httpclient.*
The old name didn't really make much sense after all...
2016-07-01 05:10:22 +03:00
Adrian Perez de Castro
e128366f7f Use eventables in matrix.client, implement a chunk of functionality
Yeah, I know: commits should have been smaller and all that. Yadda-yadda.
2016-07-01 05:05:50 +03:00
Adrian Perez de Castro
fc99710658 Improvements to matrix.eventable
* Support debug-logging to stderr by defining the MATRIX_EVENTABLE_DEBUG_LOG
  environment variable.
* Support for unhooking handlers from events.
* Simplify the low-level interface: eventable.functions() now returns the
  created functions directly, cutting down on an intermediate table.
* A new eventable.object() allows adding :hook(), :unhook() and :fire()
  methods to any table. Firing events always sends the table itself as first
  event parameter when firing any event.
2016-07-01 04:55:16 +03:00
Adrian Perez de Castro
99fbf8eb28 First pass at an event-based notification facilty
The matrix.eventable module/function returns a table with a pair of functions
which can be used to connect event handlers to events, and to generate them.
Basic usage is as follows:

  obj = eventable()
  obj.hook("event-name", print)  -- Handle the event with "print"
  obj.fire("event-name", "Hello, world")  -- Prints "Hello, world"

This initial implementation has the following limitations:

* Event handlers are always invoked in the same order in which they have been
  connected using the .hook() function.
* Individual event handlers cannot be disconnected. Only disconnecting all
  handlers for en event at once is possible via .hook("event", nil).
2016-06-30 00:24:24 +03:00
Adrian Perez de Castro
5a23cb5b85 Use the /sync endpoing instead /initialSync
The /initialSync endpoint is deprecated. This renames the api:initial_sync()
method to api:sync(), and uses the new endpoint.
2016-06-30 00:12:55 +03:00
Adrian Perez de Castro
0a58777f42 Use MATRIX_API_DEBUG_LOG environment variable
The new name indicates in a clearer way that it enables logging of matrix.api
operations.
2016-06-30 00:11:18 +03:00
Adrian Perez de Castro
9fb0bed7c0 Use "[api]" as log prefix instead of "[http]"
The old prefix could be confusing if the homeserver URL used the https://
scheme, and the new one better conveys that it is matrix.api who is doing
the logging.
2016-06-30 00:09:56 +03:00
Adrian Perez de Castro
4e27bedc12 README: Mention the LuaSocket/LuaSec-based HTTP client 2016-06-28 23:52:45 +03:00
Adrian Perez de Castro
daa8bfe923 Implement a LuaSocket/LuaSec-based HTTP client
Note that LuaSec is actually optional, and will be loaded on-demand when the
first request using the https:// scheme is issued.
2016-06-28 23:47:51 +03:00
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
Adrian Perez de Castro
cf14c37e58 Log the HTTP client being used with each request 2016-06-28 23:22:21 +03:00
Adrian Perez de Castro
28477c4db7 Always stringigy returned HTTP status code for logging
This avoids the potential issue in which the status code would be "nil" or
"false", which HTTP client libraries may choose to signal an error condition.
2016-06-28 23:21:04 +03:00
Adrian Perez de Castro
724d7cdd54 Simplify HTTP client API
* The :quote and :unquote methods are now plain functions and no longer
  receive the "self" parameter. This allows to directly use the utility
  functions provided by the HTTP client library.
* Renamed CqHttpClient to plain "httclient". The variable itself is local
  to the script so it does not need to be unique.
2016-06-28 23:20:50 +03:00
Adrian Perez de Castro
1c13a32e86 examples: Add get-user-info.lua 2016-06-23 13:41:41 +03:00
Adrian Perez de Castro
5f53ecd349 README: Add RockZ self-promotion 2016-06-23 13:40:38 +03:00
Adrian Perez de Castro
e0d49f793d README: List requirements and LuaRocks instructions 2016-06-23 13:36:31 +03:00
Adrian Perez de Castro
3752be9a73 Add README file 2016-06-23 13:19:36 +03:00
Adrian Perez de Castro
a1cf21b839 Implement room:update_room_{topic,aliases,name} 2016-06-23 04:17:15 +03:00
Adrian Perez de Castro
56a57f2e89 Add __tostring metamethods to prototypes
This is nice to have, and aids with debugging and interactive usage.
2016-06-23 04:07:01 +03:00
Adrian Perez de Castro
ec288bf9fd Make it possible to import "matrix" directly
This aliases "matrix.client", making both the following equivalent:

  matrix = require "matrix.client"
  matrix = require "matrix"
2016-06-23 03:55:09 +03:00
Adrian Perez de Castro
cafb8724e3 Import rough implementation of matrix.client 2016-06-23 03:54:48 +03:00
Adrian Perez de Castro
6528727cff Initial import: low-level API wrapper 2016-06-23 03:49:04 +03:00