Redesign matrix_http_api_new() so it returns MatrixAPI

This is for easier work with the interface.
This commit is contained in:
Gergely Polonkai 2016-01-16 19:20:24 +01:00
parent c012b05bac
commit 08cfb118fd
4 changed files with 19 additions and 13 deletions

View File

@ -308,8 +308,8 @@ matrix_api_error_quark
<SECTION>
<FILE>matrix-http-api</FILE>
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
<SUBSECTION Standard>

View File

@ -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

View File

@ -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

View File

@ -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,