File Coverage

blib/lib/WebService/ScormCloud.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;
2              
3 7     7   37376 use Moose;
  0            
  0            
4              
5             =head1 NAME
6              
7             WebService::ScormCloud - Interface to cloud.scorm.com
8              
9             =head1 DESCRIPTION
10              
11             This module provides an API interface to cloud.scorm.com, which is a
12             web service provided by Rustici Software (L<http://www.scorm.com/>).
13              
14             API docs can be found at
15             L<http://cloud.scorm.com/EngineWebServices/doc/SCORMCloudAPI.html>.
16              
17             The author of this module has no affiliation with Rustici Software
18             other than as a user of the interface.
19              
20             Registered trademarks are property of their respective owners.
21              
22             =head1 VERSION
23              
24             Version 0.03
25              
26             =cut
27              
28             our $VERSION = '0.03';
29              
30             =head1 SYNOPSIS
31              
32             use WebService::ScormCloud;
33              
34             my $ScormCloud = WebService::ScormCloud->new(
35             app_id => '12345678',
36             secret_key => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
37             );
38              
39             =cut
40              
41             use WebService::ScormCloud::Types;
42              
43             =head1 API CLASSES
44              
45             Each portion of the API is defined in its own class:
46              
47             L<WebService::ScormCloud::Service::Course>
48              
49             L<WebService::ScormCloud::Service::Debug>
50              
51             L<WebService::ScormCloud::Service::Registration>
52              
53             L<WebService::ScormCloud::Service::Reporting>
54              
55             L<WebService::ScormCloud::Service::Upload>
56              
57             =cut
58              
59             with
60             'WebService::ScormCloud::Service::Course',
61             'WebService::ScormCloud::Service::Debug',
62             'WebService::ScormCloud::Service::Registration',
63             'WebService::ScormCloud::Service::Reporting',
64             'WebService::ScormCloud::Service::Upload',
65             ;
66              
67             =head1 USAGE
68              
69             =head2 new( I<%args> )
70              
71             Construct a C<WebService::ScormCloud> object to communicate with the API.
72              
73             B<Note:> Any of the following constructor parameters can also be
74             called post-construction as object set/get methods.
75              
76             =over 4
77              
78             =item B<app_id>
79              
80             B<Required.> An application ID generated for your login at
81             L<http://cloud.scorm.com/>.
82              
83             =cut
84              
85             has 'app_id' => (
86             is => 'rw',
87             required => 1,
88             isa => 'Str',
89             );
90              
91             =item B<secret_key>
92              
93             B<Required.> A secret key that corresponds to the application ID,
94             used for hashing parameters in the API request URLs. Generated at
95             L<http://cloud.scorm.com/>.
96              
97             =cut
98              
99             has 'secret_key' => (
100             is => 'rw',
101             required => 1,
102             isa => 'Str',
103             );
104              
105             =item B<service_url>
106              
107             The API service URL. Defaults to "http://cloud.scorm.com/api".
108              
109             =cut
110              
111             has 'service_url' => (
112             is => 'rw',
113             required => 1,
114             isa => 'WebService::ScormCloud::Types::URI',
115             coerce => 1,
116             default => 'http://cloud.scorm.com/api',
117             );
118              
119             =item B<last_error_data>
120              
121             Returns a listref representing the raw response data for the
122             error(s) returned by the most recent ScormCloud service API call.
123              
124             The data will look like:
125              
126             [
127             {
128             code => 100.
129             msg => 'A general security error has occured',
130             }
131             ...
132             ]
133              
134             Useful if e.g. "die_on_bad_response" is set to false, and a service
135             API call returns undef instead of the expected object.
136              
137             =cut
138              
139             has 'last_error_data' => (
140             is => 'rw',
141             isa => 'ArrayRef',
142             default => sub { return [] },
143             );
144              
145             =item B<last_error_msg>
146              
147             Return a error message representing the error(s) returned by the
148             most recent ScormCloud service API call.
149              
150             Useful if e.g. "die_on_bad_response" is set to false, and a service
151             API call returns undef instead of the expected object.
152              
153             =cut
154              
155             my %error_codes = ();
156              
157             sub last_error_msg
158             {
159             my ($self) = @_;
160              
161             my @msg = ();
162              
163             foreach my $error (@{$self->last_error_data})
164             {
165             my $msg = $error->{msg};
166             $msg =~ s/^\s+//msx;
167             $msg =~ s/\s+$//msx;
168             $msg =~ s/\s+/ /msx;
169             $msg =~ s/ associated with appid \[.*?\]//gmsx;
170              
171             push @msg, $msg;
172             }
173              
174             return join("\n", @msg);
175             }
176              
177             =item B<lwp_user_agent>
178              
179             Set the user agent string used in API requests. Defaults to "MyApp/1.0".
180              
181             =cut
182              
183             has 'lwp_user_agent' => (
184             is => 'rw',
185             required => 1,
186             isa => 'WebService::ScormCloud::Types::LWP::UserAgent',
187             coerce => 1,
188             default => 'MyApp/1.0',
189             );
190              
191             =item B<top_level_namespace>
192              
193             Top-level namespace for API methods. Defaults to "rustici".
194              
195             =cut
196              
197             has 'top_level_namespace' => (
198             is => 'rw',
199             required => 1,
200             isa => 'Str',
201             default => 'rustici',
202             );
203              
204             =item B<dump_request_url>
205              
206             Set to true to dump request URLs to STDOUT. Default is false.
207              
208             =cut
209              
210             has 'dump_request_url' => (
211             is => 'rw',
212             isa => 'Bool',
213             default => 0,
214             );
215              
216             =item B<dump_response_xml>
217              
218             Set to true to dump raw response XML to STDOUT. Default is false.
219              
220             =cut
221              
222             has 'dump_response_xml' => (
223             is => 'rw',
224             isa => 'Bool',
225             default => 0,
226             );
227              
228             =item B<dump_response_data>
229              
230             Set to true to dump data from parsed response XML to STDOUT.
231             Default is false.
232              
233             Parsing is currently done with L<XML::Simple>.
234              
235             =cut
236              
237             has 'dump_response_data' => (
238             is => 'rw',
239             isa => 'Bool',
240             default => 0,
241             );
242              
243             =item B<dump_api_results>
244              
245             Set to true to dump results grabbed from response data by each API
246             call. Default is false.
247              
248             Parsing is currently done with L<XML::Simple>.
249              
250             =cut
251              
252             has 'dump_api_results' => (
253             is => 'rw',
254             isa => 'Bool',
255             default => 0,
256             );
257              
258             =item B<die_on_bad_response>
259              
260             Set to true to die if the API response data is malformed or invalid
261             for the given API method being called (mainly useful for testing).
262             Default is false.
263              
264             =cut
265              
266             has 'die_on_bad_response' => (
267             is => 'rw',
268             isa => 'Bool',
269             default => 0,
270             );
271              
272             =back
273              
274             =cut
275              
276             no Moose;
277              
278             __PACKAGE__->meta->make_immutable;
279              
280             1;
281              
282             __END__
283              
284             =head1 SEE ALSO
285              
286             L<http://www.scorm.com/>
287              
288             L<WebService::ScormCloud::Service::Course>
289              
290             L<WebService::ScormCloud::Service::Debug>
291              
292             L<WebService::ScormCloud::Service::Registration>
293              
294             L<WebService::ScormCloud::Service::Reporting>
295              
296             L<WebService::ScormCloud::Service::Upload>
297              
298             =head1 AUTHOR
299              
300             Larry Leszczynski, C<< <larryl at cpan.org> >>
301              
302             =head1 BUGS
303              
304             Please report any bugs or feature requests to
305             C<bug-scormcloud at rt.cpan.org>, or through the web interface at
306             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-ScormCloud>.
307             I will be notified, and then you'll automatically be notified of
308             progress on your bug as I make changes.
309              
310             Patches more than welcome, especially via GitHub:
311             L<https://github.com/larryl/ScormCloud>
312              
313             =head1 SUPPORT
314              
315             You can find documentation for this module with the perldoc command.
316              
317             perldoc WebService::ScormCloud
318              
319             You can also look for information at:
320              
321             =over 4
322              
323             =item * GitHub
324              
325             L<https://github.com/larryl/ScormCloud>
326              
327             =item * RT: CPAN's request tracker
328              
329             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WebService-ScormCloud>
330              
331             =item * AnnoCPAN: Annotated CPAN documentation
332              
333             L<http://annocpan.org/dist/WebService-ScormCloud>
334              
335             =item * CPAN Ratings
336              
337             L<http://cpanratings.perl.org/d/WebService-ScormCloud>
338              
339             =item * Search CPAN
340              
341             L<http://search.cpan.org/dist/WebService-ScormCloud/>
342              
343             =back
344              
345             =head1 ACKNOWLEDGEMENTS
346              
347              
348             =head1 COPYRIGHT & LICENSE
349              
350             Copyright 2010 Larry Leszczynski.
351              
352             This program is free software; you can redistribute it and/or modify it
353             under the terms of either: the GNU General Public License as published
354             by the Free Software Foundation; or the Artistic License.
355              
356             See http://dev.perl.org/licenses/ for more information.
357              
358             =cut
359