public static RoomOverview GetRoomOverview(string roomName, Interval interval = Interval.None) { List <RESTParameter> restParameters = new List <RESTParameter>(); restParameters.Add(new RESTParameter(RESTParameterType.HEADER, "X-Token", Context.Token)); restParameters.Add(new RESTParameter(RESTParameterType.HEADER, "X-Username", Context.Token)); string url = Parameters.URLs.Game.Room.Overview; restParameters.Add(new RESTParameter(RESTParameterType.PATH, "{roomName}", roomName)); if (interval != Interval.None) { url = Parameters.URLs.Game.Room.OverviewWithInterval; restParameters.Add(new RESTParameter(RESTParameterType.PATH, "{interval}", ((int)interval).ToString())); } RESTResponse restResponse = CallRESTService.CallService(url, restParameters, CallModeServiceREST.GET); if (restResponse.Error != null) { throw new Exception(); } else { Tools.CheckBodyResponse(restResponse.Body); return(JsonConvert.DeserializeObject <RoomOverview>(restResponse.Body)); } }
public static SearchUserResult SearchUser(string username) { List <RESTParameter> restParameters = new List <RESTParameter>(); restParameters.Add(new RESTParameter(RESTParameterType.PATH, "{username}", username)); RESTResponse restResponse = CallRESTService.CallService(Parameters.URLs.User.Find, restParameters, CallModeServiceREST.GET); SearchUserResult searchUserResult = new SearchUserResult(); if (restResponse.Error != null) { searchUserResult.Success = false; } else { Tools.CheckBodyResponse(restResponse.Body); searchUserResult.UserFound = ((JObject)JsonConvert.DeserializeObject(restResponse.Body)).SelectToken("user").ToObject <UserAccount>(); searchUserResult.Success = true; } return(searchUserResult); }
public static MyAccount GetMyAccount() { List <RESTParameter> restParameters = new List <RESTParameter>(); restParameters.Add(new RESTParameter(RESTParameterType.HEADER, "X-Token", Context.Token)); restParameters.Add(new RESTParameter(RESTParameterType.HEADER, "X-Username", Context.Token)); RESTResponse restResponse = CallRESTService.CallService(Parameters.URLs.Auth.AboutMe, restParameters, CallModeServiceREST.GET); if (restResponse.Error != null) { throw new Exception(); } Tools.CheckBodyResponse(restResponse.Body); return(JsonConvert.DeserializeObject <MyAccount>(restResponse.Body)); }
public static AuthenticationAnswer Authenticate(string email, string password) { List <RESTParameter> restParameters = new List <RESTParameter>(); var body = new { email = email, password = password }; restParameters.Add(new RESTParameter(RESTParameterType.POST, JsonConvert.SerializeObject(body))); RESTResponse restResponse = CallRESTService.CallService(Parameters.URLs.Auth.Signin, restParameters, CallModeServiceREST.POST); AuthenticationAnswer authenticationAnswer = new AuthenticationAnswer(); if (restResponse.Error != null) { authenticationAnswer.Success = false; switch (restResponse.HTTPStatuCode) { case 401: authenticationAnswer.ErrorType = AuthenticationErrorType.Unauthorized; break; default: authenticationAnswer.ErrorType = AuthenticationErrorType.Unknow; break; } } else { Tools.CheckBodyResponse(restResponse.Body); authenticationAnswer.Token = ((JObject)JsonConvert.DeserializeObject(restResponse.Body)).SelectToken("token").ToObject <string>(); Context.Token = authenticationAnswer.Token; authenticationAnswer.Success = true; } return(authenticationAnswer); }