示例#1
0
        public void DropCourse(int courseKey, HttpRCB <SuccessResponse> callback)
        {
            if (_session_token == "")
            {
                return;
            }

            var req = new RestRequest(Method.POST)
            {
                Resource = "api/user/dropEnrolledCourse"
            };

            req.AddParameter("uuid", _session_token);
            req.AddParameter("courseID", courseKey);

            var             res  = _client.Execute <SuccessResponse>(req);
            SuccessResponse succ = res.Data;

            if (succ == null)
            {
                ErrorPrinter.BadData("Parsing drop course failed");
                return;
            }

            callback(succ);
        }
示例#2
0
        public void DeletePreviousCourse(string courseID, HttpRCB <SuccessResponse> callback)
        {
            if (_session_token == "")
            {
                return;
            }

            var req = new RestRequest(Method.POST)
            {
                Resource = "api/user/deletePrevious"
            };

            req.AddParameter("uuid", _session_token);
            req.AddParameter("courseID", courseID);
            var             res  = _client.Execute <SuccessResponse>(req);
            SuccessResponse succ = res.Data;

            if (succ == null)
            {
                ErrorPrinter.BadData("Parsing delete previous class failed");
                return;
            }

            callback(succ);
        }
示例#3
0
        public void EnrollInCourse(int courseKey, HttpRCB <FullEnrollResponse> callback)
        {
            if (_session_token == "")
            {
                return;
            }

            var req = new RestRequest(Method.POST)
            {
                Resource = "api/user/enroll/"
            };

            req.AddParameter("uuid", _session_token);
            req.AddParameter("key", courseKey);
            var res = _client.Execute <FullEnrollResponse>(req);
            FullEnrollResponse succ = res.Data;

            if (succ == null)
            {
                ErrorPrinter.BadData("Parsing enrolled class failed");
                return;
            }

            callback(succ);
        }
示例#4
0
        public void Login(string email, string password, HttpRCB <LoginResponse> callback)
        {
            Console.WriteLine("LOGGING IN");
            var postRequest = new RestRequest(Method.POST)
            {
                Resource = "api/user/login"
            };

            postRequest.AddParameter("email", email);
            postRequest.AddParameter("password", password);

            var response = _client.Execute <LoginResponse>(postRequest);

            if (response.Data == null)
            {
                ErrorPrinter.BadData("Failed to login");
                return;
            }

            bool worked = callback(response.Data);

            if (worked)
            {
                Console.Write("Setting session token: ");

                _session_token = response.Data.uuid;

                Console.WriteLine(_session_token);
            }
        }
示例#5
0
        public void ChangePassword(string oldPass, string newPass, HttpRCB <SuccessResponse> callback)
        {
            var req = new RestRequest(Method.POST)
            {
                Resource = "api/user/changePassword"
            };

            req.AddParameter("uuid", _session_token);
            req.AddParameter("currentPassword", oldPass);
            req.AddParameter("newPassword", newPass);
            var             res  = _client.Execute <SuccessResponse>(req);
            SuccessResponse succ = res.Data;

            if (succ == null)
            {
                ErrorPrinter.BadData("Parsing change password failed");
                return;
            }

            callback(succ);
        }
示例#6
0
        public List <AvailableCourse> SearchForCourses(string term, string prefix, string number, string ilastname, int startTime, int endTime, int slots, HttpRCB <FullAvailableCourseResponse> callback)
        {
            if (_session_token == "")
            {
                return(null);
            }

            var req = new RestRequest(Method.GET)
            {
                Resource = "api/courses/search/" + _session_token
            };

            if (term != "")
            {
                req.AddParameter("term", term);
            }
            if (prefix != "")
            {
                req.AddParameter("prefix", prefix);
            }
            if (number != "")
            {
                req.AddParameter("number", number);
            }
            if (ilastname != "")
            {
                req.AddParameter("instructor", ilastname);
            }
            if (startTime != -1 && endTime != -1)
            {
                if (startTime < endTime)
                {
                    req.AddParameter("startTime", startTime);
                    req.AddParameter("endTime", endTime);
                }
            }
            if (slots >= 0)
            {
                req.AddParameter("slotsAvailable", slots);
            }

            var res = _client.Execute <FullAvailableCourseResponse>(req);
            FullAvailableCourseResponse courses = res.Data;

            if (courses == null)
            {
                ErrorPrinter.BadData("Parsing searched courses failed");
                return(null);
            }

            if (callback(courses))
            {
                return(courses?.ToCourses());
            }
            else
            {
                return(null);
            }
        }
示例#7
0
        public void NewUser(string email, string password, string first, string last, HttpRCB <SuccessResponse> callback)
        {
            Console.WriteLine("CREATING NEW USER");
            var req = new RestRequest(Method.POST)
            {
                Resource = "api/user/newUser"
            };

            req.AddParameter("email", email);
            req.AddParameter("password", password);
            req.AddParameter("firstName", first);
            req.AddParameter("lastName", last);

            var res = _client.Execute <SuccessResponse>(req);

            if (res.Data == null)
            {
                ErrorPrinter.BadData("Failed to add new user");
                return;
            }

            callback(res.Data);
        }