Esempio n. 1
0
        public static HttpStatusCode DeleteUserByIdentifier(int identifier, string postDataContentType = "application/json")
        {
            CreateDialogResponse dialogResponse = new CreateDialogResponse();

            // get session
            RootUser user    = GetUserByIdentifier(identifier);
            Session  session = GetSession(user.User.Login, user.User.Login);
            //
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("https://api.quickblox.com/users/{0}.json", identifier));

            request.Method      = "DELETE";
            request.KeepAlive   = false;
            request.ContentType = postDataContentType;
            request.Headers.Add(string.Format("QuickBlox-REST-API-Version: {0}", quickBloxRESTAPIVersion));
            request.Headers.Add(string.Format("QB-Token: {0}", session.Token));


            StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());

            requestWriter.Close();
            requestWriter = null;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            return(response.StatusCode);
        }
Esempio n. 2
0
        public static CreateDialogResponse CreateDialog(string login, CreateDialogRequest dialog, string postDataContentType = "application/json")
        {
            CreateDialogResponse dialogResponse = new CreateDialogResponse();

            try
            {
                // get session
                Session session = GetSession(login, login);
                //
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.quickblox.com/chat/Dialog.json");
                request.Method      = "POST";
                request.KeepAlive   = false;
                request.ContentType = postDataContentType;
                request.Headers.Add(string.Format("QuickBlox-REST-API-Version: {0}", quickBloxRESTAPIVersion));
                request.Headers.Add(string.Format("QB-Token: {0}", session.Token));

                string postData  = JsonConvert.SerializeObject(dialog);
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                request.ContentLength = byteArray.Length;

                StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
                try
                {
                    requestWriter.Write(postData);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    requestWriter.Close();
                    requestWriter = null;
                }

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    var result = reader.ReadToEnd();
                    dialogResponse = JsonConvert.DeserializeObject <CreateDialogResponse>(result);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(dialogResponse);
        }