/// <summary> /// Create a new API request. /// </summary> /// <param name="authInfo">The authentication info to send to the server.</param> /// <param name="requestPath">The API request path. You can use the constants given in <see cref="ApiRequest"/>.</param> public ApiRequest(AuthenticationInfo authInfo, string requestPath) { if (!authInfo.Authenticated) throw new InvalidOperationException(Properties.Resources.ExceptionUnauthenticatedState); WebRequest = (HttpWebRequest)System.Net.WebRequest.Create( CreateApiUrl(authInfo, requestPath)); WebRequest.Accept = "application/xml"; PropertyInfo headerInfo = WebRequest.GetType().GetProperty("UserAgent"); if (headerInfo != null) { headerInfo.SetValue(WebRequest, "MyAquinasMobileAPI", null); } else { WebRequest.Headers[HttpRequestHeader.UserAgent] = "MyAquinasMobileAPI"; } WebRequest.Headers["AuthToken"] = authInfo.Token.ToString(); }
/// <summary> /// Initialises a new Student object with the given token /// </summary> /// <param name="aquinasNumber">The short-form Aquinas number of the student.</param> /// <param name="token">The student's Authentication Token.</param> public Student(string aquinasNumber, Guid token) { AquinasNumber = aquinasNumber.ToUpper(); AdmissionNumber = GetAdmissionNumber(AquinasNumber); AuthInfo = new AuthenticationInfo(AdmissionNumber, null, token); }
/// <summary> /// Creates a valid API URL. /// </summary> /// <param name="authInfo">Authentication info used to provide the admission number.</param> /// <param name="requestPath">The API request path. You can use the constants given in <see cref="ApiRequest"/>.</param> /// <returns></returns> private string CreateApiUrl(AuthenticationInfo authInfo, string requestPath) { return String.Format(Properties.Resources.ApiTemplateUrl, requestPath, authInfo.AdmissionNumber); }
/// <summary> /// Authenticates the user with the given password. /// This will start an asynchronous authentication request. /// </summary> /// <param name="password">The user's login password.</param> public void Authenticate(string password) { AuthInfo = new AuthenticationInfo(AdmissionNumber, password); AuthInfo.BeginAuthenticate(AuthenticationCallback); }