Пример #1
0
        public async Task <NotificationRES> SendFriendRequest(string userId, string fromWho)
        {
            JObject json = new JObject();

            json["type"]    = "friendrequest";
            json["message"] = $"{fromWho} wants to be your friend";

            StringContent content = new StringContent(json.ToString(), Encoding.UTF8);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            HttpResponseMessage response = await httpClient.PostAsync($"user/{userId}/notification{apiKey}", content);

            NotificationRES res = null;

            if (response.IsSuccessStatusCode)
            {
                var receivedJson = await response.Content.ReadAsStringAsync();

                res = JsonConvert.DeserializeObject <NotificationRES>(receivedJson);

                Console.WriteLine($"{res.id}");
                Console.WriteLine($"Sent friendrequest to: {res.receiverUserId}");
                Console.WriteLine();
            }

            return(res);
        }
Пример #2
0
        public async Task <NotificationRES> SendMessage(string userId, string fromWho, string message)
        {
            JObject json = new JObject();

            json["type"]    = "message";
            json["message"] = $"{fromWho} says: {message}";

            StringContent content = new StringContent(json.ToString(), Encoding.UTF8);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            HttpResponseMessage response = await httpClient.PostAsync($"user/{userId}/notification{apiKey}", content);

            NotificationRES res = null;

            if (response.IsSuccessStatusCode)
            {
                var receivedJson = await response.Content.ReadAsStringAsync();

                res = JsonConvert.DeserializeObject <NotificationRES>(receivedJson);

                Console.WriteLine($"{res.id}");
                Console.WriteLine($"Sent message to: {res.receiverUserId}");
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine($"Unexpected Error! --- {response.StatusCode} --- {response.ReasonPhrase}\n{json}");
            }

            return(res);
        }