PHP classes for APIv2
From EVEDev
| APIv2 PHP classes | |
|---|---|
| Maintainer: | Rynlam |
| Stable release: | unknown |
| Development release: | unknown |
| OS: | Platform independent, PHP 5 required |
| License: | GPL |
| Website: | http://wiki.eve-dev.net |
Contents |
[edit] PHP classes for APIv2
Additions for usage with Kw4h's PHP classes. You'll at least need class.api.php from his work. Note that some modification of class.api.php is needed.
[edit] Changes to class.api.php
Find
private $apikey = null; private $userid = null; private $charid = null;
Add under
private $corpid = null;
Find
if (!empty($charid) && is_numeric($charid)) { $this->charid = $charid; }
Add under
if (!empty($corpid) && is_numeric($corpid)) { $this->corpid = $corpid; }
Find
if ($this->charid != null) { $params['characterID'] = $this->charid; }
Add under
if ($this->corpid != null) { $params['corporationID'] = $this->corpid; }
Find
$contents = $this->retrieveXml("/char/WalletJournal.xml.aspx", $params);
}
return $contents;
}
Add under
public function getCorporationSheet() {
$contents = $this->retrieveXml("/corp/CorporationSheet.xml.aspx");
return $contents;
}
public function getAllianceList() {
$contents = $this->retrieveXml("/eve/AllianceList.xml.aspx");
return $contents;
}
[edit] Corporation Sheet (class.corporationsheet.php)
[edit] PHP code
<?php class Corporationsheet { static function getCorporationSheet($contents) { if (!empty($contents)) { $xml = new SimpleXMLElement($contents); $output = array(); foreach ($xml->result->children() as $name => $value) { if (((string) $name) != "logo" && ((string) $name) != "rowset") { $output[(string) $name] = (string) $value; } elseif (((string) $name) == "logo") { foreach ($xml->result->logo->children() as $nameb => $valueb) { $output[(string) $name][(string) $nameb] = (string) $valueb; } } elseif (((string) $name) == "rowset") { foreach ($xml->result->rowset as $rowset) { foreach ($rowset->attributes() as $attrn => $attrv) { if ($attrn == "name") { $rsname = (string) $attrv; } } foreach ($rowset->row as $row) { $index = count($output[$rsname]); foreach ($row->attributes() as $nameb => $valueb) { if ($index < 7) { $output[$rsname][$index][(string) $nameb] = (string) $valueb; } } } } } } return $output; } return null; } } ?>
This class requires you to set cache = false in your Api() object, or every corporation you try to retrieve will give the same data as the first corporation retrieved.
[edit] Usage
<?php require_once('class.api.php'); require_once('class.corporationsheet.php'); $api = new Api(); $api->cache(false); $api->setCredentials($apiuser,$apipass,$apichar); //$api->setCredentials($apiuser,$apipass,$apichar,$apicorp); $corpxml = $api->getCorporationSheet(); $corp = Corporationsheet::getCorporationSheet($corpxml); print_r($corp); ?>
You MUST disable cache for this to work. I haven't found a way to force the base class to disable it regardless of the setting in the code, if you figure that out, tell me please :) You'll need to set $apiuser, $apipass, and $apichar to retrieve info on your character's corporation. If you have priveleges to view the corporation wallet divisions, this will show their names. If you have a corporation ID you want the info on, add $apicorp as the corporation ID onto the setCredentials line. If your script is only retrieving the corporation info for other corps, and you don't need any character data, you can do setCredentials(null,null,null,$apicorp).
[edit] Alliance List (class.alliancelist.php)
[edit] PHP Code
<?php class Alliancelist { static function getAllianceList($contents) { if (!empty($contents)) { $xml = new SimpleXMLElement($contents); $output = array(); foreach ($xml->result->rowset->row as $row) { // Alliances $output['id'][(string) $row['allianceID']] = (string) $row['name']; foreach ($row->rowset->row as $row2) { // Corporations $index = count($output[(string) $row['name']]); $output[(string) $row['name']][$index]['corporationID'] = array(); foreach ($row2->attributes() as $key => $val) { $output[(string) $row['name']][$index][(string) $key] = (string) $val; } } } return ($output); } } } ?>
[edit] Usage
<?php require_once('class.api.php'); require_once('class.alliancelist.php'); $api = new Api(); $alliancexml = $api->getAllianceList(); $alliances = Alliancelist::getAllianceList($alliancexml); print_r($alliances); ?>
Don't overuse this. It retrieves the members of EVERY alliance and their join dates. If you use this in an app, cache it yourself, and only update it every 24 hours (which is how often alliance status ingame updates, AFAIK). My apps retrieve this every 24 hours and write it to an array in a php file that I can then include in any scripts that need alliance data.

