diff --git a/matrix/api.lua b/matrix/api.lua index e13a3fe..5e2d45a 100644 --- a/matrix/api.lua +++ b/matrix/api.lua @@ -25,24 +25,24 @@ local function get_debug_log_function() end end -local get_http_factory = function (http_factory) +local get_http_client = function (http_client) -- The environment variable has precedence, as it is used to aid debugging. do local env_value = os.getenv("MATRIX_API_HTTP_CLIENT") if env_value and #env_value > 0 then - http_factory = env_value + http_client = env_value end end -- Try to import supplied HTTP client libraries, in order of preference. - local tries = http_factory and { http_factory } or { "chttp", "luasocket" } + local tries = http_client and { http_client } or { "chttp", "luasocket" } local errors = {} - for i, http_factory in ipairs(tries) do - local ok, factory = pcall(require, "matrix.factory." .. http_factory) + for i, http_client in ipairs(tries) do + local ok, client = pcall(require, "matrix.httpclient." .. http_client) if ok then - get_http_factory = function () return factory end - return get_http_factory() + get_http_client = function () return client end + return get_http_client() end - errors[i] = factory + errors[i] = client end local errmsg = { "Could not load any HTTP client library:" } for i, name in pairs(tries) do @@ -57,14 +57,14 @@ local API = {} API.__name = "matrix.api" API.__index = API -setmetatable(API, { __call = function (self, base_url, token, http_factory) +setmetatable(API, { __call = function (self, base_url, token, http_client) return setmetatable({ base_url = base_url, token = token, txn_id = 0, api_path = "/_matrix/client/r0", -- TODO: De-hardcode _log = get_debug_log_function(), - _http = get_http_factory(http_factory)(), + _http = get_http_client(http_client)(), }, API) end }) diff --git a/matrix/client.lua b/matrix/client.lua index f0d058a..6c33ca3 100644 --- a/matrix/client.lua +++ b/matrix/client.lua @@ -296,12 +296,12 @@ local Client = {} Client.__name = "matrix.client" Client.__index = Client -setmetatable(Client, { __call = function (self, base_url, token, http_factory) +setmetatable(Client, { __call = function (self, base_url, token, http_client) local c = eventable.object(setmetatable({ presence = {}, -- Indexed by user_id rooms = {}, -- Indexed by room_id _log = get_debug_log_function(), - _api = API(base_url, token, http_factory), + _api = API(base_url, token, http_client), }, Client)) -- Do an initial sync if a token was provided on construction. if token then diff --git a/matrix/factory/chttp.lua b/matrix/httpclient/chttp.lua similarity index 97% rename from matrix/factory/chttp.lua rename to matrix/httpclient/chttp.lua index 2500a06..0f01ac9 100644 --- a/matrix/factory/chttp.lua +++ b/matrix/httpclient/chttp.lua @@ -14,7 +14,7 @@ local httpclient = { quote = require "http.util" .encodeURI, unquote = require "http.util" .decodeURI, } -httpclient.__name = "matrix.factory.chttp" +httpclient.__name = "matrix.client.chttp" httpclient.__index = httpclient function httpclient:__tostring() diff --git a/matrix/factory/luasocket.lua b/matrix/httpclient/luasocket.lua similarity index 97% rename from matrix/factory/luasocket.lua rename to matrix/httpclient/luasocket.lua index af0ebca..ef0876e 100644 --- a/matrix/factory/luasocket.lua +++ b/matrix/httpclient/luasocket.lua @@ -41,7 +41,7 @@ local httpclient = { quote = require "socket.url" .escape, unquote = require "socket.url" .unescape, } -httpclient.__name = "matrix.factory.luasocket" +httpclient.__name = "matrix.client.luasocket" httpclient.__index = httpclient function httpclient:__tostring()