Monday, May 26, 2008

Code samples: invoking APIs using C#

I've previously posted sample code that demonstrates how to invoke EKP's APIs using Java and Visual Basic. Herewith, equivalent code using C#.

As with modern Visual Basic, C# is a .NET-based language. It's therefore fairly straightforward to translate our previous Visual Basic sample code into C#. As with the Visual Basic code, we will use an instance of System.Net.WebClient to make the API calls.

System.Net.WebClient client = new System.Net.WebClient();

Again, we need to set the credentials that WebClient will use for the HTTP basic authentication process. We must set the user name to a non-empty value to ensure that WebClient sends the authentication header, but the exact value doesn't matter since EKP ignores it. The password must match the value of the authentication.key property configured in the file WEB-INF/conf/ekp.properties.

String userName = "dummy";
String key = "mysecretkey";
client.Credentials = new System.Net.NetworkCredential(userName, key);

To create a user account, we send an HTTP POST request to /ekp/contentHandler/usersCsv, including CSV-formatted data in the body of the request.

String data1 = "Action,UserID,Password,FamilyName,GivenName\r\n"
             + "A,joestudent,dummypass,Student,Joe\r\n";
client.UploadString("https://ekp.example.com/ekp/contentHandler/usersCsv",
                    data1);

Similarly, we can enroll the user in a course with ID Derivatives_101 by sending an HTTP POST request to /ekp/enrollmentHandler, again including appropriately-formatted CSV data in the body of the request.

String data2 = "USERID,LEARNINGID\r\n"
             + "joestudent,Derivatives_101\r\n";
client.UploadString("https://ekp.example.com/ekp/enrollmentHandler", data2);

Sunday, May 25, 2008

Code samples: invoking APIs using Visual Basic

I've previously posted sample Java code that demonstrates how to invoke EKP's APIs. Herewith, equivalent code using Visual Basic .NET.

The .NET platform provides a couple of classes for sending HTTP requests, specifically System.Net.HttpWebRequest and System.Net.WebClient. Either will do the job. However, WebClient is a little simpler to work with, so that's what we'll use.

Dim client As Net.WebClient = New Net.WebClient()

API requests must include an HTTP basic authentication header. Fortunately, both WebClient and HttpWebRequest have built-in support for HTTP basic authentication, so this is straightforward. The user name is ignored by EKP; however, we must set the user name to a non-empty value, otherwise WebClient won't send the authentication header. The password must match the value of the authentication.key property configured in the file WEB-INF/conf/ekp.properties.

Dim userName As String = "dummy"    ' any non-empty value is okay
Dim password As String = "mysecretkey"
client.Credentials = New Net.NetworkCredential(userName, password)

To create a user account, we send an HTTP POST request to /ekp/contentHandler/usersCsv, including CSV-formatted data in the body of the request.

Dim data1 As String _
        = "Action,UserID,Password,FamilyName,GivenName" & ControlChars.CrLf _
        & "A,joestudent,dummypass,Student,Joe" & ControlChars.CrLf
client.UploadString("https://ekp.example.com/ekp/contentHandler/usersCsv", _
                    data1)

Similarly, we can enroll the user in a course with ID Derivatives_101 by sending an HTTP POST request to /ekp/enrollmentHandler, again including appropriately-formatted CSV data in the body of the request.

Dim data2 As String = "USERID,LEARNINGID" & ControlChars.CrLf _
                    & "joestudent,Derivatives_101" & ControlChars.CrLf
client.UploadString("https://ekp.example.com/ekp/enrollmentHandler", data2)

Saturday, May 17, 2008

Which catalog fields can EKP extract from the metadata in a SCORM package?

When you import a SCORM or IMS content package, EKP scans the file named imsmanifest.xml that every such package must contain, and extracts certain key information including: the course identifier; the title of the course; and information about the structure of the course including URLs and additional parameters used to launch the individual SCOs and assets.

In addition to this essential information, the package may also contain metadata in the form of a Learning Object Metadata (LOM) XML instance (either embedded in imsmanifest.xml itself, or else in a separate file referenced from imsmanifest.xml). If present, EKP can extract from this metadata any or all of the catalog fields listed below.

  • Description
  • Vendor
  • Duration Comments
  • Objectives
  • Training Hours

Shown below is a minimal LOM XML from which EKP can extract all of the additional catalog fields listed above. The relevant field values are shown in bold text. This example follows IMS LOM as used in SCORM 1.2 packages; however, the same information could be extracted from an IEEE LOM as used in SCORM 2004, and the differences would be minor.

(Note that this is a minimal XML instance from which EKP can extract the values mentioned above. The LOM XML schema denotes as mandatory some elements that are not actually required by EKP, hence this example is not actually valid against the schema, and the SCORM conformance test suite will report it as invalid.)

<lom xmlns="http://www.imsglobal.org/xsd/imsmd_rootv1p2p1">
   <general>
      <description>
         <langstring>Description</langstring>
      </description>
   </general>
   <lifecycle>
      <contribute>
         <centity>
            <vcard>ORG:Vendor</vcard>
         </centity>
      </contribute>
   </lifecycle>
   <educational>
      <typicallearningtime>
         <datetime>02:30:00</datetime>
         <description>
            <langstring>Duration Comments</langstring>
         </description>
      </typicallearningtime>
   </educational>
   <classification>
      <purpose>
        <value>
           <langstring>Educational Objective</langstring>
        </value>
      </purpose>
      <description>
         <langstring>Objective #1</langstring>
      </description>
   </classification>
   <classification>
      <purpose>
        <value>
           <langstring>Educational Objective</langstring>
        </value>
      </purpose>
      <description>
         <langstring>Objective #2</langstring>
      </description>
   </classification>
   <classification>
      <purpose>
        <value>
           <langstring>Educational Objective</langstring>
        </value>
      </purpose>
      <description>
         <langstring>Objective #3</langstring>
      </description>
   </classification>
</lom>