| 1 | #!/usr/bin/perl -w | ||||||||||
| 2 | |||||||||||
| 3 | package Sakai::Nakamura::WorldUtil; | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | require Exporter; | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | our @EXPORT_OK = (); | |||||||||
| 15 | |||||||||||
| 16 | 2 | 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 | 6 | ▶ | sub add_setup { | ||||||||
|
Subroutine
add_setup: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||
| 23 | my ( | ||||||||||
| 24 | 6 | $base_url, $id, $username, | |||||||||
| 25 | $title, $description, $tags, | ||||||||||
| 26 | $visibility, $joinability, $worldTemplate | ||||||||||
| 27 | ) = @_; | ||||||||||
| 28 | 6 | ▶ | if ( !defined $base_url ) { croak 'No base url defined to add against!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 5 | ▶ | if ( !defined $id ) { croak 'No id defined to add!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 3 | ▶ | if ( !defined $title ) { $title = $id; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 3 | ▶ | if ( !defined $description ) { $description = $id; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 3 | ▶ | if ( !defined $tags ) { $tags = $id; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 3 | ▶ | if ( !defined $visibility ) { $visibility = 'public'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 3 | ▶ | if ( !defined $joinability ) { $joinability = 'yes'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | |||||||||||
| 36 | 3 | ▶ | if ( !defined $worldTemplate ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 2 | $worldTemplate = '/var/templates/worlds/group/simple-group'; | |||||||||
| 38 | } | ||||||||||
| 39 | 3 | ▶ | if ( !defined $username ) { croak 'No user id defined to add!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 2 | 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 | 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 | 1 | ▶ | sub add_eval { | ||||||||
|
Subroutine
add_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 73 | 1 | my ($res) = @_; | |||||||||
| 74 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | #}}} | ||||||||||
| 78 | |||||||||||
| 79 | 2 | 1; | |||||||||
| 80 | |||||||||||
| 81 | __END__ | ||||||||||