Example #1
0
        public SpacedockMod GetMod(int modId)
        {
            string json;

            try
            {
                json = Call("/mod/" + modId);
            }
            catch (NativeAndCurlDownloadFailedKraken e)
            {
                // SpaceDock returns a valid json with an error message in case of non 200 codes.
                json = e.responseContent;
            }

            // Check if the mod has been removed from SD.
            var error = JsonConvert.DeserializeObject <SpacedockError>(json);

            if (error.error)
            {
                var errorMessage = $"Could not get the mod from SpaceDock, reason: {error.reason}";
                throw new Kraken(errorMessage);
            }

            return(SpacedockMod.FromJson(json));
        }
Example #2
0
        public void SDHome()
        {
            var sd = new SpacedockMod {name = "foo bar", id = 123};

            // SDHome no longer escapes URLs.
            Assert.AreEqual("https://spacedock.info/mod/123/foo bar", sd.GetPageUrl().ToString());
        }
Example #3
0
        public SpacedockMod GetMod(int modId)
        {
            string json;

            try
            {
                json = Call("/mod/" + modId);
            }
            catch (WebException e)
            {
                // SpaceDock returns a valid json with an error message in case of non 200 codes.
                json = new System.IO.StreamReader(e.Response.GetResponseStream(), System.Text.Encoding.UTF8).ReadToEnd();
                if (string.IsNullOrEmpty(json))
                {
                    // ... sometimes. Other times we get nothing.
                    throw;
                }
            }

            // Check if the mod has been removed from SD.
            var error = JsonConvert.DeserializeObject <SpacedockError>(json);

            if (error.error)
            {
                var errorMessage = $"Could not get the mod from SpaceDock, reason: {error.reason}";
                throw new Kraken(errorMessage);
            }

            return(SpacedockMod.FromJson(json));
        }
Example #4
0
        public SpacedockMod GetMod(int modId)
        {
            var json = Call("/mod/" + modId);

            // Check if the mod has been removed from SD.
            var error = JsonConvert.DeserializeObject <SpacedockError>(json);

            if (error.error)
            {
                var errorMessage = string.Format("Could not get the mod from SpaceDock, reason: {0}", error.reason);
                throw new Kraken(errorMessage);
            }

            return(SpacedockMod.FromJson(json));
        }
        private static List<string> GetAuthors(SpacedockMod mod)
        {
            var result = new List<string> { mod.author };

            if (mod.shared_authors != null)
                result.AddRange(mod.shared_authors.Select(i => i.Username));

            return result;
        }