[Developer] Code Snippets and Applications using the API
Okay so this is the place where you can post useful codes, applications, and even a place where you can show off your newly built website! So here are a few stuff I have that might come in handy for other people.
OFF TOPIC: If this is in the wrong section. Please flag it so a moderator can move it. Thanks! ^_^
Starter:
PHP Code:
<?php
// Abstracts querying the ~official~ API – add other goodies here (such as escape, etc.)
class APIFetcher {
private static $apiBase = "https://api.clashofclans.com/v1/";
private static $authKey = "! ADD YOUR API KEY HERE !";
public static function queryAPI($url) {
$in = curl_init();
$params = array("Authorization: Bearer" . self::$authKey, "Accept: application/json");
curl_setopt($in, CURLOPT_RETURNTRANSFER, true);
curl_setopt($in, CURLOPT_HTTPHEADER, $params);
curl_setopt($in, CURLOPT_URL, self::$apiBase . $url);
$result = curl_exec($in);
curl_close($in);
return $result;
}
}
class GoldenGators {
//Returns a map containing the specified clan's details.
public static function getClanDetails($id) {
$queryUrl = 'clan/%23' . $id;
return json_decode(APIFetcher::queryAPI($queryURL), true);
}
public static function getPlayerDetails($id) {
// Todo
}
}
//Example Usage
$clanJson = GoldenGators::getClanDetials('99VY9JR8');
?>
Not the most useful thing in the entire world. But it should help you get started. I'll try and get some more stuff for you guys when I complete a couple projects of mine.