public IEnumerable <StudentPoco> Course(string token, string id) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); var decodedToken = PearsonApiUtilities.DecodeFrom64(token); Mapper.CreateMap <Student, StudentPoco>(); var context = new StudentContext(); var students = (from s in context.Students where s.CourseIds.Every(id) select s).ToList(); foreach (var student in students) { try { var userJson = PearsonApiUtilities.GetUserJson(decodedToken, student.StudentId); var users = new JavaScriptSerializer().Deserialize <Users>(userJson); student.FirstName = users.users[0].firstName; student.LastName = users.users[0].lastName; } catch (Exception) { //skip it... HACK } } var result = Mapper.Map <List <Student>, IEnumerable <StudentPoco> >(students); return(result); }
// GET /api/students/5 public string GetStudent(string token, string id) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); var decodedToken = PearsonApiUtilities.DecodeFrom64(token); return(PearsonApiUtilities.GetUserJson(decodedToken, id)); }
public ActionResult OAuthTest() { const string username = "******"; const string password = "******"; var accessToken = PearsonApiUtilities.GetOauthAccessToken(username, password); ViewBag.OAuthResult = accessToken; ViewBag.MeCoursesResult = PearsonApiUtilities.XAuthApiCall(accessToken, "http://m-api.ecollege.com/me/courses"); ViewBag.CourseDetails = PearsonApiUtilities.XAuthApiCall(accessToken, "https://m-api.ecollege.com/courses/3312999"); ViewBag.Students = PearsonApiUtilities.XAuthApiCall(accessToken, "https://m-api.ecollege.com/courses/3312999/students"); ViewBag.User = PearsonApiUtilities.XAuthApiCall(accessToken, "https://m-api.ecollege.com/users/4433390"); return(View()); }
public ActionResult Test() { ViewBag.Message = "Api test page."; const string username = "******"; const string password = "******"; var accessToken = PearsonApiUtilities.GetOauthAccessToken(username, password); string[] tokenParts = accessToken.Split('|'); ViewBag.UserId = tokenParts[2]; ViewBag.AccessToken = PearsonApiUtilities.EncodeTo64(accessToken); return(View()); }
public List <StudentCourses.Course> Student(string token, string id) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); var decodedToken = PearsonApiUtilities.DecodeFrom64(token); var meCoursesJson = PearsonApiUtilities.XAuthApiCall(decodedToken, "http://m-api.ecollege.com/me/courses"); var meCourses = new JavaScriptSerializer().Deserialize <MeCourses>(meCoursesJson); var result = new List <StudentCourses.Course>(); foreach (var course in meCourses.courses) { foreach (var link in course.links) { var courseDetailJson = PearsonApiUtilities.XAuthApiCall(decodedToken, link.href); var courseDetail = new JavaScriptSerializer().Deserialize <StudentCourses>(courseDetailJson); result.Add(courseDetail.courses[0]); } } return(result); }
// POST /api/signin //[AllowCrossSiteJson] public SigninResult Authenticate(string username, string password) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); var test = Request.Content.Headers.ToString(); var token = PearsonApiUtilities.GetOauthAccessToken(username, password); //return token; string[] tokenParts = token.Split('|'); var userID = tokenParts[2]; var userJson = PearsonApiUtilities.GetUserJson(token, userID); var result = new SigninResult() { EncodedAuthToken = PearsonApiUtilities.EncodeTo64(token), UserId = userID, User = userJson }; return(result); }