private string BuildResourceURL(int pageSize, int page = 1, PluginEnums.Sorting sort = PluginEnums.Sorting.RATING)
        {
            string URL = baseURL + "resources/free";

            URL += "?size=" + pageSize;
            if (page != 1)
            {
                URL += "&page=" + page;
            }

            URL += "&sort=" + WebUtility.HtmlEncode(sort.APIName());
            URL += "&fields=" + resourceFields;

            return(URL);
        }
Example #2
0
        public static string APIName(this PluginEnums.Sorting sorting)
        {
            switch (sorting)
            {
            case PluginEnums.Sorting.RATING: return("-rating");

            case PluginEnums.Sorting.DOWNLOADS: return("-downloads");

            case PluginEnums.Sorting.LAST_UPDATE: return("-updateDate");

            case PluginEnums.Sorting.SUBMISSION_DATE: return("-releaseDate");

            default: throw new ArgumentException("Undefined enum entry in PluginEnums.Sorting.APIName()");
            }
        }
Example #3
0
        public static string FriendlyName(this PluginEnums.Sorting sorting)
        {
            switch (sorting)
            {
            case PluginEnums.Sorting.RATING: return("Most Ratings");

            case PluginEnums.Sorting.DOWNLOADS: return("Downloads");

            case PluginEnums.Sorting.LAST_UPDATE: return("Last Updated");

            case PluginEnums.Sorting.SUBMISSION_DATE: return("Release Date");

            default: throw new ArgumentException("Undefined enum entry in PluginEnums.Sorting.FriendlyName()");
            }
        }
        public List <Plugin> RequestResourceList(out bool fullyLoaded, int page = 1, PluginEnums.Sorting sort = PluginEnums.Sorting.RATING)
        {
            string url  = BuildResourceURL(pageSize, page, sort);
            string json = ResponseCache.Instance.UncacheResponse(url);

            if (json == null)
            {
                try
                {
                    Uri            uri     = new Uri(url);
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                    request.UserAgent = ApplicationManager.UserAgent;
                    using (var response = request.GetResponse())
                        using (Stream stream = response.GetResponseStream())
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                json = reader.ReadToEnd();
                            }

                    ResponseCache.Instance.CacheResponse(url, json);
                } catch (WebException e)
                {
                    ErrorLogger.Append(e);
                    Console.WriteLine("Could not receive Spigot Plugins. (either spiget.org is down or your Internet connection is not working)\nRequest URL: " + url);
                    fullyLoaded = true;
                    return(new List <Plugin>());
                }
            }

            var plugins = JsonConvert.DeserializeObject <List <Plugin> >(json);

            foreach (Plugin plugin in plugins)
            {
                plugin.author   = RequestAuthor(plugin.author.id);
                plugin.category = RequestCategory(plugin.category.id);
            }

            fullyLoaded = plugins.Count < pageSize;

            return(plugins);
        }