Changeset ae8056732884…
Parent ac87ac0178ec…
by Clayton Miller <clayton.miller@nexportengineering.com>
Changes to 26 files · Browse files at ae8056732884 Showing diff from parent ac87ac0178ec Diff from another changeset...
|
|
|
|
|
|
|
|
@@ -58,6 +58,52 @@ public int publishing_model { get; set; }
}
+ public class SubscriptionResponse
+ {
+ public Guid id { get; set; }
+ public Guid user_id { get; set; }
+ public Guid org_id { get; set; }
+ public DateTime utc_date_created { get; set; }
+ public DateTime utc_date_uploaded { get; set; }
+ public string billing_code { get; set; }
+ public DateTime utc_expiration_date { get; set; }
+ }
+
+ public class SectionResponse
+ {
+ public Guid id { get; set; }
+ public string section_number { get; set; }
+ public string section_ceus { get; set; }
+ public string section_duration { get; set; }
+ }
+
+ public class SectionEnrollmentResponse
+ {
+ public Guid id { get; set; }
+ public SectionResponse section { get; set; }
+ public DateTime enrollment_date { get; set; }
+ public DateTime expiration_date { get; set; }
+ public string course_title { get; set; }
+ public DateTime utc_completion_date { get; set; }
+ public Guid syllabus_id { get; set; }
+ public string unique_name { get; set; }
+ public int percent_assignments_complete { get; set; }
+ }
+
+ public class ClassroomSsoRequest
+ {
+ public int display { get; set; }
+ public Guid enrollment_id { get; set; }
+ }
+
+ public class ClassroomSsoResponse
+ {
+ public string url { get; set; }
+ public Guid access_token { get; set; }
+ public string token_type { get; set; }
+ public int expires_in { get; set; }
+ }
+
/// <summary>
/// This is an example of a partially implemented class, useful for calling EditUser when you only want
/// to change the email. This way, you don't need to have every single datamember available.
|
@@ -19,11 +19,11 @@ var authRequest = new WAAuthTokenRequest()
{
//You'll need to change the username to your own
- username = "Clay0M",
+ username = "SRGAdmin",
//This should ALWAYS be "password"
grant_type = "password",
//This should be YOUR password
- password = "password"
+ password = "welcome"
};
//Need to authenticate before we can make any requests
@@ -32,15 +32,15 @@ var catRequest = new CatalogRequest()
{
//You'll need to change this to the ID of the organization you want catalogs for
- group_id = new Guid("ed5ba4ac-73e4-4e64-837f-b26cb8ef3c4b"),
- //AvailableToMembers
- publishing_model = 0
+ group_id = new Guid("2d7aacf8-4a0c-4900-87b0-289bf60afac7"),
+ //For sale in marketplace
+ publishing_model = 1
};
var editEmailRequest = new EditUserEmailRequest
{
//You'll need to change the login to the desired user login
- login = "user58897",
+ login = "SRGDemo1",
//Must be valid format (foo@bar.baz)
email = "newemail@email.com"
};
@@ -51,8 +51,25 @@ //Uncomment the next line to change the email
//WebApiRequests.EditUserEmail(editEmailRequest, authToken.access_token);
+ //In this case, the email address is guaranteed to be unique, so there will only be one user returned
+ var demoUserId = WebApiRequests.GetUsers("srgdemo1@test.com", authToken.access_token).First().user_id;
+ var subscriptionId = WebApiRequests.GetSubscription(demoUserId, "shcohsdemo1", authToken.access_token).id;
+ //Just get the first enrollment for now. You could also filter by a particular course title or something
+ //similar if you wanted to.
+ var sectionEnrollmentId = WebApiRequests.GetSectionEnrollmentsForSubscription(subscriptionId,
+ authToken.access_token).First().id;
+
+ var classroomRequest = new ClassroomSsoRequest
+ {
+ enrollment_id = sectionEnrollmentId,
+ display = 0
+ };
+
+ var classroomUrl = WebApiRequests.GetClassroomUrl(classroomRequest, authToken.access_token);
+
//Throw the results of GetCatalogs into the view
ViewBag.Catalogs = catalogs;
+ ViewBag.SsoClassroomUrl = classroomUrl;
return View();
}
}
|
|
|
@@ -1,4 +1,7 @@ - @{ var catalogs = @ViewBag.Catalogs; }
+@{
+ var catalogs = @ViewBag.Catalogs;
+ var classroomUrl = @ViewBag.SsoClassroomUrl;
+}
<!DOCTYPE html>
<html lang="en">
@@ -48,9 +51,12 @@ </li>
<li>
<a href="#">Services</a>
- </li>
- <li>
- <a href="#">Contact</a>
+ </li>
+ <li>
+ <a href="#">Contact</a>
+ </li>
+ <li>
+ <a href="@classroomUrl">Go To Classroom</a>
</li>
</ul>
</div>
@@ -120,7 +126,7 @@ <footer>
<div class="row">
<div class="col-lg-12">
- <p>Copyright © Your Website 2014</p>
+ <p>Copyright © Your Website 2015</p>
</div>
</div>
</footer>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -17,7 +17,7 @@ {
using (var client = new HttpClient())
{
- client.BaseAddress = new Uri("http://local.nexportcampus.com/api/v1/");
+ client.BaseAddress = new Uri("http://stable.nexportcampus.com/api/v1/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
@@ -1,4 +1,5 @@ using System;
+using System.Collections.Generic;
using System.Net.Http;
using NexportWebApiDemo.ApiModels.v1;
@@ -11,7 +12,8 @@ /// </summary>
public class WebApiRequests
{
- private const string BaseUri = "http://local.nexportcampus.com/api/v1/";
+ //This should be the api url of the server you are on
+ private const string BaseUri = "http://stable.nexportcampus.com/api/v1/";
public static WAAuthenticationTokenResponse Authenticate(WAAuthTokenRequest request)
{
@@ -72,6 +74,60 @@ }
}
+ public static List<GetUserResponse> GetUsers(string searchTerm, Guid accessToken)
+ {
+ using (var client = new HttpClient())
+ {
+ var requestUri = BaseUri + "AdminApi/GetUsers?search_term=" + searchTerm + "&access_token=" +
+ accessToken;
+ var response = client.GetAsync(requestUri).Result;
+
+ return response.Content.ReadAsAsync<List<GetUserResponse>>().Result;
+ }
+ }
+
+ public static SubscriptionResponse GetSubscription(Guid userId, string orgShortName, Guid accessToken)
+ {
+ using (var client = new HttpClient())
+ {
+ var requestUri = BaseUri + "AdminApi/GetSubscription?user_id=" + userId + "&org_short_name=" +
+ orgShortName + "&access_token=" + accessToken;
+ var response = client.GetAsync(requestUri).Result;
+
+ return response.Content.ReadAsAsync<SubscriptionResponse>().Result;
+ }
+ }
+
+ /// <summary>
+ /// Partial implementation, only searches based on subscription
+ /// </summary>
+ /// <returns>List of section enrollments for the given subscription</returns>
+ public static List<SectionEnrollmentResponse> GetSectionEnrollmentsForSubscription(Guid subscriptionId,
+ Guid accessToken)
+ {
+ using (var client = new HttpClient())
+ {
+ var requestUri = BaseUri + "LearningApi/GetSectionEnrollments?subscriber_id=" + subscriptionId +
+ "&access_token=" + accessToken;
+
+ var response = client.GetAsync(requestUri).Result;
+
+ return response.Content.ReadAsAsync<List<SectionEnrollmentResponse>>().Result;
+ }
+ }
+
+
+ public static string GetClassroomUrl(ClassroomSsoRequest request, Guid accessToken)
+ {
+ using (var client = new HttpClient())
+ {
+ var requestUri = BaseUri + "SsoApi/Classroom?access_token=" + accessToken;
+ var response = client.PostAsJsonAsync(requestUri, request).Result;
+
+ return response.Content.ReadAsAsync<ClassroomSsoResponse>().Result.url;
+ }
+ }
+
/// <summary>
/// Example of partial EditUser implementation. Instead of editing all the fields, we only want to change the
/// email. Instead of having a different WebApi method to do this, simply make a method to call EditUser that
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Loading...