Code Monkey home page Code Monkey logo

clashofclans-api-php's Introduction

ClashOfClans-API-PHP

Scrutinizer Code Quality Build Status

This is a wrapper for SuperCell's official Clash Of Clans-API located at https://developer.clashofclans.com/#/

Before trying to use this, you have to create an account and request a token on their website. After that, change the token located in the API.class.php to yours.

I'm working on the documentation, for now, you have to figure out how to use it for yourself. There's an example in the repository, though.

Live-Demo of example: http://1n9i9c7om.com/coc/test.php Keep in mind I'm not a web designer, this page is just to show how this wrapper works.

Requirements

PHP 5 or higher with cURL support.

Usage

Search for clans

$api = new ClashOfClans();
$results = $api->searchClanByName("foxforcefürth"); //returns an array containing all search results
$clan = new CoC_Clan($results->items[0]); //gets the first result from the array

Get Clan Details

$clan = new CoC_Clan("#22UCCU0J"); 

$clan->getName(); //returns foxforcefürth 
$clan->getLevel(); //returns 5

Get information about the clan leader

$clan = new CoC_Clan("#22UCCU0J");
$members = $clan->getAllMembers();

foreach($members as $member)
{
	$member = new CoC_Member($member); //convert member into a CoC_Member object
	if($member->getRole() == "leader")
	{
		echo $member->getName(); //returns Lalato;
		echo $member->getLevel(); //returns 131 
		break; //leave the foreach after the leader was found, as there's only one per clan
	}
}

Some more example scripts (including Warlog usage) are included in the "Examples"-folder inside this repository.

Documentation

API.class.php - gets the information from the API and sends the requests to Supercell's Servers.

  • #sendRequest($url);
  • +searchClanByName($searchString);
  • +searchClan($parameters);
  • +getClanByTag($tag);
  • +getClanMembersByTag($tag);
  • +getLocationList();
  • +getLocationInfo();
  • +getLeagueList();
  • +getRankList();

Clan.class.php - gets information about a clan by using a tag

  • +__construct($tagOrClass);
  • #getClan();
  • +getTag();
  • +getName();
  • +getDescription();
  • +getType();
  • +getLocationId();
  • +getBadgeUrl($size);
  • +getWarFrequency();
  • +getLevel();
  • +getWarWins();
  • +getWarWinStreak();
  • +getPoints();
  • +getRequiredTrophies();
  • +getMemberCount();
  • +getMemberByIndex($index);
  • +getAllMembers();
  • +getMemberByName($name);

League.class.php - gets information about a league by using a league ID.

  • +__construct($league);
  • #getLeague();
  • +setLeagueByName();
  • +getLeagueIcon($size);

Location.class.php - gets information about a location by using a location ID.

  • +__construct($location);
  • #getLocation();
  • +setLocationByName();
  • +setLocationByCode();
  • +getLocationName();
  • +isCountry();
  • +getCountryCode();

Member.class.php - gets information about a location by using an stdClass returned by Clan.class.php

  • +__construct($memberObj);
  • +getTag();
  • +getName();
  • +getRole();
  • +getLevel();
  • +getLeagueId();
  • +getTrophies();
  • +getClanRank();
  • +getPreviousClanRank();
  • +getDonations();
  • +getDonationsReceived();
  • +getDonationsRatio();

# means protected
+ means public

clashofclans-api-php's People

Contributors

1n9i9c7om avatar repeatercreeper avatar scrutinizer-auto-fixer avatar tom982 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clashofclans-api-php's Issues

Found 2 Error on try

hi nico, thanks for these API. but after run example as include here, i get 2 message error

  1. Warning: require_once(./ClashAPI/API.class.php): failed to open stream: No such file or directory in /home/user/public_html/ClashOfClans-API-PHP-master/Examples/clanInformation.php on line 2
  2. Fatal error: require_once(): Failed opening required './ClashAPI/API.class.php' (include_path='.:/opt/php-5.5/pear') in /home/user/public_html/ClashOfClans-API-PHP-master/Examples/clanInformation.php on line 2

After i check the code, you miss one (dot sign)

Original Code -> Result Error :

<?php
require_once "./ClashAPI/API.class.php";

Edit Code

<?php
require_once "../ClashAPI/API.class.php";

maybe you want take a minute for commit update 👍

Geting list of clans in Location

Not sure i was checking but cant find a way to get clans from location. Should i declar first league or what to call getRankList? Or is this not yet possible?

Help me

I cannot get this work, can you please help me.

Examples Broken

I keep receiving NOTICE: Trying to get property of non-object. I even copy and pasted the examples and it still doesn't work. Please help!

I'm thinking it has to do with my setup on the SC's Developer website. IP Address could be wrong preventing the website from receiving.

Missing War information...

The following are not handled:

get /clans/{clanTag}/warlog : Clan war log
get /clans/{clanTag}/currentwar : Information about clan's current clan war
get /clans/{clanTag}/currentwar/leaguegroup : Information about clan's current clan war league group
get /clanwarleagues/wars/{warTag} : Information about a clan war league war

Slow loading league badges

Hi,

Thanks for this wrapper, really useful. Only have one issue.
As soon as I include the league badges for player by setting values for League.class.php, the load time of the whole clanmembers list is extremely slow.
When I disable the images, it fast as lightning.
Using the most recent version of all files so it should already have the caching changes in it.
Any idea what could cause this?

Regards,

Ralph

Problem in returning top Clans/Players

Please take a look at the "getRankList" function in class.API.php.
it returns the top clans all the time!
i have debug it myself but you check it out!

beside please remove all json_decodes , many people want the json_encode and the should call json_encode again!

thanks!

Non-Object

Everything I do is being met with Notice: Trying to get property of non-object in C:\xampp\htdocs\Clan Link\requests\ClashAPI\Clan.class.php on line 115

image

Checked:

  • API Key - I've used this with another API just to make sure it works and YES it does.
  • cURL in xampp - Checked and yes it does exist as my previous API actually uses cURL.

As previously stated the CODE is the exact replica of the "Examples: clanInformation.php" even the location of the API.class.php is the same.

WarLogs

Hi,

Can someone add a class for warlogs??

Update for Player Info

Player Info data is now available! I'll try and work out an update. Though I thought I'd let you know. ;3

Any specific read permissions needed on the CoC side?

So I've gotten my API token from the CoC website (made sure the IP was correct as my server).

For some reason, when I enter my clan tag (#YGJP9RGR), I am returned with a blank page (except the column headers, donation headers, etc) when I access the page. Is there anything on the CoC app that I need to enable to allow the API to access my clan's data? Do I need to the a (Co-)Leader in order for it to work?

Library as package

Thanks for previous update, one more question possible to port this lib to composer? So it will be easyer to use it with Laravel ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.