Skip to content

Commit

Permalink
Merge pull request ubc#11 from ubc/add-protocol-lti-auto-updates
Browse files Browse the repository at this point in the history
Add protocol option for automatic lti updates
  • Loading branch information
andrew-gardener authored Jan 18, 2018
2 parents b9de9e2 + 3899ed9 commit e0fdf06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 13 additions & 3 deletions lib/WebworkBridge/autoupdate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ =head1 SYNOPSIS
autoupdate [options]
Options:
-check Only check to see if LTI roster requests are successful.
-grade Try to send grades to the LMS.
-check Only check to see if LTI roster requests are successful.
-grade Try to send grades to the LMS.
-protocol Force using provided protocol when sending request to server
=head1 OPTIONS
Expand All @@ -28,6 +29,11 @@ =head1 OPTIONS
Enables additional parameters in the LTI launch request that tells
Webwork to try sending grades to the LMS.
=item B<-protocol=s>
Force using protocol when sending request to server for class membership and grade updates.
Overrides protocol used by server_root_url
=back
=cut
Expand All @@ -53,12 +59,16 @@ BEGIN
# if set to true, will try to send grades to the LMS
my $grade = '';

# force request url to use protocol (overrides server_root_url)
my $protocol = '';

my $man = 0;
my $help = 0;

GetOptions (
"check" => \$check,
"grade" => \$grade,
"protocol=s" => \$protocol,
'help|?' => \$help,
man => \$man
);
Expand Down Expand Up @@ -93,7 +103,7 @@ BEGIN
}
else
{
$cmd = $ENV{WEBWORK_ROOT} . "/lib/WebworkBridge/updateclass_lti.pl '$courseName' '$oauth_consumer_key' '$context_id' $grade";
$cmd = $ENV{WEBWORK_ROOT} . "/lib/WebworkBridge/updateclass_lti.pl '$courseName' '$oauth_consumer_key' '$context_id' '$grade' '$protocol'";
}

my $ret = `$cmd\n`;
Expand Down
8 changes: 7 additions & 1 deletion lib/WebworkBridge/updateclass_lti.pl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ BEGIN
print "Parameter count incorrect, please enter all parameters:";
print "\updateclass_lti CourseName oauthConsumerKey contextId\n";
print "\nGrades (Optional) - If given, will try to send grades to LMS.\n";
print "\nProtocol (Optional) - If given, will override request_url's protocol.\n";
print "\ne.g.: updateclass_lti Math100-100 consumerKey 123abc123abc\n";
exit();
}
Expand All @@ -38,6 +39,7 @@ BEGIN
my $oauth_consumer_key = shift;
my $context_id = shift;
my $grade = shift;
my $protocol = shift;

# bring up a course environment
my $ce = WeBWorK::CourseEnvironment->new({
Expand Down Expand Up @@ -66,7 +68,7 @@ BEGIN
my $custom_context_memberships_url = $ltiContext->custom_context_memberships_url;

my %gradeParams;
if (defined($grade))
if (defined($grade) && $grade eq 'true')
{
$gradeParams{'ext_ims_lis_resultvalue_sourcedids'} = 'decimal';
$gradeParams{'custom_gradesync'} = '1';
Expand Down Expand Up @@ -108,6 +110,10 @@ BEGIN
my $ua = LWP::UserAgent->new;
push @{ $ua->requests_redirectable }, 'POST';

# force replace request_url protocol for internal request
if ($protocol) {
$request_url =~ s/^\w+:\/\//$protocol:\/\//g;
}
my $res = $ua->post($request_url . $courseName . "/", $request->to_hash);
if ($res->is_success)
{
Expand Down

0 comments on commit e0fdf06

Please sign in to comment.