File Coverage

blib/lib/WebService/ScormCloud/Service/Registration.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package WebService::ScormCloud::Service::Registration;
2              
3 1     1   2203 use Moose::Role;
  0            
  0            
4              
5             with 'WebService::ScormCloud::Service';
6              
7             =head1 NAME
8              
9             WebService::ScormCloud::Service::Registration - ScormCloud API "registration" namespace
10              
11             =head1 VERSION
12              
13             Version 0.03
14              
15             =cut
16              
17             our $VERSION = '0.03';
18              
19             =head1 SYNOPSIS
20              
21             use WebService::ScormCloud;
22              
23             my $ScormCloud = WebService::ScormCloud->new(
24             app_id => '12345678',
25             secret_key => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
26             );
27              
28             my $registration_list = $ScormCloud->getRegistrationList;
29              
30             =head1 DESCRIPTION
31              
32             This module defines L<WebService::ScormCloud> API methods in the "registration"
33             namespace. See L<WebService::ScormCloud> for more info.
34              
35             =cut
36              
37             use Carp;
38              
39             requires 'process_request';
40              
41             =head1 METHODS
42              
43             =head2 createRegistration ( I<course_id>, I<registration_id>, I<first_name>, I<last_name>, I<learner_id> [ , I<options_hashref> ] )
44              
45             Creates a new registration.
46              
47             Required arguments are:
48              
49             =over 4
50              
51             =item B<course_id>
52              
53             =item B<registration_id>
54              
55             =item B<first_name>
56              
57             =item B<last_name>
58              
59             =item B<learner_id>
60              
61             =back
62              
63             Valid options include:
64              
65             =over 4
66              
67             =item B<email>
68              
69             =item B<postbackurl>
70              
71             =item B<authtype>
72              
73             =item B<urlname>
74              
75             =item B<urlpass>
76              
77             =item B<resultsformat>
78              
79             =item B<disableTracking>
80              
81             =back
82              
83             =cut
84              
85             sub createRegistration ## no critic (NamingConventions::Capitalization, Subroutines::ProhibitManyArgs)
86             {
87             my ($self, $course_id, $registration_id, $first_name, $last_name,
88             $learner_id, $opts)
89             = @_;
90              
91             croak 'Missing course_id' unless defined $course_id && length $course_id;
92             croak 'Missing registration_id'
93             unless defined $registration_id && length $registration_id;
94             croak 'Missing first_name' unless defined $first_name && length $first_name;
95             croak 'Missing last_name' unless defined $last_name && length $last_name;
96             croak 'Missing learner_id' unless defined $learner_id && length $learner_id;
97              
98             $opts ||= {};
99              
100             my %params = (
101             method => 'registration.createRegistration',
102             courseid => $course_id,
103             regid => $registration_id,
104             fname => $first_name,
105             lname => $last_name,
106             learnerid => $learner_id,
107             );
108              
109             foreach my $opt (
110             qw(email postbackurl authtype urlname urlpass
111             resultsformat disableTracking)
112             )
113             {
114             $params{$opt} = $opts->{$opt} if exists $opts->{$opt};
115             }
116              
117             return $self->process_request(
118             \%params,
119             sub {
120             my ($response) = @_;
121              
122             return exists $response->{success} ? 1 : 0;
123             },
124             );
125             }
126              
127             =head2 deleteRegistration ( I<registration_id> )
128              
129             Given a registration ID, delete the corresponding registration.
130              
131             =cut
132              
133             sub deleteRegistration ## no critic (NamingConventions::Capitalization)
134             {
135             my ($self, $registration_id) = @_;
136              
137             croak 'Missing registration_id' unless $registration_id;
138              
139             return $self->process_request(
140             {
141             method => 'registration.deleteRegistration',
142             regid => $registration_id,
143             },
144             sub {
145             my ($response) = @_;
146              
147             return exists $response->{success} ? 1 : 0;
148             },
149             );
150             }
151              
152             =head2 resetRegistration ( I<registration_id> )
153              
154             Given a registration ID, reset the corresponding registration.
155              
156             =cut
157              
158             sub resetRegistration ## no critic (NamingConventions::Capitalization)
159             {
160             my ($self, $registration_id) = @_;
161              
162             croak 'Missing registration_id' unless $registration_id;
163              
164             return $self->process_request(
165             {
166             method => 'registration.resetRegistration',
167             regid => $registration_id,
168             },
169             sub {
170             my ($response) = @_;
171              
172             return exists $response->{success} ? 1 : 0;
173             },
174             );
175             }
176              
177             =head2 getRegistrationList ( [ I<filters> ] )
178              
179             Returns an arrayref containing a list of registrations.
180             The returned list might be empty.
181              
182             The optional I<filters> hashref can contain any of these entries
183             to filter the returned list of registrations:
184              
185             =over 4
186              
187             =item B<filter>
188              
189             A regular expression for matching the registration ID
190              
191             =item B<coursefilter>
192              
193             A regular expression for matching the course ID
194              
195             =back
196              
197             Note that any filter regular expressions must match the B<entire>
198             string. (There seems to be an implied C<^...$> around the supplied
199             pattern.) So to match e.g. any courses that begin with "ABC":
200              
201             {coursefilter => '^ABC'} # THIS WILL NOT WORK
202              
203             {coursefilter => 'ABC.*'} # This will work
204              
205             =cut
206              
207             sub getRegistrationList ## no critic (NamingConventions::Capitalization)
208             {
209             my ($self, $filters) = @_;
210              
211             $filters ||= {};
212              
213             my %params = (method => 'registration.getRegistrationList');
214              
215             foreach my $key (qw(filter coursefilter))
216             {
217             $params{$key} = $filters->{$key} if $filters->{$key};
218             }
219              
220             return $self->process_request(
221             \%params,
222             sub {
223             my ($response) = @_;
224              
225             die "bad\n" unless exists $response->{registrationlist};
226             if ($response->{registrationlist})
227             {
228             return $response->{registrationlist};
229             }
230             else
231             {
232             return []; # empty list
233             }
234             },
235             {
236             xml_parser => {
237             ForceArray => ['registration', 'instance'],
238             GroupTags => {
239             'registrationlist' => 'registration',
240             'instances' => 'instance',
241             },
242             }
243             }
244             );
245             }
246              
247             =head2 getRegistrationResult ( I<registration_id> [ , I<results_format> ] )
248              
249             Given a registration ID, returns registration results.
250              
251             Optional C<results_format> can be "course" (the default),
252             "activity", or "full".
253              
254             =cut
255              
256             sub getRegistrationResult ## no critic (NamingConventions::Capitalization)
257             {
258             my ($self, $registration_id, $results_format) = @_;
259              
260             croak 'Missing registration_id' unless $registration_id;
261              
262             my %params = (
263             method => 'registration.getRegistrationResult',
264             regid => $registration_id
265             );
266             $params{resultsformat} = $results_format if $results_format;
267              
268             return $self->process_request(
269             \%params,
270             sub {
271             my ($response) = @_;
272              
273             return
274             ref($response->{registrationreport}) eq 'HASH'
275             ? $response->{registrationreport}
276             : undef;
277             },
278             {
279             xml_parser => {
280             ForceArray =>
281             [qw(activity comment response interaction objective)],
282             GroupTags => {
283             'children' => 'activity',
284             'comments_from_learner' => 'comment',
285             'comments_from_lms' => 'comment',
286             'correct_responses' => 'response',
287             'interactions' => 'interaction',
288             'objectives' => 'objective',
289             },
290             }
291             }
292             );
293             }
294              
295             =head2 getRegistrationListResults ( )
296              
297             Effectively, runs getRegistrationList to get all the registrations,
298             and then runs getRegistrationResult on each of them.
299              
300             Not implemented yet.
301              
302             =cut
303              
304             sub getRegistrationListResults ## no critic (NamingConventions::Capitalization)
305             {
306             croak 'Not implemented yet.';
307             }
308              
309             =head2 launchURL ( I<registration_id> , I<$redirect_url> [ , I<options_hashref> ] )
310              
311             Given a registration ID and redirect URL, returns a URL that can be
312             used in the browser to launch the test at cloud.scorm.com.
313              
314             Valid options include:
315              
316             =over 4
317              
318             =item B<cssurl>
319              
320             =item B<learnerTags>
321              
322             =item B<courseTags>
323              
324             =item B<registrationTags>
325              
326             =item B<disableTracking>
327              
328             =back
329              
330             =cut
331              
332             sub launchURL ## no critic (NamingConventions::Capitalization)
333             {
334             my ($self, $registration_id, $redirect_url, $opts) = @_;
335              
336             croak 'Missing registration_id' unless $registration_id;
337             croak 'Missing redirect_url' unless $redirect_url;
338              
339             $opts ||= {};
340              
341             my %params = (
342             method => 'registration.launch',
343             regid => $registration_id,
344             redirecturl => $redirect_url,
345             );
346              
347             foreach my $opt (
348             qw(cssurl learnerTags courseTags registrationTags disableTracking))
349             {
350             $params{$opt} = $opts->{$opt} if exists $opts->{$opt};
351             }
352              
353             return $self->request_uri(\%params);
354             }
355              
356             =head2 resetGlobalObjectives ( I<registration_id> )
357              
358             Given a registration ID, reset any global objectives associated with
359             the corresponding registration.
360              
361             =cut
362              
363             sub resetGlobalObjectives ## no critic (NamingConventions::Capitalization)
364             {
365             my ($self, $registration_id) = @_;
366              
367             croak 'Missing registration_id' unless $registration_id;
368              
369             return $self->process_request(
370             {
371             method => 'registration.resetGlobalObjectives',
372             regid => $registration_id,
373             },
374             sub {
375             my ($response) = @_;
376              
377             return exists $response->{success} ? 1 : 0;
378             },
379             );
380             }
381              
382             =head2 updateLearnerInfo ( I<learner_id>, I<fname>, I<lname> [ , I<new_id> ] )
383              
384             Reset learner info previously given during registration creation.
385              
386             Not implemented yet.
387              
388             =cut
389              
390             sub updateLearnerInfo ## no critic (NamingConventions::Capitalization)
391             {
392             my ($self, $learner_id, $first_name, $last_name, $new_id) = @_;
393              
394             croak 'Missing learner_id' unless $learner_id;
395             croak 'Missing first_name' unless $first_name;
396             croak 'Missing last_name' unless $last_name;
397              
398             croak 'Not implemented yet.';
399             }
400              
401             1;
402              
403             __END__
404              
405             =head1 SEE ALSO
406              
407             L<WebService::ScormCloud>
408              
409             =head1 AUTHOR
410              
411             Larry Leszczynski, C<< <larryl at cpan.org> >>
412              
413             =head1 BUGS
414              
415             Please report any bugs or feature requests to C<bug-scormcloud at rt.cpan.org>, or through
416             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-ScormCloud>. I will be notified, and then you'll
417             automatically be notified of progress on your bug as I make changes.
418              
419             Patches more than welcome, especially via GitHub:
420             L<https://github.com/larryl/ScormCloud>
421              
422             =head1 SUPPORT
423              
424             You can find documentation for this module with the perldoc command.
425              
426             perldoc WebService::ScormCloud::Service::Registration
427              
428             You can also look for information at:
429              
430             =over 4
431              
432             =item * GitHub
433              
434             L<https://github.com/larryl/ScormCloud>
435              
436             =item * RT: CPAN's request tracker
437              
438             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WebService-ScormCloud>
439              
440             =item * AnnoCPAN: Annotated CPAN documentation
441              
442             L<http://annocpan.org/dist/WebService-ScormCloud>
443              
444             =item * CPAN Ratings
445              
446             L<http://cpanratings.perl.org/d/WebService-ScormCloud>
447              
448             =item * Search CPAN
449              
450             L<http://search.cpan.org/dist/WebService-ScormCloud/>
451              
452             =back
453              
454             =head1 ACKNOWLEDGEMENTS
455              
456              
457             =head1 COPYRIGHT & LICENSE
458              
459             Copyright 2010 Larry Leszczynski.
460              
461             This program is free software; you can redistribute it and/or modify it
462             under the terms of either: the GNU General Public License as published
463             by the Free Software Foundation; or the Artistic License.
464              
465             See http://dev.perl.org/licenses/ for more information.
466              
467             =cut
468