composer.json000075500000000200144761607250007275 0ustar00{ "name": "boru/bitbucket", "autoload": { "psr-4" : { "boru\\bitbucket\\" : "src/" } } }instructions-composer.txt000075500000000315144761607250011714 0ustar00{ "require": { "boru/bitbucket": "dev-master" }, "repositories": [ { "type": "composer", "url": "https://satis.boruapps.com" } ] }src/Bitbucket.php000064400000001234144761607250007774 0ustar00apiBase = new api\Base($user,$pass,$outputFormat); $this->apiProject = new api\Project($user,$pass,$outputFormat); $this->apiProjectRepos = new api\ProjectRepos($user,$pass,$outputFormat); } public function api() { return $this->apiBase; } public function project() { return $this->apiProject; } public function projectRepos() { return $this->apiProjectRepos; } }src/api/Base.php000064400000006510144761607250007505 0ustar00setUser($user); $this->setPass($pass); $this->setParse($outputParseFormat); } public function setUser($user) { $this->user = $user; } public function setPass($pass) { $this->pass = $pass; } public function setParse($parse) { $this->parse = $parse; } public function setBaseUrl($base_url) { $this->base_url = $base_url; } public function setApiPath($api_path) { $this->api_path = $api_path; } public function setDebug($debug) { $this->debug = $debug; } public function setDebugRaw($debug_raw) { $this->debug_raw = $debug_raw; } protected function _getUrl($rest="") { return $this->base_url.$this->api_path.$rest; } public function _call($type,$uri,$parms=array(),$ssl_verify=false,$customheader=array('Content-Type: application/json')) { if(substr($uri,0,4) != 'http') $uri = $this->_getUrl($uri); if(!is_array($customheader) || !is_object($customheader) || empty($customheader)) $customheader=array('Content-Type: application/json'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$uri); curl_setopt($ch, CURLOPT_USERPWD, $this->user.":".$this->pass); curl_setopt($ch, CURLOPT_URL,$uri); if($this->debug_raw) curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $customheader); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl_verify); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if($type !== "GET" && is_array($parms)) $parms = json_encode($parms); switch($type) { case 'GET': if(!empty($parms)) { if(strpos($uri,"?") == false) $uri.='?'; $uri.=http_build_query($parms); } break; case 'POST': curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $parms); break; case 'DELETE': case 'PUT': default: curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($type)); curl_setopt($ch, CURLOPT_POSTFIELDS, $parms); } $response = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); $data = substr($response,$info['header_size']); if(!$this->parse) { if(strtolower($this->parse) == "array") $data = json_decode($data,true); else $data = json_decode($data); } $response = new Response($info['http_code'],trim(substr($response,0,$info['header_size'])),substr($response,$info['header_size'])); return $response; } public function _get($uri,$parms=array(),$ssl_verify=false,$customheader="") { return $this->_call("GET",$uri,$parms,$ssl_verify,$customheader); } public function _post($uri,$parms=array(),$ssl_verify=false,$customheader="") { return $this->_call("POST",$uri,$parms,$ssl_verify,$customheader); } public function _put($uri,$parms=array(),$ssl_verify=false,$customheader="") { return $this->_call("PUT",$uri,$parms,$ssl_verify,$customheader); } public function _delete($uri,$parms=array(),$ssl_verify=false,$customheader="") { return $this->_call("DELETE",$uri,$parms,$ssl_verify,$customheader); } }src/api/Project.php000064400000001774144761607250010250 0ustar00_get("/projects?name=$name"); else return $this->_get("/projects"); } public function create($key,$name,$description="") { if(empty($key)) throw new Exception('Missing Key'); if(empty($name)) throw new Exception('Missing Name'); $parms = array("key"=>$key,"name"=>$name,"description"=>$description); return $this->_post("/projects",$parms); } public function update($key,$name,$description="") { if(empty($key)) throw new Exception('Missing Key'); $parms["key"] = $key; if(!empty($name)) $parms["name"] = $name; if(!empty($description)) $parms["description"] = $description; if(count($parms)<=1) throw new Exception('Nothing to update'); return $this->_put("/projects/$key",$parms); } public function delete($key) { if(empty($key)) throw new Exception('Missing Key'); return $this->_put("/projects/$key"); } }src/api/ProjectRepos.php000064400000002003144761607250011243 0ustar00_get("/projects/$projectKey/repos"); } public function create($projectKey,$name) { if(empty($projectKey)) throw new Exception('Missing projectKey'); if(empty($name)) throw new Exception('Missing repository name'); $parms = array("name"=>$name,"scmId"=>"git","forkable"=>true); return $this->_post("/projects/$projectKey/repos",$parms); } public function update($projectKey,$repos,$data) { if(empty($projectKey)) throw new Exception('Missing projectKey'); if(empty($repos)) throw new Exception('Missing repository name'); return $this->_put("/projects/$projectKey/repos/$repos",$data); } public function delete($projectKey,$slug) { if(empty($projectKey)) throw new Exception('Missing projectKey'); if(empty($slug)) throw new Exception('Missing slug'); return $this->_put("/projects/$projectKey/repos/$slug"); } }src/api/Response.php000064400000001073144761607250010430 0ustar00header = $header; $this->status = $status; $this->data = $data; $this->data_array = json_decode($data,true); $this->data_object = json_decode($data); } public function getData($type="array") { if(empty($type)) return $this->data; if(strtolower($type) == "array") return $this->data_array; return $this->data_object; } }