/soc/2015/nakulgulati/main: a85f2e4fe1b4: hangouts: api - hangou...
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Tue Aug 4 11:47:29 EDT 2015
Changeset: a85f2e4fe1b4035f3abc8d3f8a346ca82a261fcc
Author: Nakul Gulati
Date: 2015-08-03 15:54 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/a85f2e4fe1b4
Description:
hangouts: api - hangouts_api_request changes
diffstat:
libpurple/protocols/hangouts/api.c | 45 +++++++++++++++++--------------------
libpurple/protocols/hangouts/api.h | 5 +--
2 files changed, 23 insertions(+), 27 deletions(-)
diffs (158 lines):
diff --git a/libpurple/protocols/hangouts/api.c b/libpurple/protocols/hangouts/api.c
--- a/libpurple/protocols/hangouts/api.c
+++ b/libpurple/protocols/hangouts/api.c
@@ -67,6 +67,8 @@ struct _HangoutsApiPrivate
struct _HangoutsApiHttpInfo
{
PurpleHttpCallback callback;
+ gchar *endpoint;
+ gchar *method;
};
static void
@@ -377,12 +379,11 @@ hangouts_api_get_request_header (Hangout
void
hangouts_api_request (HangoutsApi *api, const HangoutsApiHttpInfo *info,
- gchar *url_endpoint, gboolean use_json,
- gchar *request_body)
+ gboolean use_json, gchar *request_body)
{
HangoutsApiPrivate *priv = api->priv;
- gchar *url = g_strconcat (HANGOUTS_API_BASE_URL, url_endpoint, "?alt=json");
+ gchar *url = g_strconcat (HANGOUTS_API_BASE_URL, info->endpoint, "?alt=json");
PurpleHttpRequest *request;
request = purple_http_request_new (url);
@@ -396,7 +397,7 @@ hangouts_api_request (HangoutsApi *api,
}
purple_http_request_header_add (request, "content-type", content_type);
- purple_http_request_set_method (request, "POST");
+ purple_http_request_set_method (request, info->method);
purple_http_request_set_contents (request, request_body, -1);
purple_http_request (priv->gc, request, info->callback, api);
}
@@ -411,16 +412,15 @@ hangouts_api_getselfinfo_cb (PurpleHttpC
void
hangouts_api_getselfinfo (HangoutsApi *api)
{
- static const HangoutsApiHttpInfo *info =
- { hangouts_api_getselfinfo_cb };
+ static const HangoutsApiHttpInfo info =
+ { hangouts_api_getselfinfo_cb, "contacts/selfinfo", "POST" };
- gchar *url_endpoint, *header, *body;
+ gchar *header, *body;
- url_endpoint = "contacts/selfinfo";
header = hangouts_api_get_request_header (api);
body = g_strdup_printf ("[%s,[], []]", header);
- hangouts_api_request (api, info, url_endpoint, TRUE, body);
+ hangouts_api_request (api, &info, TRUE, body);
}
static void
@@ -433,14 +433,13 @@ hangouts_api_syncallevents_cb (PurpleHtt
void
hangouts_api_syncallevents (HangoutsApi *api)
{
- static const HangoutsApiHttpInfo *info =
- { hangouts_api_syncallevents_cb };
+ static const HangoutsApiHttpInfo info =
+ { hangouts_api_syncallevents_cb, "conversations/syncallnewevents", "POST" };
- gchar *url_endpoint, *header, *body;
+ gchar *header, *body;
GTimeVal *time_stamp;
time_stamp = api->priv->last_sync_timestamp;
- url_endpoint = "conversations/syncallnewevents";
header = hangouts_api_get_request_header (api);
body = g_strdup_printf ("["
"%s, "
@@ -454,7 +453,7 @@ hangouts_api_syncallevents (HangoutsApi
"]",
header, g_time_val_to_iso8601 (time_stamp));
- hangouts_api_request (api, info, url_endpoint, FALSE, body);
+ hangouts_api_request (api, &info, FALSE, body);
}
static void
@@ -471,14 +470,13 @@ hangouts_api_sendchatmessage (HangoutsAp
HangoutsOffTheRecordStatus otr_status)
{
//TODO: segments should be in the protojson format
- static const HangoutsApiHttpInfo *info =
- { hangouts_api_sendchatmessage_cb };
+ static const HangoutsApiHttpInfo info =
+ { hangouts_api_sendchatmessage_cb, "conversations/sendchatmessage", "POST" };
guint32 client_generated_id;
- gchar *url_endpoint, *image_info, *body, *header;
+ gchar *image_info, *body, *header;
client_generated_id = g_random_int_range (0, G_MAXINT32);
- url_endpoint = "conversations/sendchatmessage";
header = hangouts_api_get_request_header (api);
image_info = "None";
@@ -500,7 +498,7 @@ hangouts_api_sendchatmessage (HangoutsAp
header, segments, image_info, conversation_id,
client_generated_id, otr_status);
- hangouts_api_request (api, info, url_endpoint, FALSE, body);
+ hangouts_api_request (api, &info, FALSE, body);
}
static void
@@ -515,13 +513,12 @@ void
hangouts_api_setactiveclient (HangoutsApi *api, gboolean is_active,
gchar *timeout_sec)
{
- static const HangoutsApiHttpInfo *info =
- { hangouts_api_setactiveclient_cb };
+ static const HangoutsApiHttpInfo info =
+ { hangouts_api_setactiveclient_cb, "clients/setactiveclient", "POST" };
- gchar *url_endpoint, *is_active_flag, *body, *header;
+ gchar *is_active_flag, *body, *header;
HangoutsApiPrivate *priv;
- url_endpoint = "clients/setactiveclient";
header = hangouts_api_get_request_header (api);
priv = api->priv;
is_active_flag = "False";
@@ -539,6 +536,6 @@ hangouts_api_setactiveclient (HangoutsAp
header, is_active_flag, priv->email, priv->client_id,
timeout_sec);
- hangouts_api_request (api, info, url_endpoint, FALSE, body);
+ hangouts_api_request (api, &info, FALSE, body);
}
diff --git a/libpurple/protocols/hangouts/api.h b/libpurple/protocols/hangouts/api.h
--- a/libpurple/protocols/hangouts/api.h
+++ b/libpurple/protocols/hangouts/api.h
@@ -82,7 +82,7 @@ void
hangouts_api_fetch_login_cookies (HangoutsApi *api);
void
-hangouts_api_get_private_token(HangoutsApi *api);
+hangouts_api_get_private_token (HangoutsApi *api);
void
hangouts_api_get_chat_init (HangoutsApi *api);
@@ -92,8 +92,7 @@ hangouts_api_get_request_header (Hangout
void
hangouts_api_request (HangoutsApi *api, const HangoutsApiHttpInfo *info,
- gchar *url_endpoint, gboolean use_json,
- gchar *request_body);
+ gboolean use_json, gchar *request_body);
void
hangouts_api_getselfinfo (HangoutsApi *api);
More information about the Commits
mailing list