Example #1
0
        public static PageResponse <T> CreateSuccessResponse(JToken itemsToken, JToken pageInfoToken, Func <JToken, T> parseToken, LastPageResultsType pageResultsType)
        {
            var items = ParseItemsToken(itemsToken, parseToken);

            var pageresponse = new PageResponse <T>(items)
            {
                Status = LastResponseStatus.Successful
            };

            switch (pageResultsType)
            {
            case LastPageResultsType.Attr:
                pageresponse.AddPageInfoFromJToken(pageInfoToken);
                break;

            case LastPageResultsType.OpenQuery:
                pageresponse.AddPageInfoFromOpenQueryJToken(pageInfoToken);
                break;

            case LastPageResultsType.None:
            default:
                pageresponse.AddDefaultPageInfo(pageresponse.Content);
                break;
            }

            return(pageresponse);
        }
Example #2
0
        public static PageResponse <T> CreateSuccessResponse(JToken itemsToken, JToken pageInfoToken, Func <JToken, T> parseToken, LastPageResultsType pageResultsType)
        {
            IEnumerable <T> items;

            if (itemsToken != null && itemsToken.Children().Any())
            {
                // array notation isn't used on the api when only one object is available
                if (itemsToken.Type != JTokenType.Array)
                {
                    var item = parseToken(itemsToken);
                    items = new[] { item };
                }
                else
                {
                    items = itemsToken.Children().Select(parseToken);
                }
            }
            else
            {
                items = Enumerable.Empty <T>();
            }

            var pageresponse = new PageResponse <T>(items);

            switch (pageResultsType)
            {
            case LastPageResultsType.Attr:
                pageresponse.AddPageInfoFromJToken(pageInfoToken);
                break;

            case LastPageResultsType.OpenQuery:
                pageresponse.AddPageInfoFromOpenQueryJToken(pageInfoToken);
                break;

            case LastPageResultsType.None:
            default:
                pageresponse.AddDefaultPageInfo(pageresponse.Content);
                break;
            }

            pageresponse.Success = true;

            return(pageresponse);
        }