Example #1
0
        /// <summary>
        /// Unsubscrip the contact based on its current subscription state.
        /// </summary>
        /// <param name="userID">A string containing the user id.</param>
        /// <param name="contactID">A string containing contact id, who is going to be unsubscribed from ther user roster.</param>
        /// <param name="currentSubscription">An enum specifying the current subscription state of the contact.</param>
        public static void UnSubContact(string userID, string contactID, RosterSubscription currentSubscription)
        {
            LoadVariables();
            string     actionType = "update_roster";
            string     url        = _userService;
            RestClient client     = new RestClient(_baseURL);

            if (currentSubscription == RosterSubscription.Both)
            {
                RestRequest userRequest    = SetupRequestWithRosterParameters(url, actionType, userID, NeeoUtility.ConvertToJid(contactID), RosterSubscription.From);
                RestRequest contactRequest = SetupRequestWithRosterParameters(url, actionType, contactID, NeeoUtility.ConvertToJid(userID), RosterSubscription.To);

                ExecuteRequest(userRequest);
                ExecuteRequest(contactRequest);
            }
            else
            {
                RestRequest userRequest    = SetupRequestWithRosterParameters(url, actionType, userID, NeeoUtility.ConvertToJid(contactID), RosterSubscription.None);
                RestRequest contactRequest = SetupRequestWithRosterParameters(url, actionType, contactID, NeeoUtility.ConvertToJid(userID), RosterSubscription.None);

                ExecuteRequest(userRequest);
                ExecuteRequest(contactRequest);
            }
        }
Example #2
0
        /// <summary>
        /// Sets up request with parameters required for roster manipulation.
        /// </summary>
        /// <param name="url">A string containing the server url.</param>
        /// <param name="actionType">A string specifying the action to be performed.</param>
        /// <param name="userID">A string containing the user id of the user.</param>
        /// <param name="contactJid">A string containing the contact's jid whose subscription has to be modified in the user's roster. </param>
        /// <param name="subscription">An enum specifying the subscription to be set across the given contact <paramref name="contactJid"/></param>
        /// <returns>A request object to be processed based on the given parameters.</returns>
        private static RestRequest SetupRequestWithRosterParameters(string url, string actionType, string userID, string contactJid, RosterSubscription subscription)
        {
            RestRequest request = new RestRequest(url + _itemJID + _subscription);

            request.AddUrlSegment("type", actionType);
            request.AddUrlSegment("secret", _adminKey);
            request.AddUrlSegment("username", userID);
            request.AddUrlSegment("item_jid", contactJid);
            request.AddUrlSegment("subscription", subscription.ToString("D"));
            return(request);
        }
Example #3
0
        /// <summary>
        /// Sets up request with parameters required for roster manipulation.
        /// </summary>
        /// <param name="url">A string containing the server url.</param>
        /// <param name="actionType">A string specifying the action to be performed.</param>
        /// <param name="userID">A string containing the user id of the user.</param>
        /// <param name="contactJid">A string containing the contact's jid whose subscription has to be modified in the user's roster. </param>
        /// <param name="subscription">An enum specifying the subscription to be set across the given contact <paramref name="contactJid"/></param>
        /// <returns>A request object to be processed based on the given parameters.</returns>
        private static RestRequest SetupRequestWithRosterParameters(string url, string actionType, string userID, string contactJid, RosterSubscription subscription)
        {
            RestRequest request = new RestRequest(url + "/" + userID + "/roster/" + contactJid);

            request.Method = Method.PUT;
            request.AddHeader("Content-Type", "application/xml");
            request.AddHeader("Authorization", _adminKey);
            string RequestBody = string.Format(@"<?xml version='1.0' encoding='UTF-8' standalone='yes'?> <rosterItem> <jid>{0}</jid><subscriptionType>{1}</subscriptionType></rosterItem>", contactJid, (int)subscription);

            request.AddParameter("application/xml", RequestBody, ParameterType.RequestBody);
            return(request);
        }