Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static PageResponse <T> CreateErrorResponse(LastResponseStatus status)
        {
            var r = new PageResponse <T>
            {
                Status = status
            };

            r.AddDefaultPageInfo();

            return(r);
        }
Exemplo n.º 3
0
        public new static PageResponse <T> CreateSuccessResponse()
        {
            var r = new PageResponse <T>
            {
                Status = LastResponseStatus.Successful
            };

            r.AddDefaultPageInfo();

            return(r);
        }
Exemplo n.º 4
0
        public new static PageResponse <T> CreateSuccessResponse()
        {
            var r = new PageResponse <T>
            {
                Success = true,
                Error   = LastFmApiError.None
            };

            r.AddDefaultPageInfo();

            return(r);
        }
Exemplo n.º 5
0
        public static PageResponse <T> CreateErrorResponse(LastFmApiError error)
        {
            var r = new PageResponse <T>
            {
                Success = false,
                Error   = error
            };

            r.AddDefaultPageInfo();

            return(r);
        }
Exemplo n.º 6
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);
        }