-
Notifications
You must be signed in to change notification settings - Fork 8
WIP: Adding Caliper support #296
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ class LtiLaunchesController < ApplicationController | |
|
|
||
| skip_before_action :verify_authenticity_token | ||
| before_action :do_lti, except: [:init, :launch] | ||
| after_action :do_caliper | ||
|
|
||
| def index | ||
| if current_application_instance.disabled_at | ||
|
|
@@ -60,4 +61,19 @@ def setup_lti_response | |
| set_lti_launch_values | ||
| end | ||
|
|
||
| def do_caliper | ||
| events = Kaliper::LtiUtils.from_lti_1_2( | ||
| application_instance: current_application_instance, | ||
| user: current_user, | ||
| params: params, | ||
| ) | ||
| options = Caliper::Options.new | ||
| sensor = Caliper::Sensor.new('https://www.atomicjolt.com/sensors/1', options) | ||
| requestor = Caliper::Request::HttpRequestor.new({ | ||
| 'host' => "http://learncaliper.herokuapp.com/api/consumer/events/1ebb1f70-5e82-0137-e4ac-4a8f9eeae0c8", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis. |
||
| 'auth_token' => "1ebb1f70-5e82-0137-e4ac-4a8f9eeae0c8", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/IndentHash: Indent the right brace the same as the first position after the preceding left parenthesis. |
||
| requestor.send(sensor, events.tool_use_event) | ||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| require "caliper" | ||
|
|
||
| module Kaliper | ||
| class Events | ||
|
|
||
| attr_accessor :actor | ||
| attr_accessor :ed_app | ||
| attr_accessor :group | ||
| attr_accessor :membership | ||
| attr_accessor :session | ||
|
|
||
| def initialize(application_instance:, user:) | ||
| @application_instance = application_instance | ||
| @user = user | ||
|
|
||
| @actor = Caliper::Entities::Agent::Person.new( | ||
| id: "#{@application_instance.domain}/users/#{@user.id}", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably need to generate a different user id and include the sis id in the actor |
||
| name: @user.display_name, | ||
| ) | ||
|
|
||
| @ed_app = Caliper::Entities::Agent::SoftwareApplication.new( | ||
| id: @application_instance.domain, | ||
| name: @application_instance.application.name, | ||
| description: @application_instance.application.description, | ||
| ) | ||
| end | ||
|
|
||
| # tool use Event docs: https://www.imsglobal.org/sites/default/files/caliper/v1p1/caliper-spec-v1p1/caliper-spec-v1p1.html#toolUseEvent | ||
| def tool_use_event(event_time: Time.now.utc.iso8601) | ||
| event = Caliper::Events::ToolUseEvent.new( | ||
| id: "urn:uuid:#{SecureRandom.uuid}", | ||
| object: @ed_app, | ||
| actor: @actor, | ||
| action: Caliper::Actions::USED, | ||
| edApp: @ed_app, | ||
| eventTime: event_time | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/TrailingCommaInArguments: Put a comma after the last parameter of a multiline method call. |
||
| ) | ||
|
|
||
| event.group = @group if @group | ||
| event.membership = @membership if @membership | ||
| event.session = @session if @session | ||
| event.federated_session = @federated_session if @federated_session | ||
|
|
||
| event | ||
| end | ||
|
|
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| require "caliper" | ||
|
|
||
| module Kaliper | ||
| class LtiUtils | ||
|
|
||
| def self.from_lti_1_2(application_instance:, user:, params:) | ||
| event = Kaliper::Events.new(application_instance: application_instance, user: user) | ||
|
|
||
| if params[:customer_caliper_federated_session_id].present? | ||
| # https://www.imsglobal.org/sites/default/files/caliper/v1p1/caliper-spec-v1p1/caliper-spec-v1p1.html#ltiSession | ||
| event.federatedSession = Caliper::Entities::Session::LtiSession.new( | ||
| id: params[:customer_caliper_federated_session_id], | ||
| user: event.actor, | ||
| ) | ||
| end | ||
|
|
||
| #return from_canvas_lti(event, params) if params[:custom_canvas_api_domain].present? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/LeadingCommentSpace: Missing space after #. |
||
| event | ||
| end | ||
|
|
||
| # TODO | ||
| # def self.from_canvas_lti(event, params) | ||
|
|
||
| # event.group = Caliper::Entities::LIS::CourseSection.new( | ||
| # id: "https://#{params[:custom_canvas_api_domain]}/courses/#{params[:custom_canvas_course_id]}/sections/#{params[:custom_canvas_section_id]}", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [151/120] |
||
| # courseNumber: params[:context_title], | ||
| # academicSession: params[:canvas_term_start_at], | ||
| # ) | ||
|
|
||
| # event.membership = Caliper::Entities::LIS::Membership.new( | ||
| # id: membership_id, | ||
| # member: event.actor, | ||
| # organization: event.group, | ||
| # roles: caliper_role_from(params), | ||
| # status: Caliper::Entities::LIS::Status::ACTIVE, | ||
| # ) | ||
|
|
||
| # event.session = Caliper::Entities::Session::Session.new( | ||
| # id: id, | ||
| # startedAtTime: started_at.utc.iso8601, | ||
| # ) | ||
| # end | ||
|
|
||
| # def self.caliper_role_from(params) | ||
| # roles = [ Caliper::Entities::LIS::Role::LEARNER ] | ||
| # end | ||
|
|
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,9 @@ | |
| canvas_course_id: "$Canvas.course.id", | ||
| canvas_api_domain: "$Canvas.api.domain", | ||
| canvas_user_id: "$Canvas.user.id", | ||
| customer_caliper_endpoint_url: "$Caliper.url", | ||
| canvas_course_section_ids: "$Canvas.course.sectionIds", | ||
| canvas_term_start_at: "$Canvas.term.startAt",, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/Syntax: unexpected token tCOMMA |
||
| }, | ||
| course_navigation: { | ||
| text: "LTI Starter App", | ||
|
|
||
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.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.