Exemplo n.º 1
0
        /// <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();
        }
Exemplo n.º 2
0
 /// <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);
 }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
0
 /// <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);
 }