Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
-------
Expand Down
7 changes: 4 additions & 3 deletions src/Challonge/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions src/Challonge/Attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* Challonge's Match API class
*/
class ChallongeAttachment extends ChallongeAPI
{
protected $tournament_id;
const PREFIX = "tournaments";

public function __construct($tournament_id, $match_id)
{
$this->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');
}
}

3 changes: 2 additions & 1 deletion src/Challonge/Match.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion src/Challonge/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -43,3 +54,5 @@ public function reqRandomize()
}
}



37 changes: 27 additions & 10 deletions src/Challonge/Tournament.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}