-
Notifications
You must be signed in to change notification settings - Fork 123
/
rollcall_example.php
80 lines (62 loc) · 1.55 KB
/
rollcall_example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* These PestXML usage examples were written for the Rollcall REST service
* (see https://github.com/educoder/rollcall)
**/
require_once '../PestXML.php';
$pest = new PestXML('http://localhost:3000');
// Retrieve and iterate over the list of all Users
$users = $pest->get('/users.xml');
foreach($users->user as $user) {
echo $user->{'display-name'}." (".$user->username.")\n";
}
echo "\n";
// Create a new User
$data = array(
'user' => array(
'username' => "jcricket",
'password' => "pinocchio",
'display_name' => "Jiminy Cricket",
'kind' => "Student"
)
);
$user = $pest->post('/users.xml', $data);
echo "New User's ID: ".$user->id."\n";
echo "\n";
// Update the newly created User's attributes
$data = array(
'user' => array(
'kind' => "Instructor",
'metadata' => array(
'gender' => 'male',
'age' => 30
)
)
);
$pest->put('/users/'.$user->id.'.xml', $data);
// Retrieve the User
$user = $pest->get('/users/'.$user->id.'.xml');
echo "User XML: \n";
echo $user->asXML();
echo "\n";
echo "Name: ".$user->{'display-name'}."\n";
echo "Kind: ".$user->kind."\n";
echo "Age: ".$user->metadata->age."\n";
echo "\n";
// Delete the User
$user = $pest->delete('/users/'.$user->id.'.xml');
// Try to create a User with invalid data (missing username)
$data = array(
'user' => array(
'password' => "pinocchio",
'display_name' => "Jiminy Cricket",
'kind' => "Student"
)
);
try {
$user = $pest->post('/users.xml', $data);
} catch (Pest_InvalidRecord $e) {
echo $e->getMessage();
echo "\n";
}
?>