/// <summary> /// This Async service For Get the Player's Info. /// </summary> /// <exception cref="GameballException">Thrown if the request fails..</exception> public async Task <PlayerInfo> GetPlayerInfoAsync(string playerUniqueId, GameballLang Language = 0) { if (Language != 0) { Client.DefaultRequestHeaders.Add("lang", GameballUtils.ToValidLang(Language)); } PlayerInfoRequest Info = new PlayerInfoRequest() { PlayerUniqueId = playerUniqueId, Hash = GameballUtils.GetSHA1(playerUniqueId, TransactionKey) }; Info.Validate(); var response = await this.Client.PostAsync(ApiBase + GameballConstants.PlayerInfo, new StringContent(Info.Serialize(), Encoding.UTF8, "application/json")); //Removes Overhead of lang header if not necessary in next calls. Client.DefaultRequestHeaders.Remove("lang"); if (!response.IsSuccessStatusCode) { throw (BuildGameballException(response)); } else { return(JsonConvert.DeserializeObject <PlayerInfo>(await response.Content.ReadAsStringAsync())); } }
/// <summary> /// converts GameballLang to corresponding code. /// </summary> /// <param name="Language"></param> /// <returns></returns> public static string ToValidLang(GameballLang Language) { switch (Language) { case GameballLang.English: return("en"); case GameballLang.Arabic: return("ar"); case GameballLang.French: return("fr"); case GameballLang.German: return("de"); case GameballLang.Italian: return("it"); case GameballLang.Polish: return("pl"); case GameballLang.Portuguese: return("pt"); case GameballLang.Spanish: return("es"); default: return("en"); } }