From 08cfb118fd67e4fa54e230185b654a052e08f359 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 16 Jan 2016 19:20:24 +0100 Subject: [PATCH] Redesign matrix_http_api_new() so it returns MatrixAPI This is for easier work with the interface. --- .../matrix-glib/matrix-glib-sections.txt | 2 +- src/matrix-http-api.c | 17 +++++++++++------ src/matrix-http-api.h | 2 +- src/test-client.c | 11 ++++++----- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/reference/matrix-glib/matrix-glib-sections.txt b/docs/reference/matrix-glib/matrix-glib-sections.txt index 40cf16f..a2439b3 100644 --- a/docs/reference/matrix-glib/matrix-glib-sections.txt +++ b/docs/reference/matrix-glib/matrix-glib-sections.txt @@ -308,8 +308,8 @@ matrix_api_error_quark
matrix-http-api matrix_http_api_new -matrix_http_api_get_validate_certificate matrix_http_api_set_validate_certificate +matrix_http_api_get_validate_certificate matrix_http_api_get_base_url diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index c93fd6f..972687a 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -367,15 +367,20 @@ matrix_http_api_init(MatrixHTTPAPI *api) * requests that need authentication will fail * * Create a new #MatrixHTTPAPI object with the specified base URL, and - * an optional authorization token + * an optional authorization token. + * + * Returns: (transfer full): a new #MatrixHTTPAPI object cast to + * #MatrixAPI */ -MatrixHTTPAPI * +MatrixAPI * matrix_http_api_new(const gchar *base_url, const gchar *token) { - return g_object_new(MATRIX_TYPE_HTTP_API, - "base-url", base_url, - "token", token, - NULL); + MatrixHTTPAPI *api = g_object_new(MATRIX_TYPE_HTTP_API, + "base-url", base_url, + "token", token, + NULL); + + return MATRIX_API(api); } static void diff --git a/src/matrix-http-api.h b/src/matrix-http-api.h index 044f3e5..2019f39 100644 --- a/src/matrix-http-api.h +++ b/src/matrix-http-api.h @@ -52,7 +52,7 @@ void matrix_http_api_set_validate_certificate(MatrixHTTPAPI *api, gboolean matrix_http_api_get_validate_certificate(MatrixHTTPAPI *api); const gchar *matrix_http_api_get_base_url(MatrixHTTPAPI *api); -MatrixHTTPAPI *matrix_http_api_new(const gchar *base_url, const gchar *token); +MatrixAPI *matrix_http_api_new(const gchar *base_url, const gchar *token); G_END_DECLS diff --git a/src/test-client.c b/src/test-client.c index 5a7d410..74e800a 100644 --- a/src/test-client.c +++ b/src/test-client.c @@ -46,7 +46,7 @@ initial_sync_finished(MatrixAPI *api, { g_printf("initialSync finished\n"); - matrix_api_event_stream(MATRIX_API(api), NULL, NULL, NULL, 0, NULL); + matrix_api_event_stream(api, NULL, NULL, NULL, 0, NULL); } static void @@ -131,7 +131,7 @@ login_finished(MatrixAPI *api, g_printf("Logged in as %s\n", user_id); - matrix_api_initial_sync(MATRIX_API(api), + matrix_api_initial_sync(api, initial_sync_finished, data, 10, TRUE, NULL); @@ -154,7 +154,7 @@ login_finished(MatrixAPI *api, int main(int argc, char *argv[]) { - MatrixHTTPAPI *api; + MatrixAPI *api; GHashTable *params; GMainLoop *loop = g_main_loop_new(NULL, FALSE); GOptionContext *opts; @@ -183,7 +183,8 @@ main(int argc, char *argv[]) g_info("Starting up: %s with %s:%s", *homeserver, user, password); api = matrix_http_api_new(*homeserver, NULL); - matrix_http_api_set_validate_certificate(api, !no_validate_certs); + matrix_http_api_set_validate_certificate(MATRIX_HTTP_API(api), + !no_validate_certs); builder = json_builder_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "user"); @@ -194,7 +195,7 @@ main(int argc, char *argv[]) login_content = json_builder_get_root(builder); g_debug("Logging in"); - matrix_api_login(MATRIX_API(api), + matrix_api_login(api, login_finished, loop, "m.login.password", login_content,