Exemple #1
0
        /*
         * internal String GetErrorResponseText(int errorCode, String errorMessage)
         * {
         *  return GSRequest.GetErrorResponseText(this.method, errorCode, errorMessage);
         * }
         *
         * internal String GetErrorResponseText(int errorCode)
         * {
         *  return GetErrorResponseText(errorCode, null);
         * }*/

        internal static String GetErrorResponseText(String method, GSObject clientParams, int errorCode, String errorMessage)
        {
            if (errorMessage == null || errorMessage.Length == 0)
            {
                errorMessage = GetErrorMessage(errorCode);
            }

            String format = "json";

            if (clientParams != null)
            {
                format = clientParams.GetString("format", "json");
            }

            if (format.Equals("json"))
            {
                return("{errorCode:" + errorCode + ",errorMessage:\"" + errorMessage + "\"}");
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                sb.Append("<" + method + "Response xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:com:gigya:api http://socialize-api.gigya.com/schema\" xmlns=\"urn:com:gigya:api\">");
                sb.Append("<errorCode>" + errorCode + "</errorCode>");
                sb.Append("<errorMessage>" + errorMessage + "</errorMessager>");
                sb.Append("</" + method + "Response>");
                return(sb.ToString());
            }
        }
        /// <summary>
        /// This is a utility method for generating a base string for calculating the OAuth1 cryptographic signature.
        /// </summary>
        /// <param name="httpMethod">"POST" or "GET"</param>
        /// <param name="url">the full url without params</param>
        /// <param name="requestParams">list of params in the form of a GSObject</param>
        /// <returns>the base string to act on for calculating the OAuth1 cryptographic signature</returns>
        public static string CalcOAuth1Basestring(string httpMethod, string url, GSObject requestParams)
        {
            // Normalize the URL per the OAuth requirements
            StringBuilder normalizedUrlSB = new StringBuilder();
            Uri           u = new Uri(url);

            normalizedUrlSB.Append(u.Scheme.ToLowerInvariant());
            normalizedUrlSB.Append("://");
            normalizedUrlSB.Append(u.Host.ToLowerInvariant());
            if ((u.Scheme == "HTTP" && u.Port != 80) || (u.Scheme == "HTTPS" && u.Port != 443))
            {
                normalizedUrlSB.Append(':');
                normalizedUrlSB.Append(u.Port);
            }
            normalizedUrlSB.Append(u.LocalPath);


            // Create a sorted list of query parameters
            StringBuilder querystring = new StringBuilder();

            foreach (string key in requestParams.GetKeys())
            {
                if (requestParams.GetString(key) != null)
                {
                    querystring.Append(key);
                    querystring.Append("=");
                    querystring.Append(GSRequest.UrlEncode(requestParams.GetString(key) ?? String.Empty));
                    querystring.Append("&");
                }
            }
            if (querystring.Length > 0)
            {
                querystring.Length--;                           // remove the last ampersand
            }
            // Construct the base string from the HTTP method, the URL and the parameters
            string basestring =
                httpMethod.ToUpperInvariant() + "&" +
                GSRequest.UrlEncode(normalizedUrlSB.ToString()) + "&" +
                GSRequest.UrlEncode(querystring.ToString());

            return(basestring);
        }
Exemple #3
0
        public GSResponse(String method, Dictionary <string, string> headers, string responseText, GSLogger logSoFar)
        {
            logger.Write(logSoFar);
            this.headers      = headers;
            this.responseText = responseText.Trim();

            if (responseText == null || responseText.Length == 0)
            {
                return;
            }
            else
            {
                logger.Write("response", responseText);
            }

            if (responseText.StartsWith("{")) // JSON format
            {
                try
                {
                    this.data         = new GSObject(responseText);
                    this.errorCode    = data.GetInt("errorCode", 0);
                    this.errorMessage = data.GetString("errorMessage", null);
                }
                catch (Exception ex)
                {
                    this.errorCode    = 500;
                    this.errorMessage = ex.Message;
                }
            }
            else
            {
                // using string search to avoid dependency on parser
                String errCodeStr = GetStringBetween(responseText, "<errorCode>", "</errorCode>");
                if (errCodeStr != null)
                {
                    this.errorCode    = int.Parse(errCodeStr);
                    this.errorMessage = GetStringBetween(responseText, "<errorMessage>", "</errorMessage>");
                }
                //initializing the data with XML transformed to GSObject
                this.data = XmlToJSON(responseText);
            }
        }
Exemple #4
0
 public GSSession(GSObject currDictionaryParams)
     : this(currDictionaryParams.GetString("access_token"), currDictionaryParams.GetString("access_token_secret"), currDictionaryParams.GetLong("expires_in"))
 {
 }