diff --git a/docs/reference/matrix-glib/matrix-glib-sections.txt b/docs/reference/matrix-glib/matrix-glib-sections.txt index 187ea14..a277c62 100644 --- a/docs/reference/matrix-glib/matrix-glib-sections.txt +++ b/docs/reference/matrix-glib/matrix-glib-sections.txt @@ -58,6 +58,7 @@ matrix_http_api_get_validate_certificate matrix_http_api_set_validate_certificate matrix_http_api_get_base_url matrix_http_api_gen_parameters +matrix_http_api_register_account matrix_http_api_login MatrixHTTPAPI diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 9517716..6393323 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -82,6 +82,7 @@ static void matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) { iface->login = matrix_http_api_login; + iface->register_account = matrix_http_api_register_account; } static void @@ -452,23 +453,13 @@ update_parameters(gchar *key, gchar *value, JsonBuilder *builder) json_builder_add_value(builder, node); } -/** - * matrix_http_api_login: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request if - * finished - * @user_data: user data to pass to the callback function - * @login_type: the login type to use - * @parameters: parameters to send with the login request - * - * Perform /login - */ -void -matrix_http_api_login(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - gchar *login_type, - GHashTable *parameters) +static void +matrix_http_api_login_or_register(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + gchar *type, + gchar *login_type, + GHashTable *parameters) { JsonBuilder *builder; JsonNode *content, @@ -490,11 +481,37 @@ matrix_http_api_login(MatrixAPI *api, matrix_http_api_send(MATRIX_HTTP_API(api), callback, user_data, - "POST", "/login", + "POST", type, content, parameters); } +/** + * matrix_http_api_login: + * @api: a #MatrixAPI implementation + * @callback: (scope async): the function to call when the request if + * finished + * @user_data: user data to pass to the callback function + * @login_type: the login type to use + * @parameters: parameters to send with the login request + * + * Perform /login + */ +void +matrix_http_api_login(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + gchar *login_type, + GHashTable *parameters) +{ + matrix_http_api_login_or_register(api, + callback, + user_data, + "/login", + login_type, + parameters); +} + /** * matrix_http_api_gen_parameters: * @param1_name: name of the first parameter @@ -548,3 +565,29 @@ matrix_http_api_get_base_url(MatrixHTTPAPI *api) return priv->url; } + +/** + * matrix_http_api_register_account: + * @api: a #MatrixAPI implementation + * @callback: (scope async): the function to call when the request if + * finished + * @user_data: user data to pass to the callback function + * @login_type: the login type to use + * @parameters: parameters to send with the registration request + * + * Perform /register + */ +void +matrix_http_api_register_account(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + gchar *login_type, + GHashTable *parameters) +{ + matrix_http_api_login_or_register(api, + callback, + user_data, + "/register", + login_type, + parameters); +} diff --git a/src/matrix-http-api.h b/src/matrix-http-api.h index 8b19771..df38194 100644 --- a/src/matrix-http-api.h +++ b/src/matrix-http-api.h @@ -59,6 +59,12 @@ void matrix_http_api_login(MatrixAPI *api, gpointer user_data, gchar *login_type, GHashTable *parameters); +void matrix_http_api_register_account(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + gchar *login_type, + GHashTable *parameters); + G_END_DECLS #endif /* __MATRIX_HTTP_API_H__ */