mindonsite - Mos.xApi 0.4.0-beta-0013

A fluent .Net Standard library to create xApi statements and communicate with a LRS

PM> Install-Package Mos.xApi -Version 0.4.0-beta-0013 -Source https://www.myget.org/F/mindonsite/api/v3/index.json

Copy to clipboard

> nuget.exe install Mos.xApi -Version 0.4.0-beta-0013 -Source https://www.myget.org/F/mindonsite/api/v3/index.json

Copy to clipboard

> dotnet add package Mos.xApi --version 0.4.0-beta-0013 --source https://www.myget.org/F/mindonsite/api/v3/index.json

Copy to clipboard
<PackageReference Include="Mos.xApi" Version="0.4.0-beta-0013" />
Copy to clipboard
source https://www.myget.org/F/mindonsite/api/v3/index.json

nuget Mos.xApi  ~> 0.4.0-beta-0013
Copy to clipboard

> choco install Mos.xApi --version 0.4.0-beta-0013 --source https://www.myget.org/F/mindonsite/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "mindonsite" -SourceLocation "https://www.myget.org/F/mindonsite/api/v2"
Install-Module -Name "Mos.xApi" -RequiredVersion "0.4.0-beta-0013" -Repository "mindonsite" -AllowPreRelease
Copy to clipboard

FluentxApi

A fluent .Net Standard library to create xApi statements and communicate with a LRS

.NET Core NuGet

Installation

Add the NuGet package to your project using the Package Manager Console.

PM> Install-Package Mos.xApi

Getting started

Creating a statement

Use the Statement.Create static method to start the Statement building. All the complex objects then have a fluent builder that simplifies the creation of the Statement object.

var newStatement =
    Statement.Create(
        Actor.CreateAgent("Example Learner").WithMailBox("example.learner@adlnet.gov"),
        Verb.Create("http://adlnet.gov/expapi/verbs/attempted").AddDisplay("en-US", "attempted"),
        StatementObject.CreateActivity("http://example.adlnet.gov/xapi/example/simpleCBT")
                        .AddName("en-US", "simple CBT course")
                        .AddDescription("en-US", "A fictious example CBT course"))
        .WithResult(Result.Create()
                            .WithScore(new Score(0.95))
                            .WithSuccess(true)
                            .WithCompletion(true)
                            .WithDuration(TimeSpan.FromSeconds(1234)))
        .Build();

Once the Statement has been created, it can be serialized to json using the ToJson method. This method takes a boolean argument setting if it should be pretty printed or not.

var json = statement.ToJson(true);
Console.WriteLine(json);

Communication with a LRS

An LRS Client is also implemented in the Mos.xApi.LrsClient namespace. It implements an interface called ILrsClient and uses asynchronous methods.

using Mos.xApi.LrsClient;
...

ILrsClient lrsClient = new LrsClient("http://www.example.com/mylrs");

Statement statement = await lrsClient.GetStatementAsync(new Guid("d0371e17-4e91-46ba-924f-e78168bf0f02"));

var statementResult = await lrsClient.FindStatement(new StatementQuery{ActivityId = new Uri("http://adlnet.gov/expapi/verbs/completed")});

var statements = statementResult.Statements;

if(statements.More != null){
    var moreStatementResult = await lrsClient.FindMoreStatements(statements.More);
}

await lrsClient.SendStatementAsync(newStatement);

Parsing Statements from json

A static method Statement.FromJson allows to deserialize a statement defined as a Json string.

string jsonStatement = "...";

var statement = Statement.FromJson(jsonStatement);

Contributing

Please send your pull requests to the master branch (ideally from a feature branch in your own fork).

You can add bugs or feature requests by creating a new item on the issues page.

Credits

This project uses the following open source components

  • .NETStandard 1.6
    • Microsoft.CodeAnalysis.FxCopAnalyzers (>= 1.1.0)
    • NETStandard.Library (>= 1.6.1)
    • Newtonsoft.Json (>= 9.0.1)
    • System.ComponentModel.Annotations (>= 4.1.0)
    • System.Reflection.TypeExtensions (>= 4.3.0)
    • System.Security.Cryptography.Algorithms (>= 4.3.0)
  • .NETStandard 1.6: 1.6.0.0

Owners

Xavier Hahn

Authors

MindOnSite, Xavier Hahn

Project URL

https://github.com/MindOnSite/FluentxApi/

License

MIT

Tags

xApi,LRS,e-learning,elearning

Info

1570 total downloads
69 downloads for version 0.4.0-beta-0013
Download (26.72 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
0.10.0 28.4 KB Tue, 05 Sep 2023 18:47:34 GMT 70
0.9.0 28.43 KB Wed, 03 Feb 2021 22:33:13 GMT 70
0.8.0 28.41 KB Fri, 27 Nov 2020 07:46:00 GMT 94
0.7.0 28.19 KB Wed, 25 Sep 2019 18:57:48 GMT 77
0.6.0 28.16 KB Fri, 17 Mar 2017 14:53:37 GMT 73
0.5.0-beta-0017 28.29 KB Fri, 17 Mar 2017 13:54:29 GMT 75
0.5.0-beta-0016 27.25 KB Tue, 21 Feb 2017 14:34:51 GMT 61
0.5.0-beta-0015 27.25 KB Tue, 21 Feb 2017 14:31:06 GMT 71
0.4.0-beta-0014 26.72 KB Tue, 14 Feb 2017 15:39:15 GMT 82
0.4.0-beta-0013 26.72 KB Tue, 14 Feb 2017 15:38:04 GMT 69
0.3.0-beta-0012 26.72 KB Tue, 14 Feb 2017 15:34:49 GMT 77
0.3.0-beta-0011 26.67 KB Fri, 10 Feb 2017 12:38:01 GMT 75
0.3.0-beta-0010 26.66 KB Fri, 10 Feb 2017 11:54:41 GMT 77
0.3.0-beta-0009 26.66 KB Fri, 10 Feb 2017 11:50:35 GMT 71
0.2.1-beta-0008 24.28 KB Tue, 07 Feb 2017 14:11:02 GMT 83
0.2.1-beta-0007 24.28 KB Tue, 07 Feb 2017 14:07:22 GMT 64
0.2.0-beta-0006 24.26 KB Tue, 07 Feb 2017 11:19:26 GMT 72
0.2.0-beta-0005 24.27 KB Tue, 07 Feb 2017 11:15:07 GMT 73
0.1.0-beta-0004 24.01 KB Tue, 31 Jan 2017 14:00:49 GMT 70
0.1.0-beta-0003 24 KB Tue, 31 Jan 2017 13:55:02 GMT 74
0.1.0-beta-0002 24 KB Tue, 31 Jan 2017 12:08:52 GMT 92