Skip to content

Instantly share code, notes, and snippets.

@rubysoho07
Last active July 29, 2018 03:24
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 rubysoho07/062df1cf32a72a0bbc3ebd77c5111312 to your computer and use it in GitHub Desktop.
Save rubysoho07/062df1cf32a72a0bbc3ebd77c5111312 to your computer and use it in GitHub Desktop.
xAPI Example 1. Actor, Verb, Object
from tincan import Agent, Verb, Activity, ActivityDefinition, LanguageMap
# Agent (Check: https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#242-actor)
actor = Agent(
name="Test User",
mbox="mailto:test@example.org"
)
print actor.to_json()
# Result: {"mbox": "mailto:test@example.org", "name": "Test User", "objectType": "Agent"}
# Verb: (Check: https://registry.tincanapi.com/#home/verbs,
# https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#243-verb)
verb = Verb(
id="https://brindlewaye.com/xAPITerms/verbs/loggedin/",
display=LanguageMap({'en-us': 'Log In'})
)
print verb.to_json()
# Result: {"id": "https://brindlewaye.com/xAPITerms/verbs/loggedin/", "display": {"en-us": "Log In"}}
# Object(Activity)
# Check: https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#244-object
obj = Activity(
id="http://example.org/activity/1",
definition=ActivityDefinition(
name=LanguageMap({'en-us': 'Test Activity'})
)
)
print obj.to_json()
# Result:
# {"definition": {"name": {"en-us": "Test Activity"}}, "id": "http://example.org/activity/1", "objectType": "Activity"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment