1. Go to this page and download the library: Download 3rdpartyeve/perry library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
3rdpartyeve / perry example snippets
// once 'vendor/autoload.php';
// import the Setup class, alternatively you can always use the full qualified name)
use Perry\Setup;
// get the Instance of Setup and hand an instance of the PoolInterface implementation
// of the file cache
Setup::getInstance()->cacheImplementation = new FilePool("/path/to/cache/folder");
// change ttl to 10 minutes
Setup::$cacheTTL = 600;
// lets set an url here for this example
$url = "http://public-crest.eveonline.com/killmails/34940735/32a1ed47430a4bf247d0544b399014067a734994/";
// ve a use import on Perry\Perry, we can just use the classname here, otherwise
// it would be $killmail = \Perry\Perry::fromUrl($url);
/** @var \Perry\Representation\Eve\v1\Killmail */
$killmail = Perry::fromUrl($url);
// now there should be either an exception throw (in RL you want to catch those) or
// $killmail will contain a killmail. You can now access the values of the document
// quite easy.
// check if the victim has a character (not the cases for poses for example)
if (isset($killmail->victim->character)) {
$killstring = sprintf(
'%s of %s lost a %s to ',
$killmail->victim->character->name, // since we do have a character we can use its name
$killmail->victim->corporation->name, // victims allways have a corporation
$killmail->victim->shipType->name // the shiptype is what was actually lost
);
} else {
$killstring = sprintf(
'%s lost by %s to ',
$killmail->victim->shipType->name,
$killmail->victim->corporation->name
);
}
// attackers is a list of KillmailAttacker Objects.
$attackers = array();
foreach ($killmail->attackers as $attacker) {
// like the victim there might not be a character with the attacker (sentry guns?)
$attackers[] = isset($attacker->character) ? $attacker->character->name : $attacker->corporation->name;
}
$killstring .= join(',', $attackers);
echo $killstring;
// for more examples on what data is available in killmails, look at a killmail json string. If in doubt, there are some
// in tests/mock/kill*.json
// the references (character for example) which would be called like $killmail->victim->character(), do not work,
// since CCP has not opened those endpoints yet. :(
// except: the alliance endpoint work (at the moment on SISI only, but they will go live soon)
// declare namespace of your script (optional, but recommended)
namespace MyScript;
// lets set an url here for this example
$url = "http://public-crest.eveonline.com/districts/";
// cause Perry to make a request to CCP's CREST API, and
// populate the DistrictCollection (and the Districts it holds)
/** @var \Perry\Representation\Eve\v1\DistrictCollection */
$districtCollection = Perry::fromUrl($url);
// districtCollection has a member called "items" which contains a list of districts
// we iterate over those items, and print a short info for every district.
// owner,system and infrastructure are references, which means they refer to further
// api representations, sadly, at the moment they refer to parts of the CREST API that
// CCP has not made public yet.
// If those reprenstations where public you could access them by doing $district->owner(), which would return a
// Corporation Representation. Again, this this is not working yet, hence we only use the name of the
// reference in this example.
foreach ($districtCollection->items as $district) {
printf(
"District: %s\n Owner: %s\n System: %s\n Clone Capacity: %s\n cloneRate: %s\n Infrastructure: %s\n\n",
$district->name,
$district->owner->name,
$district->system->name,
$district->cloneCapacity,
$district->cloneRate,
$district->infrastructure->name
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.