/soc/2015/nakulgulati/main: 39345930a427: hangouts: api - getsel...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Fri Jul 24 03:34:16 EDT 2015


Changeset: 39345930a4279e59c75d4e5d83c957aa81eb1b46
Author:	 Nakul Gulati
Date:	 2015-07-24 15:33 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/39345930a427

Description:

hangouts: api - getselfinfo, syncallevents, setactiveclient

diffstat:

 libpurple/protocols/hangouts/api.c |  70 +++++++++++++++++++++++++++++++++++--
 libpurple/protocols/hangouts/api.h |   7 +++
 2 files changed, 72 insertions(+), 5 deletions(-)

diffs (115 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
@@ -35,22 +35,27 @@ typedef struct {
 	gchar *header_id;
 	gchar *client_id;
 	gchar *email;
-	GTimeVal *sync_timestamp;
+	GTimeVal *last_sync_timestamp;
 
 } _hangouts_api_data;
 
-void hangouts_api_request(HangoutsApi *hangoutsApi, gchar *url_endpoint, gchar *content_type, gchar *request_body) {
+void hangouts_api_request(HangoutsApi *hangoutsApi, gchar *url_endpoint, gboolean use_protojson, gchar *request_body) {
 
 	HangoutsApiData *data = hangoutsApi->api_data;
 	gchar *url = g_strconcat(HANGOUTS_API_BASE_URL, url_endpoint,"?alt=json");
 	PurpleHttpRequest *request = purple_http_request_new(url);
 	PurpleHttpConnection *ret;
+	gchar *content_type;
 
-	purple_http_request_header_add(request, "content-type", content_type);
+	if(use_protojson){
+		content_type = "application/json+protobuf";
+		purple_http_request_header_add(request, "content-type", content_type);
+	}
+
 	purple_http_request_header_add(request, "Authorization", hangouts_auth_get_authorization_header(data->access_token));
 	purple_http_request_set_method(request, "POST");
 	purple_http_request_set_contents(request, request_body);
-	//purple_http_request()
+	//TODO: complete and implement callback
 }
 
 gchar *
@@ -72,6 +77,61 @@ hangouts_api_get_request_header(Hangouts
 	return header;
 }
 
-void hangouts_api_getselfinfo() {
+void
+hangouts_api_getselfinfo(HangoutsApi *hangoutsApi)
+{
+	gchar *header = hangouts_api_get_request_header(hangoutsApi);
+	gchar *url_endpoint = "contacts/selfinfo";
+	gchar *request_body = g_strdup_printf("[%s,[], []]",header);
 
+	hangouts_api_request(hangoutsApi, url_endpoint, TRUE, request_body);
 }
+
+void
+hangouts_api_syncallevents(HangoutsApi *hangoutsApi)
+{
+	gchar *header = hangouts_api_get_request_header(hangoutsApi);
+	GTimeVal *time_stamp = hangoutsApi->api_data->last_sync_timestamp;
+	gchar *url_endpoint = "conversations/syncallnewevents";
+	gchar *request_body = g_strdup_printf("["
+			"%s, "
+			"%s,"
+			"[], "
+			"None, "
+			"[], "
+			"False, "
+			"[], "
+			"1048576"
+			"]",
+			header,g_time_val_to_iso8601(time_stamp));
+
+
+	hangouts_api_request(hangoutsApi, url_endpoint, TRUE, request_body);
+}
+
+void
+hangouts_api_setactiveclient(HangoutsApi *hangoutsApi, gboolean is_active, gchar *timeout_sec)
+{
+	gchar *header = hangouts_api_get_request_header(hangoutsApi);
+	HangoutsApiData *data = hangoutsApi->api_data;
+	gchar *url_endpoint = "clients/setactiveclient";
+	gchar *is_active_flag = "False";
+
+	if(is_active){
+		is_active_flag = "False";
+	}
+
+	gchar *request_body = g_strdup_printf("["
+			"%s, "
+			"%s, "
+			"%s\/%s, "
+			"%s]",
+			header,
+			is_active_flag,
+			data->email,
+			data->client_id,
+			timeout_sec);
+
+	hangouts_api_request(hangoutsApi, url_endpoint, TRUE, request_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
@@ -53,6 +53,13 @@ struct _HangoutsApi{
 GType
 hangouts_api_get_type(void);
 
+void hangouts_api_getselfinfo(HangoutsApi *hangoutsApi);
+void hangouts_api_syncallevents(HangoutsApi *hangoutsApi);
+void hangouts_api_sendchatmessage(HangoutsApi *hangoutsApi, gchar *conversation_id, gchar *segments, gchar *image_id);
+void hangouts_api_setactiveclient(HangoutsApi *hangoutsApi, gboolean is_active, gchar *timeout_sec);
+
+
+
 
 
 #endif /* _API_H */



More information about the Commits mailing list