1. Go to this page and download the library: Download rikudou/my-colony-api 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/ */
rikudou / my-colony-api example snippets
use MyColony\Api;
$api = new Api();
// get sector info
$findSector = $api->findSector();
// get colony info
$colonyInfo = $api->getColonyInfo();
// get GBT prices
$prices = $api->getGbtPrices();
// get active GBT contracts
$contracts = $api->getGbtContracts();
use MyColony\Api;
use MyColony\Helper\XYCoordinate;
$api = new Api();
$sectorInfo = $api->findSector();
// set the sector to 0,0
$sectorInfo->setXCoordinate(0)->setYCoordinate(0);
// or
$sectorInfo->setXYCoordinates(new XYCoordinate(0, 0));
// limit to 5 colonies
$sectorInfo->setLimit(5);
// only independent
$sectorInfo->onlyIndependent(true);
// changed our mind, we want also dependent colonies
$sectorInfo->onlyIndependent(false);
// here we get the result
$result = $sectorInfo->getResponse();
// or all in one go
$result = $sectorInfo
->setXCoordinate(0)
->setYCoordinate(0)
->setLimit(5)
->onlyIndependent(true)
->getResponse();
// $result is now instance of MyColony\Response\Collection\SectorMapCollection
/** @var \MyColony\Response\SectorResponse $sectorColonyInfo */
foreach($result as $sectorColonyInfo) {
$sectorColonyInfo->getName(); // returns colony name
$sectorColonyInfo->getCharter(); // returns colony charter code
$sectorColonyInfo->hasCapitol(); // true/false - whether colony has capitol
$sectorColonyInfo->getMapType(); // can be checked against \MyColony\Enum\MapType constants
$sectorColonyInfo->getPopulation(); // the population as integer
$sectorColonyInfo->getXCoordinate(); // get the x position
$sectorColonyInfo->getYCoordinate(); // get the y position
$sectorColonyInfo->getColonyInfo(); // returns ColonyInfoResponse, more on that below
}
use MyColony\Api;
$api = new Api();
$colonyInfo = $api->getColonyInfo();
// set the charter code
$colonyInfo->setCharterCode("earth");
// get response
$result = $colonyInfo->getResponse();
// or in one go
$result = $colonyInfo->setCharterCode("earth")->getResponse();
// $result is now instance of MyColony\Response\ColonyInfoResponse
$result->getCharterCode(); // the colony charter code
$result->getName(); // the colony name
$result->getCivilization(); // the civilization, can be checked against MyColony\Enum\Civilizations constants
$result->getRace(); // the race, can be checked against MyColony\Enum\Race constants
$result->getMapType(); // the map type, can be checked against MyColony\Enum\MapType
$result->getFounded(); // returns DateTime object with the date the colony was founded
$result->isIndependent(); // whether the colony is or is not independent
$result->getIndependenceDay(); // if colony is independent, returns DateTime with date and time, otherwise returns false
$result->getPopulation(); // the population as integer
$result->getGDP(); // the colony GDP as integer
$result->getUnemploymentRate(); // the unemployment rate as an integer from 0 to 100
$result->getAtmosphereStage(); // the atmosphere level based stage
$result->getDevice(); // the identifier of the device type the colony was last played on
$result->getLastActive(); // DateTime object of when the colony was last online
$result->getThemeColor(); // the theme color the colony choose
$result->getScreenshotUrl(); // returns instance of GuzzleHttp\Psr7\Uri with the URL to colony screenshot
$result->getWebsiteUrl(); // returns instance of GuzzleHttp\Psr7\Uri with the URL to colony website
$result->getSector(); // returns the instance of MyColony\Helper\XYCoordinate with sector x and y coordinates
$result->getLocation(); // returns the instance of MyColony\Helper\XYCoordinate with x and y coordinates of the location inside sector
$result->getRRRIndex(); // returns the rrr index of colony, see https://www.ape-apps.com/viewpage.php?p=3418
$result->getMotherColony(); // returns MyColony\Response\Structures\MotherColonyInfo instance with partial colony info (more below)
$result->getChildColonies(); // return MyColony\Response\Collection\ChildColoniesCollection instance (more below)
// MyColony\Response\Structures\MotherColonyInfo which extends MyColony\Response\Structures\PartialColonyInfo
// MyColony\Response\Structures\ChildColonyInfo is also child of MyColony\Response\Structures\PartialColonyInfo
$motherColony = $result->getMotherColony();
// most of the methods are the same as in the colony stored in $result
// here is the list of methods:
$motherColony->getCharterCode();
$motherColony->getName();
$motherColony->getPopulation();
$motherColony->getWebsite();
$motherColony->getRelations(); // the relation the colony in $result has with colony in $motherColony
$motherColony->getSector();
$motherColony->getLocation();
$motherColony->getRRRIndex();
$motherColony->getFullColonyInfo(); // returns instance of MyColony\Response\ColonyInfoResponse with the full info
// instance of MyColony\Response\Collection\ChildColoniesCollection
// the collection can be iterated and every child is MyColony\Response\Structures\ChildColonyInfo
$children = $result->getChildColonies();
/** @var \MyColony\Response\Structures\ChildColonyInfo $child */
foreach($children as $child) {
// all methods are the same as in mother colony, except child colonies don't have getRRRIndex()
}
use MyColony\Api;
$prices = (new Api())->getGbtPrices();
$result = $prices->getResponse();
/** @var \MyColony\Response\GbtPriceResponse $resource */
foreach ($result as $resource) {
$resource->getName(); // returns the resource name, e.g. Food, can be checked against MyColony\Enum\GbtResourceNames
$resource->getResourceId(); // returns the resource ID, can be checked against MyColony\Enum\GbtResourceIds
$resource->getLegacyPrice(); // deprecated, gets resource price for older clients
$resource->getContracts(); // returns the collection of available contracts, more on that below
$resource->getPriceDetails(); // returns instance of MyColony\Response\Structures\GbtDetailedPrice
$details = $resource->getPriceDetails();
$details->getLastTradePrice(); // the price for this resource in the latest trade
$details->getRollingAveragePrice(); // the average price for last three days
$details->getMinPrice(); // the lowest price for last three days
$details->getMaxPrice(); // the biggest price for last three days
$details->getEmergencyPrice(); // emergency price, used by game 'if the market get too crazy'
}
use MyColony\Api;
use MyColony\Enum\GbtResourceIds;
$contracts = (new Api())->getGbtContracts();
// set the resource id to 3 (Wood)
$contracts->setResourceId(GbtResourceIds::WOOD);
// get the response
$contracts->getResponse();
// or all at once
$result = $contracts->setResourceId(GbtResourceIds::WOOD)->getResponse();
// $result is now instance of MyColony\Response\Collection\GbtContractsCollection
/** @var \MyColony\Response\GbtContractResponse $contract */
foreach($result as $contract) {
$contract->getResourceId(); // resource id, can be checked against MyColony\Enum\GbtResourceIds
$contract->getResourceName(); // resource name, can be checked against MyColony\Enum\GbtResourceNames
$contract->getSellerName(); // returns the name of the colony that is selling the item
$contract->getSellerCharterCode(); // the charter code of colony that is selling the item
$contract->getQuantity(); // the count of goods being sold
$contract->getPrice(); // the total price of the trade
$contract->getExpirationDate(); // DateTime object of date and time when the trade disappears from GBT
$contract->isSelling(); // whether the one who created the trade is selling
$contract->isBuying(); // whether the one who created the trade is buying
$contract->getSellerColonyInfo(); // instance of MyColony\Response\ColonyInfoResponse, see 'Colony Info' section above
$contract->getPricingInfo(); // instance of MyColony\Response\GbtPriceResponse, see 'GBT Prices' section above
}
use MyColony\Enum\GbtResourceIds;
$woodId = GbtResourceIds::findByName("Wood"); // returns 3
use MyColony\Enum\GbtResourceNames;
$name = GbtResourceNames::findById(3); // return "Wood"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.