File Coverage

blib/lib/Sakai/Nakamura/WorldUtil.pm
Criterion Covered Total %
statement 39 39 100.0
branch 18 18 100.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 66 66 100.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             package Sakai::Nakamura::WorldUtil;
4              
5 2     2   29969 use 5.008001;
  2         7  
  2         79  
6 2     2   13 use strict;
  2         5  
  2         58  
7 2     2   19 use warnings;
  2         2  
  2         65  
8 2     2   10 use Carp;
  2         4  
  2         186  
9              
10             require Exporter;
11              
12 2     2   10 use base qw(Exporter);
  2         4  
  2         859  
13              
14             our @EXPORT_OK = ();
15              
16             our $VERSION = '0.13';
17              
18             #{{{sub add_setup
19             # TODO: Have first and last name passed in for email
20             # TODO: Support multiple tags properly
21              
22             sub add_setup {
23             my (
24 6     6 1 215 $base_url, $id, $username,
25             $title, $description, $tags,
26             $visibility, $joinability, $worldTemplate
27             ) = @_;
28 6 100       23 if ( !defined $base_url ) { croak 'No base url defined to add against!'; }
  1         25  
29 5 100       18 if ( !defined $id ) { croak 'No id defined to add!'; }
  2         28  
30 3 100       11 if ( !defined $title ) { $title = $id; }
  2         6  
31 3 100       10 if ( !defined $description ) { $description = $id; }
  2         3  
32 3 100       10 if ( !defined $tags ) { $tags = $id; }
  2         12  
33 3 100       11 if ( !defined $visibility ) { $visibility = 'public'; }
  2         6  
34 3 100       14 if ( !defined $joinability ) { $joinability = 'yes'; }
  2         3  
35              
36 3 100       9 if ( !defined $worldTemplate ) {
37 2         4 $worldTemplate = '/var/templates/worlds/group/simple-group';
38             }
39 3 100       9 if ( !defined $username ) { croak 'No user id defined to add!'; }
  1         27  
40 2         15 my $post_variables =
41             "\$post_variables = ['data','{\"id\":\""
42             . $id
43             . "\",\"title\":\""
44             . $title
45             . "\",\"tags\":[\""
46             . $tags
47             . "\"],\"description\":\""
48             . $description
49             . "\",\"visibility\":\""
50             . $visibility
51             . "\",\"joinability\":\""
52             . $joinability
53             . "\",\"worldTemplate\":\""
54             . $worldTemplate
55             . "\",\"message\":{\"body\":\"Hi \${firstName}\\n\\n \${creatorName} has added you as a \${role} to the group \\\"\${groupName}\\\"\\n\\n You can find it here \${link}\",\"subject\":\"\${creatorName} has added you as a \${role} to the group \\\"\${groupName}\\\"\",\"creatorName\":\"\",\"groupName\":\""
56             . $title
57             . "\",\"system\":\"Sakai\",\"link\":\""
58             . $base_url . "/~"
59             . $id
60             . "\",\"toSend\":[]},\"usersToAdd\":[{\"userid\":\""
61             . $username
62             . "\",\"role\":\"manager\"}]}']";
63 2         15 return "post $base_url/system/world/create $post_variables";
64             }
65              
66             #}}}
67              
68             #{{{sub add_eval
69             # TODO: check JSON that is returned for success, as a 200 status code is
70             # returned even if the world is not successfully added!
71              
72             sub add_eval {
73 1     1 1 3 my ($res) = @_;
74 1         3 return ( ${$res}->code eq '200' );
  1         10  
75             }
76              
77             #}}}
78              
79             1;
80              
81             __END__