From 0a2756f7c9d05bfb9a22de6ca094ccb3d67329e1 Mon Sep 17 00:00:00 2001 From: Jayson Phillips Date: Sun, 6 Mar 2011 12:54:03 -0500 Subject: [PATCH] Most of the group param is covered. --- Convore.php | 60 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/Convore.php b/Convore.php index 8d8767f..97f3a44 100644 --- a/Convore.php +++ b/Convore.php @@ -6,11 +6,18 @@ class Convore { private $base_url; private $http_response; - public function __construct($user, $pass) { - $this->credentials = vsprintf('%s:%s', array($user, $pass)); + public function __construct() { $this->base_url = "https://convore.com/api"; } + function setCredentials($user, $pass) { + $this->credentials = vsprintf('%s:%s', array($user, $pass)); + } + + function getCredentials() { + return $this->credentials; + } + function verifyAccount() { return $this->methodCall('/account/verify.json', 'get'); } @@ -23,27 +30,62 @@ function usersOnline() { return $this->methodCall('/account/online.json', 'get'); } - function getGroups() { + function getAllGroups() { return $this->methodCall('/groups.json', 'get'); } - function methodCall($convore_method, $action, $auth_required = true, $params = null) { + // Groups methods + + function createGroup($name, $kind, $desc = null, $slug = null) { + + $params = array('name' => $name, + 'kind' => $kind, + 'description' => $desc, + 'slug' => $slug); + + return $this->methodCall('/groups/create.json', 'post', $params); + } + + function getGroup($group_id) { + return $this->methodCall('/groups/'.$group_id.'.json', 'get'); + } + + function getGroupMembers($group_id, $filter = null) { + $params = array('filter' => sprintf('%s', $filter)); + return $this->methodCall('/groups/'.$group_id.'/members.json', 'get', $params); + + } + + function joinGroup($group_id) { + $params = array('group_id' => sprintf('%d', $group_id)); + return $this->methodCall('/groups/'.$group_id.'/join.json', 'post', $params); + } + + function joinPrivateGroup($group_id) { + $params = array('group_id' => sprintf('%d', $group_id)); + return $this->methodCall('/groups/'.$group_id.'/request.json', 'post', $params); + + } + + + function methodCall($convore_method, $action, $params = null, $auth_required = true) { $ch = curl_init(); $request = sprintf($this->base_url.'%s', $convore_method); + if($action == 'get' && isset($params)) { + curl_setopt($ch, CURLOPT_HTTPGET, true); + $request = $request.'?'.http_build_query($params); + } + curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERPWD, $this->credentials); if ($action == 'post') { - curl_setopt($ch, CURLOPT_HTTPPOST, 1); + curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); } - if($action == 'get') { - curl_setopt($ch, CURLOPT_HTTPGET, true); - } - $convore_data = curl_exec($ch); $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); return json_decode($convore_data);