Changeset e50cb9741a7f…
Parent 138874f56881…
by Clayton Miller <clayton.miller@nexportengineering.com>
Changes to 25 files · Browse files at e50cb9741a7f Showing diff from parent 138874f56881 Diff from another changeset...
|
|
|
|
|
|
|
|
@@ -3,6 +3,9 @@
namespace NexportWebApiDemo.ApiModels.v1
{
+ //Each of these classes should reflect the request/response objects for the WebApi methods you intend to call
+ //You can choose to only implement particular datamembers, but the names MUST match the names in the online documentation
+
public class WAAuthTokenRequest
{
public string username { get; set; }
@@ -54,4 +57,14 @@ public TimeSpan? access_time_limit { get; set; }
public int publishing_model { 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.
+ /// </summary>
+ public class EditUserEmailRequest
+ {
+ public string login { get; set; }
+ public string email { get; set; }
+ }
}
|
@@ -8,25 +8,48 @@ {
public class HomeController : Controller
{
+ /// <summary>
+ /// Normally you wouldn't put all of this code in the Index action, but this should be
+ /// acceptable for a demo environment
+ /// </summary>
+ /// <returns></returns>
public ActionResult Index()
{
ViewBag.Title="NexportWebApiDemo";
var authRequest = new WAAuthTokenRequest()
{
+ //You'll need to change the username to your own
username = "Clay0M",
+ //This should ALWAYS be "password"
grant_type = "password",
+ //This should be YOUR password
password = "password"
};
+ //Need to authenticate before we can make any requests
var authToken = WebApiRequests.Authenticate(authRequest);
+
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
};
+ var editEmailRequest = new EditUserEmailRequest
+ {
+ //You'll need to change the login to the desired user login
+ login = "user58897",
+ //Must be valid format (foo@bar.baz)
+ email = "newemail@email.com"
+ };
+
var catResponse = WebApiRequests.GetCatalogs(catRequest, authToken.access_token);
var catalogs = catResponse.catalogs.ToList();
+ //Uncomment the next line to change the email
+ //WebApiRequests.EditUserEmail(editEmailRequest, authToken.access_token);
+ //Throw the results of GetCatalogs into the view
ViewBag.Catalogs = catalogs;
return View();
}
|
|
|
@@ -81,6 +81,7 @@ <th>Catalog</th>
<th>Organization</th>
<th>Date Created</th>
+ <!--You can add additional columns here, like Owner Name-->
</tr>
</thead>
<tbody>
@@ -96,6 +97,7 @@ <td>
@catalog.date_created
</td>
+ <!--Check CatalogResponseItem fields for other datamembers (such as catalog.owner_name)-->
</tr>
}
</tbody>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -4,6 +4,10 @@
namespace NexportWebApiDemoClient
{
+ /// <summary>
+ /// This is where all of the methods that call the WebApi methods live. The idea is to take the request information
+ /// and an access token, and call the WebApi method from its URL.
+ /// </summary>
public class WebApiRequests
{
private const string BaseUri = "http://local.nexportcampus.com/api/v1/";
@@ -66,5 +70,22 @@ return response.Content.ReadAsStringAsync().Result;
}
}
+
+ /// <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
+ /// only passes the email in.
+ /// </summary>
+ /// <param name="request">Contains fields from EditUserRequest from WebApi</param>
+ /// <param name="accessToken"></param>
+ public static void EditUserEmail(EditUserEmailRequest request, Guid accessToken)
+ {
+ using (var client = new HttpClient())
+ {
+ var requestUri = BaseUri + "AdminApi/EditUser?access_token=" + accessToken;
+ //While it may seem weird that I'm storing the result and not using it, this is actually necessary
+ var result = client.PostAsJsonAsync(requestUri, request).Result;
+ }
+ }
}
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Loading...