Rename matrix.factory.* -> matrix.httpclient.*
The old name didn't really make much sense after all...
This commit is contained in:
@@ -25,24 +25,24 @@ local function get_debug_log_function()
|
|||||||
end
|
end
|
||||||
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.
|
-- The environment variable has precedence, as it is used to aid debugging.
|
||||||
do
|
do
|
||||||
local env_value = os.getenv("MATRIX_API_HTTP_CLIENT")
|
local env_value = os.getenv("MATRIX_API_HTTP_CLIENT")
|
||||||
if env_value and #env_value > 0 then
|
if env_value and #env_value > 0 then
|
||||||
http_factory = env_value
|
http_client = env_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Try to import supplied HTTP client libraries, in order of preference.
|
-- 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 = {}
|
local errors = {}
|
||||||
for i, http_factory in ipairs(tries) do
|
for i, http_client in ipairs(tries) do
|
||||||
local ok, factory = pcall(require, "matrix.factory." .. http_factory)
|
local ok, client = pcall(require, "matrix.httpclient." .. http_client)
|
||||||
if ok then
|
if ok then
|
||||||
get_http_factory = function () return factory end
|
get_http_client = function () return client end
|
||||||
return get_http_factory()
|
return get_http_client()
|
||||||
end
|
end
|
||||||
errors[i] = factory
|
errors[i] = client
|
||||||
end
|
end
|
||||||
local errmsg = { "Could not load any HTTP client library:" }
|
local errmsg = { "Could not load any HTTP client library:" }
|
||||||
for i, name in pairs(tries) do
|
for i, name in pairs(tries) do
|
||||||
@@ -57,14 +57,14 @@ local API = {}
|
|||||||
API.__name = "matrix.api"
|
API.__name = "matrix.api"
|
||||||
API.__index = 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({
|
return setmetatable({
|
||||||
base_url = base_url,
|
base_url = base_url,
|
||||||
token = token,
|
token = token,
|
||||||
txn_id = 0,
|
txn_id = 0,
|
||||||
api_path = "/_matrix/client/r0", -- TODO: De-hardcode
|
api_path = "/_matrix/client/r0", -- TODO: De-hardcode
|
||||||
_log = get_debug_log_function(),
|
_log = get_debug_log_function(),
|
||||||
_http = get_http_factory(http_factory)(),
|
_http = get_http_client(http_client)(),
|
||||||
}, API)
|
}, API)
|
||||||
end })
|
end })
|
||||||
|
|
||||||
|
|||||||
@@ -296,12 +296,12 @@ local Client = {}
|
|||||||
Client.__name = "matrix.client"
|
Client.__name = "matrix.client"
|
||||||
Client.__index = 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({
|
local c = eventable.object(setmetatable({
|
||||||
presence = {}, -- Indexed by user_id
|
presence = {}, -- Indexed by user_id
|
||||||
rooms = {}, -- Indexed by room_id
|
rooms = {}, -- Indexed by room_id
|
||||||
_log = get_debug_log_function(),
|
_log = get_debug_log_function(),
|
||||||
_api = API(base_url, token, http_factory),
|
_api = API(base_url, token, http_client),
|
||||||
}, Client))
|
}, Client))
|
||||||
-- Do an initial sync if a token was provided on construction.
|
-- Do an initial sync if a token was provided on construction.
|
||||||
if token then
|
if token then
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ local httpclient = {
|
|||||||
quote = require "http.util" .encodeURI,
|
quote = require "http.util" .encodeURI,
|
||||||
unquote = require "http.util" .decodeURI,
|
unquote = require "http.util" .decodeURI,
|
||||||
}
|
}
|
||||||
httpclient.__name = "matrix.factory.chttp"
|
httpclient.__name = "matrix.client.chttp"
|
||||||
httpclient.__index = httpclient
|
httpclient.__index = httpclient
|
||||||
|
|
||||||
function httpclient:__tostring()
|
function httpclient:__tostring()
|
||||||
@@ -41,7 +41,7 @@ local httpclient = {
|
|||||||
quote = require "socket.url" .escape,
|
quote = require "socket.url" .escape,
|
||||||
unquote = require "socket.url" .unescape,
|
unquote = require "socket.url" .unescape,
|
||||||
}
|
}
|
||||||
httpclient.__name = "matrix.factory.luasocket"
|
httpclient.__name = "matrix.client.luasocket"
|
||||||
httpclient.__index = httpclient
|
httpclient.__index = httpclient
|
||||||
|
|
||||||
function httpclient:__tostring()
|
function httpclient:__tostring()
|
||||||
Reference in New Issue
Block a user