Connectster.Shopify.ShopifyCommunicator.GetPageOfProducts C# (CSharp) Method

GetPageOfProducts() public method

public GetPageOfProducts ( ShopifyStoreAuth storeAuth, int numWanted, int pageNumber ) : List
storeAuth ShopifyStoreAuth
numWanted int
pageNumber int
return List
        public List<ShopifyProduct> GetPageOfProducts(ShopifyStoreAuth storeAuth, int numWanted, int pageNumber)
        {
            if (storeAuth == null)
            {
                Logger.Warn("ShopifyCommunicator::GetPageOfProducts: storeAuth cannot be null");
                return null;
            }

            if (!(numWanted > 0 && numWanted < 251 && pageNumber > 0))
            {
                Logger.WarnFormat(
                    "ShopifyCommunicator::GetPageOfProducts(): numWanted({0}) must be between 0 and 251, pageNumber({1}) must be >0.",
                    numWanted, pageNumber);
                return null;
            }

            var url = new StringBuilder();
            url.Append(_protocol);
            url.Append(storeAuth.StoreSubDomain);
            url.Append(_domain);
            url.Append("/admin/products.xml?");

            url.Append("limit=" + numWanted);
            url.Append("&page=" + pageNumber);

            XmlDocument xDoc = ShopifyGet(url.ToString(), HashString(_appAuth.Secret + storeAuth.StoreAuthToken));
            //Now the fun part of parsing this xml.
            if (xDoc == null)
            {
                return null;
            }

            XmlNodeList productNodeList = xDoc.SelectNodes("//products/product");

            var returnList = new List<ShopifyProduct>();
            //			Foreach product found, serialize and add to return list
            if (productNodeList != null)
                foreach (XmlNode productNode in productNodeList)
                {
                    var productDoc = new XmlDocument();
                    productDoc.AppendChild(productDoc.ImportNode(productNode, true));
                    var serializedResponse = new ShopifyResponse<ShopifyProduct>(productDoc);

                    if (serializedResponse.State == ResponseState.OK)
                    {
                        returnList.Add(serializedResponse.ResponseObject);
                    }
                    else
                    {
                        XmlNodeList idNode = productNode.SelectNodes("//id");
                        if (idNode != null)
                        {
                            string productId = idNode.Count > 0 ? idNode[0].InnerText : "null";
                            Logger.ErrorFormat(
                                "ShopifyCommunicator()::GetPageOfProducts(): Couldn't parse product ({0}) returned in page of product.",
                                productId);
                        }
                    }
                }

            return returnList;
        }