/// <summary> /// Fetches data about all the games you've uploaded or have edit access to. /// </summary> public DeveloperGamesRequest(string yourKey) { if (string.IsNullOrEmpty(yourKey)) { requestError = RequestType.ErrorType.DetailsMissing; return; } string requestURL = "https://itch.io/api/1/" + yourKey + "/my-games"; string jsonResponse = ItchGlobal.GetResposeHTTPAsync(requestURL).GetAwaiter().GetResult(); switch (jsonResponse) { case "{\"errors\":[\"invalid key\"]}": requestError = RequestType.ErrorType.InvalidKey; break; case "{\"errors\":[\"api key does not permit `profile: games`\"]}": requestError = RequestType.ErrorType.OutOfScopeKey; break; default: games = new List <RequestType.Game>(); var jsonObject = System.Json.JsonValue.Parse(jsonResponse); for (int i = 0; i < jsonObject["games"].Count; i++) { RequestType.Game game = new RequestType.Game(); game.earnings = new List <RequestType.Game.Earning>(); game.gameCoverURL = jsonObject["games"][i].ContainsKey("cover_url") ? (string)jsonObject["games"][i]["cover_url"] : ""; game.createdDate = jsonObject["games"][i].ContainsKey("created_at") ? (string)jsonObject["games"][i]["created_at"] : ""; game.downloadCount = jsonObject["games"][i].ContainsKey("downloads_count") ? (int)jsonObject["games"][i]["downloads_count"] : 0; game.gameID = jsonObject["games"][i].ContainsKey("id") ? (int)jsonObject["games"][i]["id"] : 0; game.minPrice = jsonObject["games"][i].ContainsKey("min_price") ? (int)jsonObject["games"][i]["min_price"] : 0; game.supportsAndroid = jsonObject["games"][i].ContainsKey("p_android") ? (bool)jsonObject["games"][i]["p_android"] : false; game.supportsLinux = jsonObject["games"][i].ContainsKey("p_linux") ? (bool)jsonObject["games"][i]["p_linux"] : false; game.supportsOSX = jsonObject["games"][i].ContainsKey("p_osx") ? (bool)jsonObject["games"][i]["p_osx"] : false; game.supportsWindows = jsonObject["games"][i].ContainsKey("p_windows") ? (bool)jsonObject["games"][i]["p_windows"] : false; game.isPublished = jsonObject["games"][i].ContainsKey("published") ? (bool)jsonObject["games"][i]["published"] : false; game.publishedDate = jsonObject["games"][i].ContainsKey("published_at") ? (string)jsonObject["games"][i]["published_at"] : ""; game.purchaseCount = jsonObject["games"][i].ContainsKey("purchases_count") ? (int)jsonObject["games"][i]["purchases_count"] : 0; game.gameDescription = jsonObject["games"][i].ContainsKey("short_text") ? (string)jsonObject["games"][i]["short_text"] : ""; game.gameTitile = jsonObject["games"][i].ContainsKey("title") ? (string)jsonObject["games"][i]["title"] : ""; game.type = jsonObject["games"][i].ContainsKey("type") ? (string)jsonObject["games"][i]["type"] : ""; game.gameURL = jsonObject["games"][i].ContainsKey("url") ? (string)jsonObject["games"][i]["url"] : ""; game.viewCount = jsonObject["games"][i].ContainsKey("views_count") ? (int)jsonObject["games"][i]["views_count"] : 0; if (jsonObject["games"][i].ContainsKey("earnings")) { for (int ii = 0; ii < jsonObject["games"][i]["earnings"].Count; ii++) { RequestType.Game.Earning earning = new RequestType.Game.Earning(); earning.currency = jsonObject["games"][i]["earnings"][ii].ContainsKey("currency") ? (string)jsonObject["games"][i]["earnings"][ii]["currency"] : ""; earning.purchaseAmountString = jsonObject["games"][i]["earnings"][ii].ContainsKey("amount_formatted") ? (string)jsonObject["games"][i]["earnings"][ii]["amount_formatted"] : ""; earning.purchaseAmountInt = jsonObject["games"][i]["earnings"][ii].ContainsKey("amount") ? (int)jsonObject["games"][i]["earnings"][ii]["amount"] : 0; game.earnings.Add(earning); } } games.Add(game); } break; } }
/// <summary> /// Fetches a download key from and API call. /// <para></para> /// If it exists for game and returns it. /// </summary> /// <param name="yourKey"></param> /// <param name="gameID"></param> /// <param name="userID"></param> public DownloadKeyRequest(string yourKey, string gameID, string userID) { if (string.IsNullOrEmpty(yourKey) || string.IsNullOrEmpty(gameID) || string.IsNullOrEmpty(userID)) { error = RequestType.ErrorType.DetailsMissing; return; } string requestURL = "https://itch.io/api/1/" + yourKey + "/game/" + gameID + "/download_keys?user_id=" + userID; string jsonResponse = ItchGlobal.GetResposeHTTPAsync(requestURL).GetAwaiter().GetResult(); switch (jsonResponse) { case "{\"errors\":[\"invalid key\"]}": error = RequestType.ErrorType.InvalidKey; break; case "{\"errors\":[\"game_id must be an integer\"]}": error = RequestType.ErrorType.InvalidGameID; break; case "{\"errors\":[\"invalid game_id\"]}": error = RequestType.ErrorType.InvalidGameID; break; case "{\"errors\":[\"no download key found\"]}": error = RequestType.ErrorType.InvalidGameID; break; default: downloadKey = new RequestType.DownloadKey(); downloadKey.owner = new ItchUserRequest.RequestType.User(); var jsonObject = System.Json.JsonValue.Parse(jsonResponse); downloadKey.dateCreated = jsonObject["download_key"].ContainsKey("created_at") ? (string)jsonObject["download_key"]["created_at"] : ""; downloadKey.gameID = jsonObject["download_key"].ContainsKey("game_id") ? (int)jsonObject["download_key"]["game_id"] : 0; downloadKey.downloads = jsonObject["download_key"].ContainsKey("downloads") ? (int)jsonObject["download_key"]["downloads"] : 0; downloadKey.keyID = jsonObject["download_key"].ContainsKey("id") ? (int)jsonObject["download_key"]["id"] : 0; downloadKey.owner.avatarURL = jsonObject["download_key"]["owner"].ContainsKey("cover_url") ? (string)jsonObject["download_key"]["owner"]["cover_url"] : ""; downloadKey.owner.displayName = jsonObject["download_key"]["owner"].ContainsKey("display_name") ? (string)jsonObject["download_key"]["owner"]["display_name"] : ""; downloadKey.owner.isDeveloper = jsonObject["download_key"]["owner"].ContainsKey("developer") ? (bool)jsonObject["download_key"]["owner"]["developer"] : false; downloadKey.owner.userID = jsonObject["download_key"]["owner"].ContainsKey("id") ? (int)jsonObject["download_key"]["owner"]["id"] : 0; downloadKey.owner.profileURL = jsonObject["download_key"]["owner"].ContainsKey("url") ? (string)jsonObject["download_key"]["owner"]["url"] : ""; downloadKey.owner.isGamer = jsonObject["download_key"]["owner"].ContainsKey("gamer") ? (bool)jsonObject["download_key"]["owner"]["gamer"] : false; downloadKey.owner.userName = jsonObject["download_key"]["owner"].ContainsKey("username") ? (string)jsonObject["download_key"]["owner"]["username"] : ""; downloadKey.owner.isPressUser = jsonObject["download_key"]["owner"].ContainsKey("press_user") ? (bool)jsonObject["download_key"]["owner"]["press_user"] : false; downloadKey.downloadKey = jsonObject["download_key"].ContainsKey("key") ? (string)jsonObject["download_key"]["key"] : ""; break; } }