Skip to content

Instantly share code, notes, and snippets.

@jameskeane
Created October 1, 2012 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameskeane/3812865 to your computer and use it in GitHub Desktop.
Save jameskeane/3812865 to your computer and use it in GitHub Desktop.
Working draft of 3rd party module API
// Top hat monocle - third party module API
// =====
// ## Module Discovery
// All 3rd party modules _must_ be discoverable based on a simple http resource URI
// i.e.
// GET /modules/question
{
name: "Question Module",
author: "Top Hat Monocle",
apikey: "2314h32kljh349823jefskludfs90234ij",
create: 'https://example.com/modules/question/create',
render: 'https://example.com/modules/question/render',
grade: 'https://example.com/modules/question/grade'
}
// ## Module creation
// give us an HTML page that can be embedded with google CAJA,
// we will give you save(JSON) and cancel() methods
// ## Module Rendering
hat.module // The JSON object that was saved during object creation
hat.user = { // The user object
id: 'random GUID that anonymously identifies the user',
is_teacher: function() {}, // Are they a teacher?
is_student: function() {} // Are they a student?
}
// Different APIs are exposed based on the user's role
if( hat.user.is_teacher() ) {
// teachers can exposed globals
hat.global(key, value)
// per user kv-store
hat.set(key, value)
hat.get(key)
// record marks, for gradebook
// Called when a student submits an answer,
// submission is of the form {submission: {your json}, grade: 0-1}
hat.on('student:submission', function(student, submission) {
});
} else if( hat.user.is_student() ) {
// This is for submitting answers, the student:submission event will be called
hat.submit(JSON);
// per user kv-store
hat.set(key, value)
hat.get(key)
hat.on('global:update', function(key, value) {
});
hat.on('global:created', function(key, value) {
});
}
// ## Module Grading
// We will post a JSON object to your grading URI, i.e.
// --
// POST /modules/question/grade
// { module: {The JSON saved during creation}, submission: {the JSON submitted by the student} }
// -- You will respond with a normalized grade between 0 and 1
// i.e. { grade: 0.7 }
@hughes
Copy link

hughes commented Oct 2, 2012

is everything from hat.module down is code that exists within the template that they give us? or is hat a variable in our app that they're allowed to access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment