forked from andrewscofield/parse.com-php-library
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparseRole.php
More file actions
221 lines (199 loc) · 5.81 KB
/
Copy pathparseRole.php
File metadata and controls
221 lines (199 loc) · 5.81 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* Handles some of the functionality for Roles described in
* https://parse.com/docs/rest#roles
*
* @author jobiwankanboi
*/
class parseRole extends parseObject {
public function __construct($name) {
if($name != '') {
parent::__construct('roles');
$this->data['name'] = $name;
} else {
$this->throwError('include the roleName when creating a parseRole');
}
}
/**
* Cannot change name of a role.
*
* @param type $name
* @param type $value
*/
public function __set($name,$value){
if($name != '_className' && $name != 'name'){
$this->data[$name] = $value;
}
}
/*
$parseObject->users = array(
'__op' => 'AddRelation',
'objects' => array(
$parseObject->dataType('pointer', array('post','8TOXdXf3tz'))
$parseObject->dataType('pointer', array('post','Ed1nuqPvc')),
)
);
*/
/**
* https://parse.com/docs/rest#roles-updating
* @param type $userIds
*/
public function addUsersToRole($userIds = array()) {
$objects = array();
foreach ($userIds as $userId) {
$objects[] = $this->dataType('pointer', array('_User', $userId));
}
$this->setProperty('users', array(
'__op' => 'AddRelation',
'objects' => $objects
));
}
/**
* https://parse.com/docs/rest#roles-updating
* @param type $userIds
*/
public function removeUsersFromRole($userIds = array()) {
$objects = array();
foreach ($userIds as $userId) {
$objects[] = $this->dataType('pointer', array('_User', $userId));
}
$this->setProperty('users', array(
'__op' => 'RemoveRelation',
'objects' => $objects
));
}
/**
* https://parse.com/docs/rest#roles-creating
*
* @return type
*/
public function save(){
if(!$this->data['ACL'])
$this->throwError('Must have ACL with role');
if(count($this->data) > 0 && $this->_className != ''){
$request = $this->request(array(
'method' => 'POST',
'requestUrl' => $this->_className,
'data' => $this->data,
));
return $request;
}
}
/**
* https://parse.com/docs/rest#roles-retrieving
* @param type $id
* @return type
*/
public function get($id){
if($this->_className != '' || !empty($id)){
$request = $this->request(array(
'method' => 'GET',
'requestUrl' => $this->_className.'/'.$id
));
if(!empty($this->_includes)){
$request['include'] = implode(',', $this->_includes);
}
return $request;
}
}
/**
* https://parse.com/docs/rest#roles-updating
* @param type $id
* @return type
*/
public function update($id){
if($this->_className != '' || !empty($id)){
$request = $this->request(array(
'method' => 'PUT',
'requestUrl' => $this->_className.'/'.$id,
'data' => $this->data,
));
return $request;
}
}
/**
* https://parse.com/docs/rest#roles-deleting
* @param type $id
* @return type
*/
public function delete($id){
if($this->_className != '' || !empty($id)){
$request = $this->request(array(
'method' => 'DELETE',
'requestUrl' => $this->_className.'/'.$id
));
return $request;
}
}
/**
*
* @param type $field
* @param type $amount
*/
public function increment($field,$amount){
$this->throwError("function increment makes no sense for role.");
}
/**
*
* @param type $id
*/
public function decrement($id){
$this->throwError("function decrement makes no sense for role.");
}
/**
* curl -X POST \
-H "X-Parse-Application-Id: Z0GKPdAmkIZsKg9nGgSGU52DQBUP2xavHmACYsAI" \
-H "X-Parse-REST-API-Key: lOQHg18qhxveTkNA6YGIWDtwBpwQ9ULyK2ZwPqTh" \
-H "Content-Type: application/json" \
-d '{
"name": "Moderators",
"ACL": {
"*": {
"read": true
}
}
}' \
https://api.parse.com/1/roles
*/
/**
* curl -X POST \
-H "X-Parse-Application-Id: Z0GKPdAmkIZsKg9nGgSGU52DQBUP2xavHmACYsAI" \
-H "X-Parse-REST-API-Key: lOQHg18qhxveTkNA6YGIWDtwBpwQ9ULyK2ZwPqTh" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.parse.com/1/classes/GameScore
*
*/
/**
* curl -X PUT \
-H "X-Parse-Application-Id: Z0GKPdAmkIZsKg9nGgSGU52DQBUP2xavHmACYsAI" \
-H "X-Parse-REST-API-Key: lOQHg18qhxveTkNA6YGIWDtwBpwQ9ULyK2ZwPqTh" \
-H "Content-Type: application/json" \
-d '{"opponents":{"__op":"AddRelation","objects":[{"__type":"Pointer","className":"Player","objectId":"Vx4nudeWn"}]}}' \
https://api.parse.com/1/classes/GameScore/Ed1nuqPvcm
*
* curl -X PUT \
-H "X-Parse-Application-Id: Z0GKPdAmkIZsKg9nGgSGU52DQBUP2xavHmACYsAI" \
-H "X-Parse-Master-Key: F3ywLEYgKT9JzxQKCX6L2UG7Ni6Aq7oIOlZWxVf0" \
-H "Content-Type: application/json" \
-d '{
"users": {
"__op": "AddRelation",
"objects": [
{
"__type": "Pointer",
"className": "_User",
"objectId": "8TOXdXf3tz"
},
{
"__type": "Pointer",
"className": "_User",
"objectId": "g7y9tkhB7O"
}
]
}
}' \
https://api.parse.com/1/roles/mrmBZvsErB
*/
}
?>