Пример #1
0
        public static int GetUserCount(int id, Size size, SizeOperators op)
        {
            int width  = 0;
            int height = 0;

            SizeToParams(size, out width, out height);
            return(GetUserCount(id, width, height, op));
        }
Пример #2
0
        public static int GetPopularCount(Size size, SizeOperators op)
        {
            int width  = 0;
            int height = 0;

            SizeToParams(size, out width, out height);
            return(GetPopularCount(width, height, op));
        }
Пример #3
0
        public static int GetUserCount(int id, int width, int height, SizeOperators op)
        {
            WallpaperResponse response = Get(buildUrl(LookupMethods.user_count, InfoLevels.Basic, 1, width, height, op, id));

            if (response == null)
            {
                LastResult = "An unknown error has occured!";
            }
            else if (response.Counts == null)
            {
                LastResult = response.ErrorMessage;
            }
            else
            {
                return(response.Count);
            }

            return(-1);
        }
Пример #4
0
        private static string buildUrl(LookupMethods method, InfoLevels infolevel = InfoLevels.Basic, int page = 1, int width = 0, int height = 0, SizeOperators op = SizeOperators.Equal, int id = 0, string query = null, SortMethods sortby = SortMethods.Newest)
        {
            if (AuthenticationKey == null || AuthenticationKey.Trim().Length == 0)
            {
                throw new NullReferenceException("API Key cannot be null!");
            }

            if (page < 1)
            {
                page = 1;
            }

            if ((width <= 0 && height > 0) || (width > 0 && height <= 0))
            {
                throw new ArgumentException("Both Width and height must be specified!");
            }

            string toReturn = baseUrl + AuthenticationKey + "&method=" + method;

            switch (infolevel)
            {
            //case InfoLevels.Basic:
            case InfoLevels.IncludeCategory:
                toReturn += "&info_level=2";
                break;

            case InfoLevels.IncludeCategoryCollectionAndGroup:
                toReturn += "&info_level=3";
                break;
            }

            if (page > 1)
            {
                toReturn += "&page=" + page;
            }

            if (width > 0)
            {
                toReturn += "&width=" + width + "&height=" + height;
            }

            switch (op)
            {
            //case SizeOperators.Equal:
            case SizeOperators.Max:
                toReturn += "&operator=max";
                break;

            case SizeOperators.Min:
                toReturn += "&operator=min";
                break;
            }

            if (id > 0)
            {
                toReturn += "&id=" + id;
            }

            if (method == LookupMethods.search || method == LookupMethods.user)
            {
                toReturn += "&term=" + Uri.EscapeDataString(query);
            }

            switch (sortby)
            {
            case SortMethods.Favorites:
                toReturn += "&sort=favorites";
                break;

            case SortMethods.Newest:
                toReturn += "&sort=newest";
                break;

            case SortMethods.Rating:
                toReturn += "&sort=rating";
                break;

            case SortMethods.Views:
                toReturn += "&sort=views";
                break;
            }

            return(toReturn += "&check_last=1");
        }
Пример #5
0
        private static List <string> BuildUrls(LookupMethods method, InfoLevels infolevel = InfoLevels.Basic, int maxResults = 30, int width = 0, int height = 0, SizeOperators op = SizeOperators.Equal, int id = 0, string query = null, SortMethods sortby = SortMethods.Newest)
        {
            int maxPages = MaxResultsToPages(maxResults);

            List <string> toReturn = new List <string>();

            for (int i = 0; i < maxPages; i++)
            {
                toReturn.Add(buildUrl(method, infolevel, i, width, height, op, id, query, sortby));
            }

            return(toReturn);
        }
Пример #6
0
        public static async Task <List <Wallpaper> > QueryAsync(LookupMethods method, InfoLevels level = InfoLevels.Basic, int maxResults = 30, Size?size = null, SizeOperators op = SizeOperators.Equal, int id = 0, string searchterm = null, SortMethods sortBy = SortMethods.Newest)
        {
            int width  = 0;
            int height = 0;

            SizeToParams(size, out width, out height);

            List <string> urls = BuildUrls(method, level, maxResults, width, height, op, id, searchterm, sortBy);

            return(await Task.Run(() => {
                try
                {
                    return Get(urls);
                }
                catch (Exception) { return null; }
            }));
        }