Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ gem "webpacker"
# Application secrets checker
gem "nuclear_secrets"

# Caliper
gem "rest-client"
gem "uuid"
git "https://github.com/IMSGlobal/caliper-ruby.git", branch: "develop" do
gem "ims_caliper"
end

# This is only here because we are on ruby 2.4. When we upgrade ruby we can remove this
gem "sprockets", "~>3.7.2"

Expand Down
31 changes: 30 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: https://github.com/IMSGlobal/caliper-ruby.git
revision: 16256300ecdf13bd2438ffc166b1a93f240b9839
branch: develop
specs:
ims_caliper (1.1)

GIT
remote: https://github.com/alexpeattie/heroku_secrets.git
revision: 717af8e0acf399bc88d2c8c1a7e230023942af0f
Expand Down Expand Up @@ -122,6 +129,8 @@ GEM
actionmailer (>= 5.0)
devise (>= 4.6)
diff-lcs (1.4.4)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.6)
dotenv-rails (2.7.6)
dotenv (= 2.7.6)
Expand Down Expand Up @@ -169,6 +178,9 @@ GEM
rspec (>= 2.99.0, < 4.0)
hashdiff (1.0.1)
hashie (4.1.0)
http-accept (1.7.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
httparty (0.18.1)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
Expand Down Expand Up @@ -203,6 +215,8 @@ GEM
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.2.7)
macaddr (1.7.2)
systemu (~> 2.6.5)
mail (2.7.1)
mini_mime (>= 0.1.1)
mail_view (2.0.4)
Expand All @@ -222,6 +236,7 @@ GEM
multi_xml (0.6.0)
multipart-post (2.1.1)
nenv (0.3.0)
netrc (0.11.0)
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
Expand Down Expand Up @@ -322,6 +337,11 @@ GEM
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.4)
rolify (5.3.0)
rollbar (2.27.0)
Expand Down Expand Up @@ -404,6 +424,7 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
strong_password (0.0.9)
systemu (2.6.5)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thor (1.0.1)
Expand All @@ -413,7 +434,12 @@ GEM
thread_safe (~> 0.1)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
unicode-display_width (1.7.0)
uuid (2.3.9)
macaddr (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (3.7.0)
Expand Down Expand Up @@ -468,6 +494,7 @@ DEPENDENCIES
httparty
hub
ims-lti (~> 2.1.5)
ims_caliper!
json-jwt
jwt
launchy
Expand Down Expand Up @@ -495,6 +522,7 @@ DEPENDENCIES
rb-fchange
rb-fsevent
rb-inotify
rest-client
rolify
rollbar
rspec-rails
Expand All @@ -513,11 +541,12 @@ DEPENDENCIES
strong_password
tzinfo-data
uglifier
uuid
web-console (~> 3.7.0)
webmock
webpacker
will_paginate
yajl-ruby

BUNDLED WITH
1.17.3
2.1.4
16 changes: 16 additions & 0 deletions app/controllers/lti_launches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown

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.

requestor = Caliper::Request::HttpRequestor.new({
'host' => "http://learncaliper.herokuapp.com/api/consumer/events/1ebb1f70-5e82-0137-e4ac-4a8f9eeae0c8",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

'auth_token' => "1ebb1f70-5e82-0137-e4ac-4a8f9eeae0c8",
Copy link
Copy Markdown

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.

})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
48 changes: 48 additions & 0 deletions app/lib/kaliper/events.rb
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}",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
49 changes: 49 additions & 0 deletions app/lib/kaliper/lti_utils.rb
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?
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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]}",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
3 changes: 3 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/Syntax: unexpected token tCOMMA

},
course_navigation: {
text: "LTI Starter App",
Expand Down