{"id":22446939,"url":"https://github.com/learnosity/learnosity-sdk-ruby","last_synced_at":"2025-08-01T21:32:20.169Z","repository":{"id":41002204,"uuid":"85268135","full_name":"Learnosity/learnosity-sdk-ruby","owner":"Learnosity","description":"Learnosity's Ruby SDK","archived":false,"fork":false,"pushed_at":"2024-11-05T04:19:52.000Z","size":513,"stargazers_count":2,"open_issues_count":3,"forks_count":3,"subscribers_count":40,"default_branch":"master","last_synced_at":"2024-12-01T11:50:39.348Z","etag":null,"topics":["learnosity","ruby","sdk"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Learnosity.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-17T03:43:40.000Z","updated_at":"2024-11-05T04:19:55.000Z","dependencies_parsed_at":"2024-07-12T15:12:03.489Z","dependency_job_id":"c6f52482-4efc-4e7e-9b04-d3b09646fa39","html_url":"https://github.com/Learnosity/learnosity-sdk-ruby","commit_stats":{"total_commits":70,"total_committers":12,"mean_commits":5.833333333333333,"dds":0.7428571428571429,"last_synced_commit":"27201cd4538e29ac35561689d46a242074a9bb48"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Learnosity%2Flearnosity-sdk-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Learnosity%2Flearnosity-sdk-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Learnosity%2Flearnosity-sdk-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Learnosity%2Flearnosity-sdk-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Learnosity","download_url":"https://codeload.github.com/Learnosity/learnosity-sdk-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228407877,"owners_count":17915083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["learnosity","ruby","sdk"],"created_at":"2024-12-06T04:13:06.580Z","updated_at":"2024-12-06T04:13:07.196Z","avatar_url":"https://github.com/Learnosity.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg width=\"50%\" height=\"50%\" src=\"docs/images/image-logo-graphic.png\" title=\"Learnosity logo, an open book with multicolored pages.\"\u003e\u003c/p\u003e\n\u003ch1 align=\"center\"\u003eLearnosity SDK - Ruby\u003c/h1\u003e\n\u003cp align=\"center\"\u003eEverything you need to start building your app in Learnosity, with the Ruby programming language.\u003cbr\u003e \n(Prefer another language? \u003ca href=\"https://help.learnosity.com/hc/en-us/sections/360000194318-Server-side-development-SDKs\"\u003eClick here\u003c/a\u003e)\u003cbr\u003e\nAn official Learnosity open-source project.\u003c/p\u003e\n\n[![Latest Stable Version](https://badge.fury.io/gh/Learnosity%2Flearnosity-sdk-ruby.svg)](https://rubygems.org/gems/learnosity-sdk)\n[![Build Status](https://app.travis-ci.com/Learnosity/learnosity-sdk-ruby.svg?branch=master)](https://app.travis-ci.com/Learnosity/learnosity-sdk-ruby)\n[![License](docs/images/apache-license.svg)](LICENSE.md)\n[![Downloads](docs/images/downloads.svg)](https://github.com/Learnosity/learnosity-sdk-ruby/releases)\n---\n\n## Table of Contents\n\n* [Overview: what does it do?](#overview-what-does-it-do)\n* [Requirements](#requirements)\n* [Installation](#installation)\n* [Quick start guide](#quick-start-guide)\n* [Next steps: additional documentation](#next-steps-additional-documentation)\n* [Contributing to this project](#contributing-to-this-project)\n* [License](#license)\n* [Usage tracking](#usage-tracking)\n* [Further reading](#further-reading)\n\n## Overview: what does it do?\nThe Learnosity Ruby SDK makes it simple to interact with Learnosity APIs.\n\n![image-concept-overview.png](docs/images/image-concept-overview.png \"Conceptual overview, showing your app, connecting to the Learnosity SDK, then the Learnosity Items API.\")\n\nIt provides a number of convenience features for developers, that make it simple to do the following essential tasks:\n\n* Creating signed security requests for API initialization, and\n* Interacting with the Data API.\n\nFor example, the SDK helps with creating a signed request for Learnosity:\n\n![image-signed-request-creation.png](docs/images/image-signed-request-creation.png \"Diagram showing the flow of information from your app, sending key, secret and parameters to the Learnosity SDK, then the Learnosity SDK sending back a fully formed request.\")\n\nOnce the SDK has created the signed request for you, your app sends that on to an API in the Learnosity cloud, which then retrieves the assessment you are asking for, as seen in the diagram below:\n\n![image-assessment-retrieval.png](docs/images/image-assessment-retrieval.png \"Diagram showing your app sending the fully formed request to the Learnosity cloud, then the cloud retrieving your assessment, which is then rendered in the student's browser.\")\n\nThis scenario is what you can see running in the quick start guide example ([see below](#quick-start-guide)).\n\nThere's more features, besides. See the detailed list of SDK features on the [reference page](REFERENCE.md).\n\n[(Back to top)](#table-of-contents)\n\n## Requirements\n\n1. Runtime libraries for Ruby installed. ([instructions](https://www.ruby-lang.org/en/downloads/branches/))\n\n2. The [RubyGems](https://rubygems.org/) package manager installed. You use this to access the Learnosity Ruby SDK on [RubyGems](https://rubygems.org/gems/learnosity-sdk).\n\nNot using Ruby? See the [SDKs for other languages](https://help.learnosity.com/hc/en-us/sections/360000194318-Server-side-development-SDKs).\n\n### Supported Ruby Versions\nThe Ruby SDK supports the “normal maintenance” and “security maintenance” versions listed on the [Ruby home page](https://www.ruby-lang.org/en/downloads/branches/). Please contact our support team if you are having trouble with a specific version.\n\n[(Back to top)](#table-of-contents)\n\n## Installation\n### **Installation via RubyGems**\nUsing RubyGems is the recommended way to install the Learnosity SDK for Ruby in production. The easiest way is to run this from your project folder:\n\n``` bash\n    gem install learnosity_sdk\n```\n\n### **Alternative method 1: download the zip file**\nDownload the latest version of the SDK as a self-contained ZIP file from the [GitHub Releases](https://github.com/Learnosity/learnosity-sdk-ruby/releases) page. The distribution ZIP file contains all the necessary dependencies. \n\nNote: after installation, run this command in (docs/quickstart/lrn-sdk-rails/):\n\n``` bash\n    bundle install\n```\n\n### **Alternative 2: development install from a git clone**\nTo install from the terminal, run this command:\n\n``` bash\n    git clone git@github.com:Learnosity/learnosity-sdk-Ruby.git\n```\n\nNote: after installation, run this command in (docs/quickstart/lrn-sdk-rails/):\n\n``` bash\n    bundle install\n```\n\nNote that these manual installation methods are for development and testing only.\nFor production use, you should install the SDK using the RubyGems package manager for Ruby, as described above.\n\n[(Back to top)](#table-of-contents)\n\n## Quick start guide\nLet's take a look at a simple example of the SDK in action. In this example, we'll load an assessment into the browser.\n\n### **Start up your web server and view the standalone assessment example**\nTo start up your Ruby web server, first find the following folder location under the SDK. Change directory ('cd') to this location on the command line.\n\n``` bash\n    cd docs/quickstart/lrn-sdk-rails/\n```\n\nTo start, run this command from that folder:\n\n``` bash\n    rails server\n```\n\nFrom this point on, we'll assume that your web server is available at this local address (it will report the port being used when you launch it, by default it's port 3000): \n\nhttp://localhost:3000\n\nYou can now access the APIs using the following URL [click here](http://localhost:3000)\n\n\u003cimg width=\"50%\" height=\"50%\" src=\"docs/images/image-quickstart-index.png\"\u003e\n\nFollowing are the routes to access our APIs.\n\n* Author API : http://localhost:3000/author/index\n* Questions API : http://localhost:3000/questions/index\n* Items API : http://localhost:3000/items/index\n* Reports API : http://localhost:3000/reports/index\n\nOpen these pages with your web browser. These are all basic examples of Learnosity's integration. You can interact with these demo pages to try out the various APIs. The Items API example is a basic example of an assessment loaded into a web page with Learnosity's assessment player. You can interact with this demo assessment to try out the various Question types.\n\n\u003cimg width=\"50%\" height=\"50%\" src=\"docs/images/image-quickstart-examples-assessment.png\"\u003e\n\n[(Back to top)](#table-of-contents)\n\n### **How it works**\nLet's walk through the code for this standalone assessment example. The source files are included under the `docs/quickstart/lrn-sdk-rails/` folder.\n\nLet's consider the Items API code. The first section is a controller file in Ruby, [items_controller.rb](docs/quickstart/lrn-sdk-rails/app/controllers/items_controller.rb) from `docs/quickstart/lrn-sdk-rails/app/controllers/` and it is executed server-side. It constructs a set of configuration options for Items API, and securely signs them using the consumer key. We also add a few lines to [application.rb](docs/quickstart/lrn-sdk-rails/config/application.rb) for our Learnosity credentials. The second section is HTML and JavaScript in an [ERB](https://docs.ruby-lang.org/en/2.3.0/ERB.html) template [index.html.erb](docs/quickstart/lrn-sdk-rails/app/views/items/index.html.erb) and is executed client-side, once the page is loaded in the browser. It renders and runs the assessment functionality.\n\n[(Back to top)](#table-of-contents)\n\n### **Server-side code**\nWe start by including some LearnositySDK helpers in [items_controller.rb](docs/quickstart/lrn-sdk-rails/app/controllers/items_controller.rb) - they'll make it easy to generate and sign the config options, and unique user and session IDs.\n\n``` ruby\nrequire 'learnosity/sdk/request/init' # Learnosity helper.\nrequire 'securerandom'                # Library for generating UUIDs.\n```\n\nNow we'll declare the configuration options for Items API. The following options specify which assessment content should be rendered, how it should be displayed, which user is taking this assessment and how their responses should be stored. \n\n``` ruby\nclass IndexController \u003c ApplicationController\n    @@items_request = {\n        \"user_id\" =\u003e SecureRandom.uuid,\n        \"activity_template_id\" =\u003e \"quickstart_examples_activity_template_001\",\n        \"session_id\" =\u003e SecureRandom.uuid,\n        \"activity_id\" =\u003e \"quickstart_examples_activity_001\",\n        \"rendering_type\" =\u003e \"assess\",\n        \"type\" =\u003e \"submit_practice\",\n        \"name\" =\u003e \"Items API Quickstart\",\n        \"state\" =\u003e \"initial\"\n  }\n```\n\n* `user_id`: unique student identifier. Note: we never send or save student's names or other personally identifiable information in these requests. The unique identifier should be used to look up the entry in a database of students accessible within your system only. [Learn more](https://help.learnosity.com/hc/en-us/articles/360002309578-Student-Privacy-and-Personally-Identifiable-Information-PII-).\n* `activity_template_id`: reference of the Activity to retrieve from the Item bank. The Activity defines which Items will be served in this assessment.\n* `session_id`: uniquely identifies this specific assessment attempt for save/resume, data retrieval and reporting purposes. Here, we're using the `Uuid` helper to auto-generate a unique session id.\n* `activity_id`: a string you define, used solely for analytics to allow you run reporting and compare results of users submitting the same assessment.\n* `rendering_type`: selects a rendering mode, `assess` mode is a \"standalone\" mode (loading a complete assessment player for navigation, as opposed to `inline` for embedding without).\n* `type`: selects the context for the student response storage. `submit_practice` mode means the student responses will be stored in the Learnosity cloud, allowing for grading and review.\n* `name`: human-friendly display name to be shown in reporting, via Reports API and Data API.\n* `state`: Optional. Can be set to `initial`, `resume` or `review`. `initial` is the default.\n\n**Note**: you can submit the configuration options either as an array as shown above, or a JSON string.\n\nNext, we declare the Learnosity consumer credentials we'll use to authorize this request. \n\nWe'll now open the file [application.rb](docs/quickstart/lrn-sdk-rails/config/application.rb), under `docs/quickstart/lrn-sdk-rails/config/` to set our Learnosity login credentials. Notice the two values *config.consumer_key* and *config.consumer_secret*.\n\n``` ruby\nrequire 'rails/all'\n# Require the gems listed in Gemfile, including any gems\n# you've limited to :test, :development, or :production.\nBundler.require(*Rails.groups)\n\nmodule LrnSdkRails\n  class Application \u003c Rails::Application\n    # Settings in config/environments/* take precedence over those specified here.\n    # Application configuration should go into files in config/initializers\n    # -- all .rb files in that directory are automatically loaded.\n\n    # The consumerKey and consumerSecret are the public \u0026 private\n    # security keys required to access Learnosity APIs and\n    # data. Learnosity will provide keys for your own private account.\n    # Note: The consumer secret should be in a properly secured credential store, \n    # and *NEVER* checked into version control. \n    # The keys listed here grant access to Learnosity's public demos account.\n    config.consumer_key = 'yis0TYCu7U9V4o7M'\n    config.consumer_secret = '74c5fd430cf1242a527f6223aebd42d30464be22'\n  end\nend\n```\n\nThe consumer key and consumer secret in this example are for Learnosity's public \"demos\" account. Once Learnosity provides your own consumer credentials, your Item bank and assessment data will be tied to your own consumer key and secret.\n\u003ci\u003e(of course, you should never normally put passwords into version control)\u003c/i\u003e\n\nNow, back in [index_controller.rb](docs/quickstart/lrn-sdk-rails/app/controllers/index_controller.rb), we reference the key and secret, and also construct security settings that ensure the report is initialized on the intended domain. The value provided to the domain property must match the domain from which the file is actually served.\n\n``` ruby\n    @@security_packet = {\n        # XXX: This is a Learnosity Demos consumer; replace it with your own consumer key\n        'consumer_key'   =\u003e Rails.configuration.consumer_key,\n        'domain'         =\u003e 'localhost'\n    }\n    # XXX: The consumer secret should be in a properly secured credential store, and *NEVER* checked into version control\n    @@consumer_secret = Rails.configuration.consumer_secret\n```\n\nNow we call LearnositySDK's `Init()` helper to construct our Items API configuration parameters, and sign them securely with the `security_packet`, `consumerSecret` and `items_request` parameters. \n\n``` ruby\n  def index\n    @init = Learnosity::Sdk::Request::Init.new(\n      'items',\n      @@security_packet,\n      @@consumer_secret,\n      @@items_request\n    )\n  end\n```\n\n[(Back to top)](#table-of-contents)\n\n### **Web page content**\nWe've got our set of signed configuration parameters, so now we can set up our page content for output. The page can be as simple or as complex as needed, using your own HTML and JavaScript to render the desired product experience.\n\nThis example uses plain HTML in an ERB template, served by Rails. \n\n``` html\n\u003ch1\u003eStandalone Assessment Example\u003c/h1\u003e\n\u003cdiv id=\"learnosity_assess\"\u003e\u003c/div\u003e\n\u003cscript src=\"https://items.learnosity.com/?latest-lts\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  var eventOptions = {\n    readyListener: init\n  },\n    itemsApp = LearnosityItems.init(\u003c%= raw @init.generate %\u003e);\n  function init () {\n    var assessApp = itemsApp.assessApp();\n    assessApp.on('item:load', function () {\n      console.log('Active item:', getActiveItem(this.getItems()));\n    });\n    assessApp.on('test:submit:success', function () {\n      toggleModalClass();\n    });\n  }\n\u003c/script\u003e\n```\n\nThe important parts to be aware of in this HTML are:\n\n* A div with `id=\"learnosity_assess\"`. This is where the Learnosity assessment player will be rendered to deliver the assessment.\n* The `\u003cscript src=\"https://items.learnosity.com/?latest-lts\"\u003e\u003c/script\u003e` tag, which includes Learnosity's Items API on the page and makes the global `LearnosityItems` object available. The version specified as `latest-lts` will retrieve the latest version supported. To know more about switching to a specific LTS version, visit our [Long Term Support (LTS) page](https://help.learnosity.com/hc/en-us/articles/360001268538-Release-Cadence-and-Version-Lifecycle). In production, you should always pin to a specific LTS version to ensure version compatibility.\n* The call to `LearnosityItems.init()`, which initiates Items API to inject the assessment player into the page.\n* The variable `\u003c%= raw @init.generate %\u003e` dynamically sends the contents of our init options to JavaScript, so it can be passed to `init()`.\n\nThe call to `init()` returns an instance of the ItemsApp, which we can use to programmatically drive the assessment using its methods. We pull in our Learnosity configuration in a variable `\u003c%= raw @init.generate %\u003e`, that the ERB template will import from the Ruby controller file.\n\nThis marks the end of the quick start guide. From here, try modifying the example files yourself, you are welcome to use this code as a basis for your own projects.\n\nTake a look at some more in-depth options and tutorials on using Learnosity assessment functionality below.\n\n[(Back to top)](#table-of-contents)\n\n## Next steps: additional documentation\n\n### **SDK reference**\nSee a more detailed breakdown of all the SDK features, and examples of how to use more advanced or specialised features on the [SDK reference page](REFERENCE.md).\n\n### **Additional quick start guides**\nThere are more quick start guides, going beyond the initial quick start topic of loading an assessment, these further tutorials show how to set up authoring and analytics:\n\n* [Authoring Items quick start guide](https://help.learnosity.com/hc/en-us/articles/360000754958-Getting-Started-With-the-Author-API) (Author API) - create and edit new Questions and Items for your Item bank, then group your assessment Items into Activities, and\n* [Analytics / student reporting quick start guide](https://help.learnosity.com/hc/en-us/articles/360000755838-Getting-Started-With-the-Reports-API) (Reports API) - view the results and scores from an assessment Activity. \n\n### **Learnosity demos repository**\nOn our [demo site](https://demos.learnosity.com/), browse through many examples of Learnosity API integration. You can also download the entire demo site source code, the code for any single demo, or browse the codebase directly on GitHub.\n\n### **Learnosity reference documentation**\nSee full documentation for Learnosity API init options, methods and events in the [Learnosity reference site](https://reference.learnosity.com/).\n\n### **Technical use-cases documentation**\nFind guidance on how to select a development pattern and arrange the architecture of your application with Learnosity, in the [Technical Use-Cases Overview](https://help.learnosity.com/hc/en-us/articles/360000757777-Technical-Use-Cases-Overview).\n\n### **Deciding what to build or integrate**\nGet help deciding what application functionality to build yourself, or integrate off-the-shelf with the [Learnosity \"Golden Path\" documentation](https://help.learnosity.com/hc/en-us/articles/360000754578-Recommended-Deployment-Patterns-Golden-Path-).\n\n### **Key Learnosity concepts**\nWant more general information about how apps on Learnosity actually work? Take a look at our [Key Learnosity Concepts page](https://help.learnosity.com/hc/en-us/articles/360000754638-Key-Learnosity-Concepts).\n\n### **Glossary**\nNeed an explanation for the unique Learnosity meanings for Item, Activity and Item bank? See our [Glossary of Learnosity-specific terms](https://help.learnosity.com/hc/en-us/articles/360000754838-Glossary-of-Learnosity-and-Industry-Terms).\n\n[(Back to top)](#table-of-contents)\n\n## Contributing to this project\n\n### Adding new features or fixing bugs\nContributions are welcome. See the [contributing instructions](CONTRIBUTING.md) page for more information. You can also get in touch via our support team.\n\n[(Back to top)](#table-of-contents)\n\n## License\nThe Learnosity Ruby SDK is licensed under an Apache 2.0 license. [Read more](LICENSE.md).\n\n[(Back to top)](#table-of-contents)\n\n## Usage tracking\nOur SDKs include code to track the following information by adding it to the request being signed:\n\n- SDK version\n- SDK language\n- SDK language version\n- Host platform (OS)\n- Platform version\n\nWe use this data to enable better support and feature planning.\n\n[(Back to top)](#table-of-contents)\n\n## Further reading\nThanks for reading to the end! Find more information about developing an app with Learnosity on our documentation sites: \n\n* [help.learnosity.com](http://help.learnosity.com/hc/en-us) -- general help portal and tutorials,\n* [reference.learnosity.com](http://reference.learnosity.com) -- developer reference site, and\n* [authorguide.learnosity.com](http://authorguide.learnosity.com) -- authoring documentation for content creators.\n\n[(Back to top)](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearnosity%2Flearnosity-sdk-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flearnosity%2Flearnosity-sdk-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearnosity%2Flearnosity-sdk-ruby/lists"}