-
Notifications
You must be signed in to change notification settings - Fork 40
Added example script and dedicated example resource config file #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# An example script showing the functionality of the TinCanPython Library | ||
|
||
import uuid | ||
from resources import lrs_properties | ||
from tincan import ( | ||
RemoteLRS, | ||
Statement, | ||
Agent, | ||
Verb, | ||
Activity, | ||
Context, | ||
LanguageMap, | ||
ActivityDefinition, | ||
StateDocument, | ||
) | ||
|
||
# construct an LRS | ||
print "constructing the LRS..." | ||
lrs = RemoteLRS( | ||
version=lrs_properties.version, | ||
endpoint=lrs_properties.endpoint, | ||
username=lrs_properties.username, | ||
password=lrs_properties.password, | ||
) | ||
print "...done" | ||
|
||
# construct the actor of the statement | ||
print "constructing the Actor..." | ||
actor = Agent( | ||
name='UserMan', | ||
mbox='mailto:tincanpython@tincanapi.com', | ||
) | ||
print "...done" | ||
|
||
# construct the verb of the statement | ||
print "constructing the Verb..." | ||
verb = Verb( | ||
id='http://adlnet.gov/expapi/verbs/experienced', | ||
display=LanguageMap({'en-US': 'experienced'}), | ||
) | ||
print "...done" | ||
|
||
# construct the object of the statement | ||
print "constructing the Object..." | ||
object = Activity( | ||
id='http://tincanapi.com/TinCanPython/Example/0', | ||
definition=ActivityDefinition( | ||
name=LanguageMap({'en-US': 'TinCanPython Library'}), | ||
description=LanguageMap({'en-US': 'Use of, or interaction with, the TinCanPython Library'}), | ||
), | ||
) | ||
print "...done" | ||
|
||
# construct a context for the statement | ||
print "constructing the Context..." | ||
context = Context( | ||
registration=uuid.uuid4(), | ||
instructor=Agent( | ||
name='Lord TinCan', | ||
mbox='mailto:lordtincan@tincanapi.com', | ||
), | ||
#language='en-US', | ||
) | ||
print "...done" | ||
|
||
# construct the actual statement | ||
print "constructing the Statement..." | ||
statement = Statement( | ||
actor=actor, | ||
verb=verb, | ||
object=object, | ||
context=context, | ||
) | ||
print "...done" | ||
|
||
# save our statement to the remote_lrs and store the response in 'response' | ||
print "saving the Statement..." | ||
response = lrs.save_statement(statement) | ||
|
||
if not response: | ||
raise ValueError("statement failed to save") | ||
print "...done" | ||
|
||
# retrieve our statement from the remote_lrs using the id returned in the response | ||
print "Now, retrieving statement..." | ||
response = lrs.retrieve_statement(response.content.id) | ||
|
||
if not response.success: | ||
raise ValueError("statement could not be retrieved") | ||
print "...done" | ||
|
||
print "constructing new Statement from retrieved statement data..." | ||
ret_statement = response.content | ||
print "...done" | ||
|
||
# now, using our old statement and our returned statement, we can send multiple statements | ||
# note: these statements are logically identical, but are 2 separate objects | ||
print "saving both Statements" | ||
response = lrs.save_statements([statement, ret_statement]) | ||
|
||
if not response: | ||
raise ValueError("statements failed to save") | ||
print "...done" | ||
|
||
# we can query our statements using an object | ||
# constructing the query object with common fields | ||
# note: more information about queries can be found in the API documentation: | ||
# docs/build/html/tincan.html#module-tincan.remote_lrs | ||
query = { | ||
"agent": actor, | ||
"verb": verb, | ||
"activity": object, | ||
"related_activities": True, | ||
"related_agents": True, | ||
"limit": 2, | ||
} | ||
|
||
print "querying statements..." | ||
response = lrs.query_statements(query) | ||
|
||
if not response: | ||
raise ValueError("statements could not be queried") | ||
print "...done" | ||
|
||
# now we will explore saving a document, e.g. a state document | ||
print "constructing a state document..." | ||
state_document = StateDocument( | ||
activity=object, | ||
agent=actor, | ||
id='stateDoc', | ||
content=bytearray('stateDocValue', encoding='utf-8'), | ||
) | ||
print "...done" | ||
|
||
print "saving state document..." | ||
response = lrs.save_state(state_document) | ||
|
||
if not response.success: | ||
raise ValueError("could not save state document") | ||
print "...done" |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
Contains user-specific information for testing. | ||
""" | ||
|
||
|
||
endpoint="<endpoint>" | ||
version ="<valid_version>" # 1.0.1 | 1.0.0 | 0.95 | 0.9 | ||
username="<username>" | ||
password="<password>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[metadata] | ||
description-file = README.md | ||
description-file = README.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same name should be used for the same Agent, if you want to switch names then switch IFIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does IFI mean mbox? I wanted the instructor to be Lord TinCan and the learner to be UserMan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'mbox' is one of the IFI's, yes.