Exemplo n.º 1
0
        /// <summary>
        /// Make an HTTP Request to the Shopify API
        /// </summary>
        /// <param name="method">method to be used in the request</param>
        /// <param name="path">the path that should be requested</param>
        /// <seealso cref="http://api.shopify.com/"/>
        /// <returns>the server response</returns>
        public async Task <object> Call(HttpMethod method, string path, NameValueCollection parameters = null, object data = null)
        {
            // cute bit of dynamic feature.
            String reqBody;

            if (data is String)
            {
                reqBody = (String)data;
            }
            else
            {
                EnsureTranslator();
                reqBody = Translator.Encode(data);
            }
            var result = await CallRaw(method, GetRequestContentType(), path, parameters, reqBody);

            //At least one endpoint will return an empty string, that we need to account for.
            if (string.IsNullOrWhiteSpace(result))
            {
                return(null);
            }

            if (Translator != null)
            {
                return(Translator.Decode(result));
            }
            else
            {
                return(result);
            }
        }