/// <summary> /// Create a new container for information relevant to requested User /// </summary> /// <param name="userKey"></param> public ItchUserRequest(string userKey) { if (string.IsNullOrEmpty(userKey)) { requestError = RequestType.ErrorType.DetailsMissing; return; } string requestURL = "https://itch.io/api/1/" + userKey + "/me"; string jsonResponse = ItchGlobal.GetResposeHTTPAsync(requestURL).GetAwaiter().GetResult(); if (jsonResponse == "{\"errors\":[\"invalid key\"]}") { requestError = RequestType.ErrorType.InvalidKey; } else { user = new RequestType.User(); var jsonObject = System.Json.JsonValue.Parse(jsonResponse); user.avatarURL = jsonObject["user"].ContainsKey("cover_url") ? (string)jsonObject["user"]["cover_url"] : ""; user.displayName = jsonObject["user"].ContainsKey("display_name") ? (string)jsonObject["user"]["display_name"] : ""; user.isDeveloper = jsonObject["user"].ContainsKey("developer") ? (bool)jsonObject["user"]["developer"] : false; user.userID = jsonObject["user"].ContainsKey("id") ? (int)jsonObject["user"]["id"] : 0; user.profileURL = jsonObject["user"].ContainsKey("url") ? (string)jsonObject["user"]["url"] : ""; user.isGamer = jsonObject["user"].ContainsKey("gamer") ? (bool)jsonObject["user"]["gamer"] : false; user.userName = jsonObject["user"].ContainsKey("username") ? (string)jsonObject["user"]["username"] : ""; user.isPressUser = jsonObject["user"].ContainsKey("press_user") ? (bool)jsonObject["user"]["press_user"] : false; } }
/// <summary> /// If the user has an avatar, the image will be returned in the form of a byte array. /// <para></para> /// This can then passed to various Engines/IDE's to create an image in their format. /// <para></para> /// Unity Example: Texture2D.LoadImage(ItchToolkit.ItchUserRequest.GetAvatarByteArray("URL")); /// </summary> /// <returns></returns> public byte[] GetAvatarByteArray() { if (!string.IsNullOrEmpty(user.avatarURL)) { return(ItchGlobal.GetResposeHTTPAsyncAsByteArray(user.avatarURL).GetAwaiter().GetResult()); } else { return(null); } }