Beispiel #1
0
        public void GetSelfInfo()
        {
            GetSelfInfoRequest request = new GetSelfInfoRequest()
            {
                request_header = RequestHeaderBody
            };

            HttpResponseMessage message = _client.PostProtoJson("contacts/getselfinfo", request);

            if (UserInformationReceived != null)
            {
                GetSelfInfoResponse response = message.Content.ReadAsProtoJson <GetSelfInfoResponse>();

                CurrentUser = new User(response.self_entity);
                UserInformationReceived(this, CurrentUser);
            }
        }
Beispiel #2
0
        public async Task GetSelfInfoAsync()
        {
            GetSelfInfoRequest request = new GetSelfInfoRequest()
            {
                request_header = RequestHeaderBody,
            };

            using (HttpResponseMessage message = await _client.PostProtoJson("contacts/getselfinfo", _api_key, request))
            {
                GetSelfInfoResponse response = await message.Content.ReadAsProtoJson <GetSelfInfoResponse>();

                CurrentUser = response.self_entity;
                if (OnUserInformationReceived != null)
                {
                    OnUserInformationReceived(this, CurrentUser);
                }
            }
        }
Beispiel #3
0
        async Task initializeChat()
        {
            // We first need to fetch the 'pvt' token, which is required for the
            // initialization request (otherwise it will return 400).
            HttpResponseMessage message = await _client.Execute(HangoutUri.PVT_TOKEN_URL, _initParams);

            string data = await message.Content.ReadAsStringAsync();

            Newtonsoft.Json.Linq.JArray array = JArray.Parse(data);

            _initParams["pvt"] = array[1].ToString();

            // Now make the actual initialization request:
            message = await _client.Execute(HangoutUri.CHAT_INIT_URL, _initParams);

            data = await message.Content.ReadAsStringAsync();

            message.Dispose();


            // Parse the response by using a regex to find all the JS objects, and
            // parsing them. Not everything will be parsable, but we don't care if
            // an object we don't need can't be parsed.

            Dictionary <string, Newtonsoft.Json.Linq.JArray> dataDictionary = Parser.ParseInitParams(data);

            // a this time we can not fix key as index can change.
            string key = null;

            foreach (JArray jarray in dataDictionary.Values)
            {
                try
                {
                    key = jarray[0][0].ToString();
                }
                catch { key = null; }

                switch (key)
                {
                case "cin:cac":
                    _api_key = jarray[0][2].ToString();
                    break;

                case "cic:vd":
                    _email = jarray[0][2].ToString();     // cic:vd
                    break;

                case "cin:acc":
                    if (jarray[0].Count() > 6)
                    {
                        _header_date    = jarray[0][4].ToString();  //cin:acc
                        _header_version = jarray[0][6].ToString();
                    }
                    break;

                case "cin:bcsc":
                    _header_id = jarray[0][7].ToString();     // cin:bcsc
                    break;

                case "cgserp":
                    jarray[0][0].Remove();
                    GetSuggestedEntitiesResponse cgserp = ProtoJsonSerializer.Deserialize <GetSuggestedEntitiesResponse>(jarray[0] as JArray);
                    if (cgserp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK)
                    {
                        _contacts = cgserp.contacts_you_hangout_with.contact.ToDictionary(c => c.entity.id.gaia_id, c => new User(c.entity));
                    }
                    break;

                case "cgsirp":
                    jarray[0][0].Remove();
                    GetSelfInfoResponse cgsirp = ProtoJsonSerializer.Deserialize <GetSelfInfoResponse>(jarray[0] as JArray);
                    if (cgsirp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK)
                    {
                        if (!string.IsNullOrEmpty(_email))
                        {
                            cgsirp.self_entity.properties.canonical_email = _email;
                        }
                        CurrentUser = new User(cgsirp.self_entity);
                    }
                    break;

                case "csrcrp":
                    jarray[0][0].Remove();
                    SyncRecentConversationsResponse csrcrp = ProtoJsonSerializer.Deserialize <SyncRecentConversationsResponse>(jarray[0] as JArray);
                    if (csrcrp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK)
                    {
                        _active_conversations = csrcrp.conversation_state.ToDictionary(c => c.conversation_id.id, c => new WTalk.Model.Conversation(c));
                    }
                    break;
                }
            }

            // call all events
            if (UserInformationReceived != null)
            {
                UserInformationReceived(this, CurrentUser);
            }


            data           = null;
            dataDictionary = null;
            //this._timestamp = double.Parse(dataDictionary["ds:21"][0][1][4].ToString());
        }