LearnositySDK 0.8.0
See the version list below for details.
dotnet add package LearnositySDK --version 0.8.0
NuGet\Install-Package LearnositySDK -Version 0.8.0
<PackageReference Include="LearnositySDK" Version="0.8.0" />
paket add LearnositySDK --version 0.8.0
#r "nuget: LearnositySDK, 0.8.0"
// Install LearnositySDK as a Cake Addin #addin nuget:?package=LearnositySDK&version=0.8.0 // Install LearnositySDK as a Cake Tool #tool nuget:?package=LearnositySDK&version=0.8.0
Learnosity SDK - ASP.NET / C#
This repository contains full .NET solution.
LearnositySDK library helps you to generate request JSON for following services:
- assess
- author
- data
- items
- questions
- reports
- schemas
In addition data and schemas services use Request/Remote
class to perform HTTP Request, and fetch needed data. Data service can also use Request/DataApi
wrapper making pagination requests easier.
Contents
Solution consists in two projects:
- LearnositySDK
- LearnositySDKUnitTests
LearnositySDK
This project is a class library built in compatibility with .NET Standard 2.0
This project uses only one external dependency: Newtonsoft.Json library (http://james.newtonking.com/json)
Installation
To install Learnosity SDK .NET NuGet package, run the following command in the Package Manager Console
PM> Install-Package LearnositySDK
Usage
Init class
The Request/Init
class is used to generate the necessary security and request data (in the correct format) to integrate with any of the Learnosity API services.
The Init constructor takes up to 5 arguments:
- [string] service type
- [string/JsonObject] security details (no secret)
- [string] secret
- [string/JsonObject] request details (optional)
- [string] action (optional)
// prepare all the params
string service = "items";
JsonObject security = new JsonObject();
security.set("consumer_key", "yis0TYCu7U9V4o7M");
security.set("domain", "localhost");
security.set("user_id", "12345678");
string secret = "74c5fd430cf1242a527f6223aebd42d30464be22";
JsonObject request = new JsonObject();
request.set("activity_template_id", "demo-activity-1");
request.set("activity_id", "my-demo-activity");
request.set("name", "Demo Activity");
request.set("course_id", "demo_yis0TYCu7U9V4o7M");
request.set("session_id", Uuid.generate());
request.set("user_id", "demo_student");
// Instantiate Init class
Init init = new Init(service, security, secret, request);
// Call the generate() method to retrieve a JavaScript object
string JavaScriptObject = init.generate();
On JavaScript side:
// Pass the object to the initialisation of any Learnosity API
LearnosityApp.init(JavaScriptObject);
Arguments
service<br> A string representing the Learnosity service (API) you want to integrate with. Valid options are:
- assess
- author
- data
- items
- questions
- reports
security<br> An associative array^ that includes your consumer_key but does not include your secret. The SDK sets defaults for you, but valid options are:
- consumer_key
- domain (optional)
- timestamp (optional)
- user_id (optional)
^Note – the SDK accepts JSON strings or JsonObject objects.
secret<br> Your secret key, as provided by Learnosity.
request<br> An optional associative array^ of data relevant to the API being used. This will be any data minus the security details that you would normally use to initialise an API.
^Note – the SDK accepts JSON strings or JsonObject objects.
action<br> An optional string used only if integrating with the Data API. Valid options are:
- get
- set
- update
- delete
<hr>
Remote class
The Remote class is used to make server side, cross domain requests. Think of it as a HTTPWebRequest or WebClient wrapper.
You'll call either get() or post() with the following arguments:
- [string] URL
- [string/Dictionary<string, string>] Data payload
- [JsonObject] Options
string url = "http://schemas.learnosity.com/stable/questions/templates";
Remote remote = new Remote();
remote.get(url);
string body = remote.getBody();
Arguments
URL<br> A string URL, including schema and path. Eg:
https://schemas.learnosity.com/stable/questions/templates
Data<br> An optional associative array^ of data to be sent as a payload. For GET it will be a URL encoded query string.
^Note – the SDK accepts query strings or Dictionary<string, string> objects.
Options<br> An optional associative array^ of request parameters. Valid options are: int timeout (seconds), JsonObject headers, string encoding
^Note – the SDK accepts JsonObject objects.
Remote methods
The following methods are available after making a get()
or post()
.
getBody()<br> Returns the body of the response payload.
getError()<br> Returns an array that includes the error code and message (if an error was thrown)
getHeader()<br> Currently only returns the content_type header of the response.
getSize()<br> Returns the size of the response payload in bytes.
getStatusCode()<br> Returns the HTTP status code of the response.
DataApi class
This class serves as a wrapper for data API calls. It has two public methods:
request()<br>
Allows you to perform single request. For now data API calls are limited to 1000 records, which means, that subsequent calls can be required.
You can pass data.meta.next
token in your requestPacket to load next set of records. See also requestRecursive
method.
Check Examples.Data.DataApi()
for an example.
requestRecursive()<br>
Allows you to perform subsequent requests recursively, returning the chunk of data after each recursion.
Chunks are passed into callback function defined by following delegate:
public delegate bool ProcessData(string data);
Check Examples.Data.DataApiRecursive()
for an example.
JsonObject class
Serves as an simple implementation of PHP associative arrays. It provides many overloaded get()
and set()
methods to allow you create your flexible objects.
Constructor accepts only one parameter: bool isArray = false
. It's required to set this flag to true
if your object should behave like an array.
Example with both - objects and arrays:
JsonObject session_ids = new JsonObject(true);
session_ids.set("AC023456-2C73-44DC-82DA28894FCBC3BF");
JsonObject report = new JsonObject();
report.set("id", "report-1");
report.set("type", "sessions-summary");
report.set("user_id", "brianmoser");
report.set("session_ids", session_ids);
JsonObject reports = new JsonObject(true);
reports.set(report);
JsonObject request = new JsonObject();
request.set("reports", reports);
JsonObjectFactory class
If you already have your data in JSON string, simply run fromString()
method, to convert it to JsonObject instance:
string json = "[\"a\", \"b\"]";
JsonObject jo = JsonObjectFactory.fromString(json);
Version
Version v0.1.0 - June 2014
Examples
Each service has it's own example - you can find them in Examples
folder of LearnositySDK project. To run them simply invoke static Simple
method.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 10.0.3)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on LearnositySDK:
Package | Downloads |
---|---|
SM.Strongmind.Learnosity
Package Description |
|
LearnosityDotNetHelper
A library to assist .NET developers when working with the Learnosity APIs. |
|
LearnosityFunctions.Services
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Update to .Net Standard