StringToDictionary() public static method

Converts a URL parameter encoded string into a dictionary.
e.g. ab=cd&ef=gh will return a dictionary of { "ab" => "cd", "ef" => "gh" }.
public static StringToDictionary ( string response ) : string>.Dictionary
response string
return string>.Dictionary
Beispiel #1
0
        /// <summary>
        /// Constructor for the OAuthException class.
        /// </summary>
        /// <param name="innerException"></param>
        public OAuthException(Exception innerException) : base("OAuth Exception", innerException)
        {
            WebException exception = innerException as WebException;

            if (exception == null)
            {
                return;
            }

            HttpWebResponse res = exception.Response as HttpWebResponse;

            if (res == null)
            {
                return;
            }

            using (StreamReader sr = new StreamReader(res.GetResponseStream()))
            {
                string response = sr.ReadToEnd();

                FullResponse = response;

                OAuthErrorPameters = UtilityMethods.StringToDictionary(response);
                mess = "OAuth Exception occurred: " + OAuthErrorPameters["oauth_problem"];
            }
        }
        /// <summary>
        /// Parses a URL parameter encoded string and returns a new <see cref="OAuthAccessToken"/>
        /// </summary>
        /// <param name="response">A URL parameter encoded string, e.g. "oauth_token=ABC&amp;oauth_token_secret=DEF&amp;user_id=1234567@N00".</param>
        /// <returns></returns>
        internal static OAuthAccessToken ParseResponse(string response)
        {
            Dictionary <string, string> parts = UtilityMethods.StringToDictionary(response);

            OAuthAccessToken token = new OAuthAccessToken();

            if (parts.ContainsKey("oauth_token"))
            {
                token.Token = parts["oauth_token"];
            }
            if (parts.ContainsKey("oauth_token_secret"))
            {
                token.TokenSecret = parts["oauth_token_secret"];
            }
            if (parts.ContainsKey("user_nsid"))
            {
                token.UserId = parts["user_nsid"];
            }
            if (parts.ContainsKey("fullname"))
            {
                token.FullName = parts["fullname"];
            }
            if (parts.ContainsKey("username"))
            {
                token.Username = parts["username"];
            }

            return(token);
        }
        /// <summary>
        /// Parses a URL parameter encoded string and returns a new <see cref="OAuthAccessToken"/>
        /// </summary>
        /// <param name="response">A URL parameter encoded string, e.g. "oauth_token=ABC&amp;oauth_token_secret=DEF&amp;user_id=1234567@N00".</param>
        /// <returns></returns>
        internal static OAuthAccessToken ParseResponse(string response)
        {
            if (response.Contains("//:"))
            {
                response = response.Substring(response.IndexOf("?", StringComparison.Ordinal));
            }
            Dictionary <string, string> parts = UtilityMethods.StringToDictionary(response);

            var token = new OAuthAccessToken();

            if (parts.ContainsKey("oauth_token"))
            {
                token.Token = parts["oauth_token"];
            }
            if (parts.ContainsKey("oauth_token_secret"))
            {
                token.TokenSecret = parts["oauth_token_secret"];
            }
            if (parts.ContainsKey("user_nsid"))
            {
                token.UserId = parts["user_nsid"];
            }
            if (parts.ContainsKey("fullname"))
            {
                token.FullName = parts["fullname"];
            }
            if (parts.ContainsKey("username"))
            {
                token.Username = parts["username"];
            }

            return(token);
        }
Beispiel #4
0
        /// <summary>
        /// Constructor for the OAuthException class.
        /// </summary>
        /// <param name="response"></param>
        /// <param name="innerException"></param>
        public OAuthException(string response, Exception innerException) : base("OAuth Exception", innerException)
        {
            FullResponse = response;

            OAuthErrorPameters = UtilityMethods.StringToDictionary(response);

            mess = "OAuth Exception occurred: " + OAuthErrorPameters["oauth_problem"];
        }
Beispiel #5
0
        /// <summary>
        /// Parses a URL parameter encoded string and returns a new <see cref="OAuthRequestToken"/>
        /// </summary>
        /// <param name="response">A URL parameter encoded string, e.g. "oauth_token=ABC&amp;oauth_token_secret=DEF".</param>
        /// <returns></returns>
        public static OAuthRequestToken ParseResponse(string response)
        {
            Dictionary <string, string> parameters = UtilityMethods.StringToDictionary(response);
            OAuthRequestToken           token      = new OAuthRequestToken();

            token.Token       = parameters["oauth_token"];
            token.TokenSecret = parameters["oauth_token_secret"];
            return(token);
        }
Beispiel #6
0
        /// <summary>
        /// Constructor for the OAuthException class.
        /// </summary>
        /// <param name="response"></param>
        /// <param name="innerException"></param>
        public OAuthException(string response, Exception innerException) : base("OAuth Exception", innerException)
        {
            FullResponse = response;

            try
            {
                OAuthErrorPameters = UtilityMethods.StringToDictionary(response);
            }
            catch (Exception)
            {
                throw new Exception("Failed to parse OAuth error message: " + FullResponse, innerException);
            }

            mess = "OAuth Exception occurred: " + OAuthErrorPameters["oauth_problem"];
        }