Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.

Commit a1cee7e

Browse files
committed
Added E-voting Apis
1 parent ee23f38 commit a1cee7e

1 file changed

Lines changed: 85 additions & 12 deletions

File tree

src/UnionCloud/Api.php

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Api {
99

10-
private $VERSION = "0.1.1";
10+
private $VERSION = "0.1.0";
1111

1212
private $host;
1313

@@ -32,7 +32,7 @@ public function setAuthToken($token, $token_expires) {
3232
private function _curl($endpoint, $verb) {
3333
$curl = new Curl();
3434
$curl->setUserAgent('UnionCloud API PHP Wrapper v' . $this->VERSION);
35-
35+
3636
$curl->setOpt(CURLOPT_CAINFO, dirname(__FILE__) . '/../../unioncloud.pem');
3737
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, true);
3838
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
@@ -124,7 +124,6 @@ private function _delete($endpoint, $data = null) {
124124

125125

126126

127-
128127
#
129128
# Authenticate
130129
#
@@ -182,12 +181,13 @@ public function groups_get() {
182181

183182
public function groups_save_membership($data) {
184183
$curl = $this->_post("/save_memberships", [], array_merge(["auth_token" => $this->auth_token], $data));
184+
echo $this->_curl_debug($curl, true);
185185
return @$curl->response;
186186
}
187+
188+
189+
187190

188-
189-
190-
191191
#
192192
# Users
193193
#
@@ -254,6 +254,7 @@ public function usergroup_get_members($ug_id, $mode = "standard", $page = null,
254254
if ($page == null) { $page = 1; }
255255

256256
$curl = $this->_get("/user_groups/".$ug_id."/user_group_memberships", ["mode" => $mode, "page" => $page]);
257+
echo $this->_curl_debug($curl, true);
257258
$max = $this->_curl_header($curl, "total_pages");
258259
$output = $curl->response["data"];
259260

@@ -281,8 +282,6 @@ public function usergroup_folderstructure() {
281282
}
282283

283284

284-
285-
286285
#
287286
# UserGroup Membership
288287
#
@@ -291,13 +290,18 @@ public function usergroup_membership_create($data) {
291290
return $curl->response["data"];
292291
}
293292

293+
public function usergroup_membership_create_multiple($data) {
294+
$curl = $this->_post("/user_group_memberships/upload", ["data" => $data]);
295+
return $curl->response["data"];
296+
}
297+
294298
public function usergroup_membership_update($ugm_id, $data) {
295299
$curl = $this->_put("/user_group_memberships/".$ugm_id, ["data" => $data]);
296300
return $curl->response["data"];
297301
}
298302

299303
public function usergroup_membership_delete($ugm_id) {
300-
$curl = $this->_delete("/user_group_memberships/".$ugm_id, ["data" => $data]);
304+
$curl = $this->_delete("/user_group_memberships/".$ugm_id, []);
301305
return $curl->response["data"];
302306
}
303307

@@ -311,10 +315,10 @@ public function eventtypes_get() {
311315
$curl = $this->_get("/event_types");
312316
return $curl->response["data"];
313317
}
318+
319+
320+
314321

315-
316-
317-
318322
#
319323
# Events
320324
#
@@ -394,5 +398,74 @@ public function event_question_delete($event_id, $question_id) {
394398
$curl = $this->_delete("/events/".$event_id."/questions/".$question_id);
395399
return $curl->response["data"];
396400
}
401+
402+
403+
404+
405+
#
406+
# eVoting Elections
407+
#
408+
public function election_categories($page = 1) {
409+
$curl = $this->_get("/election_categories", ["page" => $page]);
410+
return $curl->response;
411+
}
412+
413+
public function election_category_get($category_id) {
414+
$curl = $this->_get("/election_categories/" . $category_id, []);
415+
return $curl->response;
416+
}
417+
418+
419+
public function election_positions($page = 1, $mode = "full") {
420+
$curl = $this->_get("/election_positions", ["page" => $page, "mode" => $mode]);
421+
return $curl->response;
422+
}
423+
424+
public function election_position_get($position_id, $mode = "full") {
425+
$curl = $this->_get("/election_positions/" . $position_id, ["mode" => $mode]);
426+
return $curl->response;
427+
}
428+
429+
430+
public function elections($page = 1, $mode = "full") {
431+
$curl = $this->_get("/elections", ["page" => $page, "mode" => $mode]);
432+
return $curl->response;
433+
}
434+
435+
public function election_get($election_id, $mode = "full") {
436+
$curl = $this->_get("/elections/" . $election_id, ["mode" => $mode]);
437+
return $curl->response;
438+
}
439+
440+
441+
public function election_standings($election_id, $page = 1, $mode = "standard") {
442+
$curl = $this->_get("/elections/" . $election_id . "/election_standings", ["page" => $page, "mode" => $mode]);
443+
return $curl->response;
444+
}
445+
446+
// returns filepath
447+
public function election_voters($election_id, $voter_type = "actual", $page = 1) {
448+
$curl = $this->_get("/elections/" . $election_id . "/election_voters", ["page" => $page, "voter_type" => $voter_type]);
449+
450+
$file = $curl->response["file_path"];
451+
$src = file_get_contents($file);
452+
return json_decode($src, true);
453+
}
454+
455+
// returns filepath
456+
public function election_voters_demographics($election_id, $voter_type = "actual", $page = 1, $mode = "basic") {
457+
$curl = $this->_get("/elections/" . $election_id . "/election_voters_demographics", ["page" => $page, "voter_type" => $voter_type, "mode" => $mode]);
458+
459+
$file = $curl->response["file_path"];
460+
$src = file_get_contents($file);
461+
return json_decode($src, true);
462+
}
463+
464+
465+
public function election_votes($election_id, $page = 1) {
466+
$curl = $this->_get("/elections/" . $election_id . "/votes", ["page" => $page]);
467+
return $curl->response;
468+
}
469+
397470

398471
}

0 commit comments

Comments
 (0)