api: add generic request
This commit is contained in:
parent
71d237046d
commit
d657fea159
5 changed files with 35 additions and 1 deletions
|
|
@ -397,6 +397,26 @@ func apiv0_joinedrooms(cid C.int) *C.char {
|
|||
return C.CString(s)
|
||||
}
|
||||
|
||||
//export apiv0_genericrequest
|
||||
func apiv0_genericrequest(cid C.int, method *C.char, path *C.char, data *C.char) *C.char {
|
||||
cli, err := getClient(int(cid))
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
var bup mautrix.BaseURLPath
|
||||
err = json.Unmarshal([]byte(C.GoString(path)), &bup)
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
urlPath := cli.BuildURLWithFullQuery(mautrix.BaseURLPath(bup), nil)
|
||||
d := C.GoString(data)
|
||||
resp, err := cli.MakeFullRequest(context.Background(), mautrix.FullRequest{Method: C.GoString(method), URL: urlPath, RequestBytes: []byte(d), ResponseJSON: nil})
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
return C.CString(string(resp))
|
||||
}
|
||||
|
||||
//export apiv0_createroom
|
||||
func apiv0_createroom(cid C.int, data *C.char) *C.char {
|
||||
cli, err := getClient(int(cid))
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ ffibuilder.cdef(
|
|||
extern char* apiv0_leaveroom(int cid, char* roomid);
|
||||
extern char* apiv0_joinedrooms(int cid);
|
||||
extern char* apiv0_createroom(int cid, char* data);
|
||||
extern char* apiv0_genericrequest(int cid, char* method, char* path, char* data);
|
||||
extern int apiv0_removeclient(int cid);
|
||||
extern char* apiv0_listclients();
|
||||
extern char* apiv0_getoptions(int cid);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ apiv0_createclient_pass
|
|||
apiv0_createroom
|
||||
apiv0_deinitialize
|
||||
apiv0_discover
|
||||
apiv0_genericrequest
|
||||
apiv0_getoptions
|
||||
apiv0_initialize
|
||||
apiv0_joinedrooms
|
||||
|
|
|
|||
|
|
@ -49,6 +49,14 @@ class ApiV0Api:
|
|||
def createroom(cid, data):
|
||||
return _stringresult(lib.apiv0_createroom(cid, _autodict(data)))
|
||||
|
||||
@staticmethod
|
||||
def generic(cid, method, path, data):
|
||||
return _stringresult(
|
||||
lib.apiv0_genericrequest(
|
||||
cid, _autostring(method), _autolist(path), _autodict(data)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class ApiV0:
|
||||
"""ApiV0"""
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import threading
|
|||
from _pygomx import ffi, lib
|
||||
|
||||
from .apiv0 import ApiV0Api
|
||||
from .errors import CheckApiError, CheckApiResult, PygomxAPIError
|
||||
from .errors import CheckApiError, CheckApiErrorOnly, CheckApiResult, PygomxAPIError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -92,6 +92,10 @@ class _AsyncClient:
|
|||
r = ApiV0Api.createroom(self.client_id, data_dict)
|
||||
return CheckApiResult(r)
|
||||
|
||||
async def generic(self, method, path, data):
|
||||
r = ApiV0Api.generic(self.client_id, method, path, data)
|
||||
return CheckApiErrorOnly(r)
|
||||
|
||||
|
||||
def process_event(self, evt):
|
||||
if hasattr(self, "on_event") and callable(self.on_event):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue