Skip to content

Commit

Permalink
Merge pull request #159 from instructure/add-submitted-at
Browse files Browse the repository at this point in the history
Add support for "submittedAt" property
  • Loading branch information
westonkd authored Feb 3, 2020
2 parents 83959e2 + 6301fd1 commit c657c98
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 19 deletions.
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
language: ruby
before_install:
- gem install bundler
- gem install bundler -v '~> 1.14'
rvm:
- "1.9.3"
- "2.0.0"
branches:
only:
- master
- 2.0.x
- 1.2.x
- 2.3
script: bundle exec rspec spec
29 changes: 23 additions & 6 deletions lib/ims/lti/extensions/outcome_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def accepts_outcome_url?
accepted_outcome_types.member?("url")
end

# check if the consumer accepts a submitted at date as outcome data
def accepts_submitted_at?
accepted_outcome_types.member?("submitted_at")
end

def accepts_outcome_lti_launch_url?
accepted_outcome_types.member?("lti_launch_url")
end
Expand All @@ -76,7 +81,7 @@ def accepts_outcome_result_total_score?
end

# POSTs the given score to the Tool Consumer with a replaceResult and
# adds the specified data. The data hash can have the keys "text", "cdata_text", "url", or "lti_launch_url"
# adds the specified data. The data hash can have the keys "text", "cdata_text", "url", "submitted_at" or "lti_launch_url"
#
# If both cdata_text and text are sent, cdata_text will be used
#
Expand All @@ -93,7 +98,7 @@ def post_replace_result_with_data!(score = nil, data={})

# POSTs the given score to the Tool Consumer with a replaceResult and
# adds the specified data. The options hash can have the keys
# :text, :cdata_text, :url, :lti_launch_url, :score, or :total_score
# :text, :cdata_text, :url, :submitted_at, :lti_launch_url, :score, or :total_score
#
# If both cdata_text and text are sent, cdata_text will be used
# If both total_score and score are sent, total_score will be used
Expand All @@ -110,6 +115,7 @@ def post_extended_replace_result!(options = {})
req.outcome_cdata_text = opts[:cdata_text]
req.outcome_text = opts[:text]
req.outcome_url = opts[:url]
req.submitted_at = opts[:submitted_at]
req.outcome_lti_launch_url = opts[:lti_launch_url]
req.total_score = opts[:total_score]
req.post_replace_result!(opts[:score])
Expand All @@ -120,9 +126,9 @@ module ToolConsumer
include IMS::LTI::Extensions::ExtensionBase
include Base

OUTCOME_DATA_TYPES = %w{text url lti_launch_url}
OUTCOME_DATA_TYPES = %w{text url lti_launch_url submitted_at}

# a list of the outcome data types accepted, currently only 'url' and
# a list of the outcome data types accepted, currently only 'url', 'submitted_at' and
# 'text' are valid
#
# tc.outcome_data_values_accepted(['url', 'text'])
Expand Down Expand Up @@ -150,7 +156,7 @@ module OutcomeRequest
include IMS::LTI::Extensions::ExtensionBase
include Base

attr_accessor :outcome_text, :outcome_url, :outcome_lti_launch_url, :outcome_cdata_text, :total_score
attr_accessor :outcome_text, :outcome_url, :submitted_at, :outcome_lti_launch_url, :outcome_cdata_text, :total_score

def result_values(node)
super
Expand Down Expand Up @@ -178,6 +184,13 @@ def result_values(node)
end
end

def details(node)
super
return unless has_details_data?

node.submittedAt submitted_at
end

def score
total_score ? nil : @score
end
Expand All @@ -186,6 +199,10 @@ def has_result_data?
!!outcome_text || !!outcome_url || !!outcome_lti_launch_url || !!outcome_cdata_text || !!total_score || super
end

def has_details_data?
!!submitted_at
end

def extention_process_xml(doc)
super
@outcome_text = doc.get_text("//resultRecord/result/resultData/text")
Expand All @@ -196,4 +213,4 @@ def extention_process_xml(doc)

end
end
end
end
15 changes: 15 additions & 0 deletions lib/ims/lti/outcome_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def generate_request_xml
end
results(record)
end
submission_details(request)
end
end
end
Expand All @@ -182,6 +183,10 @@ def has_result_data?
!!score
end

def has_details_data?
false
end

def results(node)
return unless has_result_data?

Expand All @@ -190,6 +195,16 @@ def results(node)
end
end

def submission_details(request)
return unless has_details_data?
request.submissionDetails do |record|
details(record)
end
end

def details(record)
end

def result_values(node)
if score
node.resultScore do |res_score|
Expand Down
4 changes: 2 additions & 2 deletions lib/ims/lti/tool_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def new_request
:consumer_secret => @consumer_secret,
:lis_outcome_service_url => lis_outcome_service_url,
:lis_result_sourcedid =>lis_result_sourcedid)

extend_outcome_request(@outcome_requests.last)
end

end
end
12 changes: 10 additions & 2 deletions spec/extensions/outcome_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
@tp.accepts_outcome_data?.should == true
@tp.accepts_outcome_text?.should == true
@tp.accepts_outcome_url?.should == false
@tp.accepts_submitted_at?.should == false
@tp.accepts_outcome_lti_launch_url?.should == false
end

it "should add TC functionality" do
tc = IMS::LTI::ToolConsumer.new("hey", "ho")
tc.extend IMS::LTI::Extensions::OutcomeData::ToolConsumer
tc.support_outcome_data!
tc.outcome_data_values_accepted.should == 'text,url,lti_launch_url'
tc.outcome_data_values_accepted.should == 'text,url,lti_launch_url,submitted_at'
tc.outcome_data_values_accepted = 'url,text'
tc.outcome_data_values_accepted.should == 'url,text'
tc.outcome_data_values_accepted = %w{text url}
Expand Down Expand Up @@ -99,6 +100,13 @@
@tp.post_extended_replace_result!(url: 'http://url')
end

it 'handles submitted_at' do
xml = submission_xml % %{<submittedAt>2020-01-01</submittedAt>}
mock_request(xml)

@tp.post_extended_replace_result!(submitted_at: '2020-01-01')
end

it 'handles total_score' do
xml = result_xml % %{<resultTotalScore><language>en</language><textString>13</textString></resultTotalScore>}
mock_request(xml)
Expand Down Expand Up @@ -135,4 +143,4 @@
end
end
end
end
end
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def create_test_tp
end

def expected_xml; %{<?xml version="1.0" encoding="UTF-8"?><imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0"><imsx_POXHeader><imsx_POXRequestHeaderInfo><imsx_version>V1.0</imsx_version><imsx_messageIdentifier>123456789</imsx_messageIdentifier></imsx_POXRequestHeaderInfo></imsx_POXHeader><imsx_POXBody>%s</imsx_POXBody></imsx_POXEnvelopeRequest>} end
def result_xml; expected_xml % %{<replaceResultRequest><resultRecord><sourcedGUID><sourcedId>261-154-728-17-784</sourcedId></sourcedGUID><result>%s</result></resultRecord></replaceResultRequest>} end
def result_base_xml; expected_xml % %{<replaceResultRequest><resultRecord><sourcedGUID><sourcedId>261-154-728-17-784</sourcedId></sourcedGUID>%s</resultRecord>%s</replaceResultRequest>} end
def result_xml; result_base_xml % ["<result>%s</result>", ""] end
def submission_xml; result_base_xml % ["", "<submissionDetails>%s</submissionDetails>"] end
def replace_result_xml; result_xml % %{<resultScore><language>en</language><textString>5</textString></resultScore>} end
def read_result_xml; expected_xml % %{<readResultRequest><resultRecord><sourcedGUID><sourcedId>261-154-728-17-784</sourcedId></sourcedGUID></resultRecord></readResultRequest>} end
def delete_result_xml; expected_xml % %{<deleteResultRequest><resultRecord><sourcedGUID><sourcedId>261-154-728-17-784</sourcedId></sourcedGUID></resultRecord></deleteResultRequest>} end
Expand Down

0 comments on commit c657c98

Please sign in to comment.