diff --git a/README.md b/README.md index bdfdf21..f4c1057 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ SUMMARY ------- -This is a thin PHP library for integration with the Challonge API. Uses cURL for http request and SimpleXML for the response handling. Just appends API Key +This is a thin PHP library for integration with the Challonge API. Uses cURL for http request and SimpleXML for the response handling. Just appends API Key. +Master by craigjackson forked from wshatch's master. +This fork updates to api v1 and adds "attachments" api requests. +by Mano82 EXAMPLE ------- diff --git a/src/Challonge/API.php b/src/Challonge/API.php index 2deaf79..eaad266 100644 --- a/src/Challonge/API.php +++ b/src/Challonge/API.php @@ -11,7 +11,7 @@ class ChallongeAPI { - const API_URL = 'https://challonge.com/api/tournaments'; + const API_URL = 'https://api.challonge.com/v1/'; const API_EXT = '.xml'; static public $api_key; protected $params = array(); @@ -43,7 +43,7 @@ public function request($url_append = '', $method = 'get', $params = array()) { case 'get': curl_setopt($ch, CURLOPT_URL, $this->prepareURL($url_append, $params)); - break; + break; case 'post': curl_setopt($ch, CURLOPT_URL, $this->prepareURL($url_append)); curl_setopt($ch, CURLOPT_POST, true); @@ -64,6 +64,7 @@ public function request($url_append = '', $method = 'get', $params = array()) default: return false; } + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); if ($response === false) { @@ -75,7 +76,7 @@ public function request($url_append = '', $method = 'get', $params = array()) public function prepareURL($url_append, $params = array()) { - return self::API_URL . $url_append . self::API_EXT . '?' . http_build_query(array_merge($params, array('api_key' => self::$api_key)), '', '&'); + return self::API_URL . $url_append . self::API_EXT . '?' . http_build_query(array_merge($params, array('api_key' => self::$api_key)), '', '&'); } protected function handleResponse($response) diff --git a/src/Challonge/Attachment.php b/src/Challonge/Attachment.php new file mode 100644 index 0000000..e30723f --- /dev/null +++ b/src/Challonge/Attachment.php @@ -0,0 +1,41 @@ +ids = self::PREFIX."/".$tournament_id."/matches/".$match_id."/attachments"; + } + + public function reqIndex() + { + return $this->request("/{$this->ids}"); + } + + public function reqCreate() + { + return $this->request("/{$this->ids}",'post'); + } + + public function reqShow($id) + { + return $this->request("/{$this->ids}/$id"); + } + + public function reqUpdate($id) + { + return $this->request("/{$this->ids}/$id",'put'); + } + + public function reqDestroy($id) + { + return $this->request("/{$this->ids}/$id",'delete'); + } +} + diff --git a/src/Challonge/Match.php b/src/Challonge/Match.php index d01f706..d609710 100644 --- a/src/Challonge/Match.php +++ b/src/Challonge/Match.php @@ -6,10 +6,11 @@ class ChallongeMatch extends ChallongeAPI { protected $tournament_id; + const PREFIX = "tournaments"; public function __construct($tournament_id) { - $this->tournament_id = $tournament_id; + $this->tournament_id = self::PREFIX."/".$tournament_id; } public function reqIndex() diff --git a/src/Challonge/Participant.php b/src/Challonge/Participant.php index fa024ac..7a27070 100644 --- a/src/Challonge/Participant.php +++ b/src/Challonge/Participant.php @@ -6,10 +6,11 @@ class ChallongeParticipant extends ChallongeAPI { protected $tournament_id; + const PREFIX = "tournaments"; public function __construct($tournament_id) { - $this->tournament_id = $tournament_id; + $this->tournament_id = self::PREFIX."/".$tournament_id; } public function reqIndex() @@ -21,6 +22,11 @@ public function reqCreate() { return $this->request("/{$this->tournament_id}/participants", 'post'); } + + public function reqBulkAdd() + { + return $this->request("/{$this->tournament_id}/participants/bulk_add", 'post'); + } public function reqShow($id) { @@ -31,6 +37,11 @@ public function reqUpdate($id) { return $this->request("/{$this->tournament_id}/participants/$id", 'put'); } + + public function reqCheckIn($id) + { + return $this->request("/{$this->tournament_id}/participants/$id/check_in", 'post'); + } public function reqDestroy($id) { @@ -43,3 +54,5 @@ public function reqRandomize() } } + + diff --git a/src/Challonge/Tournament.php b/src/Challonge/Tournament.php index d09cb03..b46dbda 100644 --- a/src/Challonge/Tournament.php +++ b/src/Challonge/Tournament.php @@ -5,44 +5,61 @@ */ class ChallongeTournament extends ChallongeAPI { - public function reqIndex() + const PREFIX = "tournaments"; + + public function reqIndex() { - return $this->request(); + return $this->request(self::PREFIX); } public function reqCreate() { - return $this->request('', 'post'); + return $this->request(self::PREFIX, 'post'); } public function reqShow($id) { - return $this->request("/$id"); + return $this->request(self::PREFIX."/$id"); } public function reqUpdate($id) { - return $this->request("/$id", 'put'); + return $this->request(self::PREFIX."/$id", 'put'); } public function reqDestroy($id) { - return $this->request("/$id", 'delete'); + return $this->request(self::PREFIX."/$id", 'delete'); } - public function reqPublish($id) + /*public function reqPublish($id) { return $this->request("/publish/$id", 'post'); - } + }*/ public function reqStart($id) { - return $this->request("/start/$id", 'post'); + return $this->request(self::PREFIX."/$id/start", 'post'); } public function reqReset($id) { - return $this->request("/reset/$id", 'post'); + return $this->request(self::PREFIX."/$id/reset", 'post'); + } + + public function reqFinalize($id) + { + return $this->request(self::PREFIX."/$id/finalize", 'post'); + } + + public function reqProcessCheckIns($id) + { + return $this->request(self::PREFIX."/$id/process_check_ins", 'post'); + } + + public function reqAbortCheckIn($id) + { + return $this->request(self::PREFIX."/$id/abort_check_in", 'post'); } }