/// <summary> /// send credentials to get user token /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="facebookId"></param> /// <returns></returns> public string Login(string username, string password, string facebookId = "") { var message = new LoginMessage() { FacebookId = facebookId, Username = username, Password = password }; var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/login", message).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } var token = JsonConvert.DeserializeObject <string>(body); if (!string.IsNullOrWhiteSpace(token)) { UserToken.Token = token; } return(token); }
/// <summary> /// Delete the map with the specified hash id /// </summary> /// <param name="mapHashId"></param> public void DeleteMap(string mapHashId) { var httpResponse = HttpRequestHelper.DeleteAsync(Endpoint + "/" + mapHashId, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
public static string RetrieveAccessToken(string code) { var url = $"https://graph.facebook.com/oauth/access_token?client_id={FacebookAppId}&redirect_uri={RedirectUri}&client_secret={FacebookAppSecret}&code={code}"; var response = HttpRequestHelper.GetAsync(url).Result; var body = HttpRequestHelper.GetContent(response).Result; var token = HttpUtility.ParseQueryString(body).Get("access_token"); return(token); }
/// <summary> /// set the visibility of the tutorial forthe specified user token /// </summary> /// <param name="visibility"></param> public void SetLightTutorialVisibility(bool visibility) { var httpResponse = HttpRequestHelper.GetAsync(Endpoint + "/tutorial/light/" + visibility, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// Get a list of all the user's friends /// </summary> /// <returns></returns> public void CompleteDaily() { var httpResponse = HttpRequestHelper.GetAsync(Endpoint + "/done", UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// Add a image for the map /// </summary> /// <param name="mapHashId"></param> /// <param name="imageBytes"></param> public void UpdateMapImage(string mapHashId, byte[] imageBytes) { var httpResponse = HttpRequestHelper.PostBodyContentAsync(Endpoint + "/image/" + mapHashId, imageBytes, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// The host can start the game he host given the right gameHashId /// </summary> /// <param name="gameHashId"></param> public void StartGame(string gameHashId) { var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/start/" + gameHashId, null, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// Update friend list with specified friend list /// </summary> /// <param name="friends"></param> public void UpdateFriends(List <BasicUserInfo> friends) { var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint, friends, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// Add an entry to the leaderboard of the specified zone hash id /// </summary> /// <param name="zoneHashId"></param> /// <param name="leader"></param> public void AddLeaderEntry(string zoneHashId, LeaderModel leader) { var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/" + zoneHashId, leader, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// Update current user profile with providen information /// </summary> /// <param name="profile"></param> /// <returns></returns> public ProfileModel UpdateUserProfile(ProfileModel profile) { var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint, profile, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <ProfileModel>(body)); }
/// <summary> /// Get the info on the user wven if he is private /// </summary> /// <param name="hashId"></param> /// <returns></returns> public ProfileModel GetUserInfoPlease(string hashId) { var httpResponse = HttpRequestHelper.GetAsync(Endpoint + "/pretty/please/" + hashId, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <ProfileModel>(body)); }
/// <summary> /// get if the user is currently online /// </summary> /// <param name="userHashId"></param> /// <returns></returns> public bool GetIsConnected(string userHashId) { var httpResponse = HttpRequestHelper.GetAsync(Endpoint + "/isonline/" + userHashId, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <bool>(body)); }
/// <summary> /// Get all the information on a map (with content of map) /// </summary> /// <param name="mapHashId"></param> /// <returns></returns> public MapModel GetMapFromId(string mapHashId) { var httpResponse = HttpRequestHelper.GetAsync(Endpoint + "/search/" + mapHashId, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <MapModel>(body)); }
/// <summary> /// Get a list of all the user's friends /// </summary> /// <returns></returns> public List <BasicUserInfo> GetFriends() { var httpResponse = HttpRequestHelper.GetAsync(Endpoint, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } return(JsonConvert.DeserializeObject <List <BasicUserInfo> >(body)); }
/// <summary> /// Get info one one specific game /// </summary> /// <param name="gameHashId"></param> /// <returns></returns> public GameModel GetGameInfo(string gameHashId) { var httpResponse = HttpRequestHelper.GetAsync(Endpoint + "/" + gameHashId, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <GameModel>(body)); }
/// <summary> /// Create a new game with the specified information /// </summary> /// <param name="game"></param> /// <returns></returns> public GameModel CreateGame(GameModel game) { var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/new", game, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <GameModel>(body)); }
/// <summary> /// Get information on all the maps of a specific user /// </summary> /// <param name="playerHashId"></param> /// <returns></returns> public List <MapModel> GetPlayerZones(string playerHashId) { var httpResponse = HttpRequestHelper.GetAsync(Endpoint + "/user/" + playerHashId, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <List <MapModel> >(body)); }
/// <summary> /// Get all game that are currently on the server /// </summary> /// <returns></returns> public List <GameModel> GetAllGames() { var httpResponse = HttpRequestHelper.GetAsync(Endpoint, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <List <GameModel> >(body)); }
/// <summary> /// Disconnect from game /// </summary> /// <param name="gameHashId"></param> public void DisconnectGame(string gameHashId) { var message = new JoinGameMessage() { GameHashId = gameHashId }; var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/disconnect", message, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// Delete the game identified by the given hash id /// </summary> /// <param name="gameHashId"></param> public void DeleteGame(string gameHashId) { if (string.IsNullOrWhiteSpace(gameHashId)) { return; } var httpResponse = HttpRequestHelper.DeleteAsync(Endpoint + "/one/" + gameHashId, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// Delete current user /// </summary> public void DeleteUser() { if (UserToken.Token == "") { return; } var httpResponse = HttpRequestHelper.DeleteAsync(Endpoint, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// To spectate a game /// </summary> /// <param name="gameHashId"></param> /// <returns></returns> public GameModel Spectate(string gameHashId) { var message = new JoinGameMessage() { GameHashId = gameHashId }; var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/spectate", message, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <GameModel>(body)); }
/// <summary> /// Update an existing game /// Con only update the content and the level /// </summary> /// <param name="hashId"></param> /// <param name="content"></param> /// <param name="level"></param> public void UpdateMap(string hashId, string content, int level) { var map = new MapModel() { HashId = hashId, Content = content, Level = level }; var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/update", map, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NoContent) { throw new Exception(body); } }
/// <summary> /// Create a new map with the given information /// return the new game hash id /// </summary> /// <param name="name"></param> /// <param name="content"></param> /// <param name="level"></param> /// <returns></returns> public string CreateMap(string name, string content, int level = 0) { var map = new MapModel() { Name = name, Content = content, Level = level }; var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/new", map, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <string>(body)); }
/// <summary> /// Performs a request to the specified URI and returns an EveApiResponse of specified type. /// </summary> /// <typeparam name="T">The type parameter for the xml response.</typeparam> /// <param name="uri">The URI to request.</param> /// <returns></returns> public override T Request <T>(Uri uri) { DateTime cachedUntil; bool fromCache = CacheExpirationRegister.TryGetValue(uri, out cachedUntil) && DateTime.UtcNow < cachedUntil; string data = ""; HttpWebRequest request = HttpRequestHelper.CreateRequest(uri); request.ContentType = ContentType; request.CachePolicy = fromCache ? new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable) : new HttpRequestCachePolicy(HttpRequestCacheLevel.Reload); request.Proxy = null; try { data = HttpRequestHelper.GetContent(request); } catch (WebException e) { var response = (HttpWebResponse)e.Response; Debug.WriteLine("From cache: " + response.IsFromCache); if (response.StatusCode != HttpStatusCode.BadRequest) { throw new InvalidRequestException("Request caused a WebException.", e); } Stream responseStream = response.GetResponseStream(); if (responseStream == null) { throw new InvalidRequestException("Request caused a WebException.", e); } using (var reader = new StreamReader(responseStream)) { data = reader.ReadToEnd(); var error = Serializer.Deserialize <EveApiError>(data); throw new InvalidRequestException(error.Error.ErrorCode, error.Error.ErrorText, e); } } var xml = Serializer.Deserialize <T>(data); register(uri, xml); SaveCacheState(); return(xml); }
public GameModel CreateGame(string name, int maxPlayer, List <string> zonesHash, string password = "") { var isPrivate = !string.IsNullOrWhiteSpace(password); var gameModel = new GameModel() { Name = name, MaxPlayersCount = maxPlayer, IsPrivate = isPrivate, Password = password, ZonesHashId = zonesHash }; var httpResponse = HttpRequestHelper.PostObjectAsync(Endpoint + "/new", gameModel, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } return(JsonConvert.DeserializeObject <GameModel>(body)); }
/// <summary> /// Get the image for the map and return it's path /// </summary> /// <param name="mapHashId"></param> /// <param name="imagePath"></param> /// <returns></returns> public string GetMapImage(string mapHashId, string imagePath = null) { var httpResponse = HttpRequestHelper.GetAsync(Endpoint + "/image/" + mapHashId, UserToken.Token).Result; var body = HttpRequestHelper.GetContent(httpResponse).Result; var statusCode = HttpRequestHelper.GetStatusCode(httpResponse); if (statusCode != HttpStatusCode.OK) { throw new Exception(body); } var fileData = JsonConvert.DeserializeObject <byte[]>(body); var path = imagePath ?? Path.GetTempPath() + mapHashId + ".png"; using (var image = Image.FromStream(new MemoryStream(fileData))) { image.Save(path, ImageFormat.Png); } return(path); }