PHP code example of evemarket / eve-market-details

1. Go to this page and download the library: Download evemarket/eve-market-details 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/ */

    

evemarket / eve-market-details example snippets



// Guzzle Client:
$client      = new Client();

$itemDetails = new EveOnline\Items\Details($client);

$itemDetails->details($href, function($response){
  ...
});

// Guzzle Client
$client       = new Client();
$marketGroups = new EveOnline\Market\Groups\MarketGroups($client);

// We use: https://crest-tq.eveonline.com/market/groups/ to get the groups.
$groups = marketGroups->fetchGroupPages(function($response){
  // Get the body and the bodies contents. Then decode the json.

  // Do other work.

  // Important:
  return $decodedJSONResponse;
});

// Because there will be a lot of groups you might want to chunk them up:
// Notice how we use items, an array of groups.
$groupChunks = array_chunk($groups->items, 100);

// create a series of jobs based off each chunk.
// For example, in laravel you might do:
foreach ($groupChunks as $chunk) {
    dispatch(new JobNameHere($chunk));
}

// We are only going to take one chunk of the $groupChunks for this example:
$groupsRequest     = marketGroups->createRequestsForGroups($groupChunks[0]);

$groupsInformation = marketGroups->fetchGroupsInfromation(function($reason, $index){
  // $reason is the reason why it failed. its a guzzle object or error object.
  // $index refers to the $groupsRequest[$index], as to which request failed.
});

$acceptedResponses = marketGroups->getAcceptedResponses();

// The above will show something like:
// [index => [[decodedJSONResponse], [decodedJSONResponse]]]

// Finally we need the container of data:
$groupsContainer = EveMarketGroups::getGroupInformationContainer($acceptedResponses, $groupChunks[0]);

// This will be an array of array where the key is the group name.
// ['groupName' => [[decodedJSONResponse], [decodedJSONResponse]]]

// Assume you have a couple regions and a couple item id's. These ned to be arrays.

// Guzzle Client.
$client         = new Client();

$historicalData = EveOnline\Market\History\MarketHistory($client);

// Remember the params must be arrays.
$historicalData->createRequests($regionIds, $itemIds);

historicalData->getItemHistoryForRegion(-20, function(array $regionItemPair, $responseJson){

    // $regionItemPair - the array [$regionId, $itemId]
    // $responseJson - Example response: https://crest-tq.eveonline.com/market/10000002/types/34/history/

}, function($reason, $index) {
  // $reason, guzzle object or error object stating why it failed.
  // $index, the index of responses created to tell you which response failed.
});

// Guzzle Client
$client = new Client();
$order  = new EveOnline\Market\Orders\Order($client);

$regionDetails = $order->getRegionDetailsJson($regionHref);
$orders        = $order->getBuyDetails($itemHref, $regionDetails);

if ($orders->totalCount !== 0) {
  // Do something ... We have buy orders for this region and item.
} else {
  // No buy orders. Tell the user.
}

$regionDetails = $order->getRegionDetailsJson($regionHref);
$orders        = $order->getSellDetails($itemHref, $regionDetails);

if ($orders->totalCount !== 0) {
  // Do something ... We have sell orders for this region and item.
} else {
  // No sell orders. Tell the user.
}

$regionHrefs = [];

// Push all the href's from the regions fetched and stored into the database onto a container.
foreach($regionsFromTheDatabase as $region) {
   array_push($regionHrefs, $region->href);
}

// We need an instance of Order handler:
$orderHandler           = new EveOnline\Market\Orders($this->client);

$orders                 = $order->searchAllRegionsForOrders($regionHrefs, $orderHandler);
$responses              = $orderHandler->getAcceptedResponsesJson();

// remember to pass in the $itemHref.
// isBuying represents two aspects: 1 are we searching all regions for buy orders? (true/false).
// if false then we search all regions for sell orders.
$createdRequestsForPool = $order->createRequestsForMarketDetailsPool($responses, $itemHref, $isBuying);

// Lets get all the order details back. This will be an array of details.
$orderDetails           = $order->getOrderResponsesFromRegionSearch($orderHandler, $createdRequestsForPool);

if (count($orderDetails) == 0) {
   return false;
}

foreach ($orderDetails as $order) {
   if ($order->totalCount !== 0) {
       // Store the orders.
   }
}

// If there are no orders across all regions then tell the user.

// Guzzle Client
$client = new Client();
$prices = new EveOnline\Market\Prices\Prices($client);

$prices->prices(function($response) {
  // $response is a GuzzleHttp\Psr7\Response object.
});

// Guzzle Client
$client = new Client();
$types  = new EveOnline\Market\Types\Types($client);

$typesContainer = $types->fetchTypes();

// See: https://crest-tq.eveonline.com/market/types/ as an example.

// Guzzle Client
$client  = new Client();
$regions = new EveOnline\Market\Regions\Regions($client);

$regions->regions(function($response){
  // $response is a GuzzleHttp\Psr7\Response object.
});

// See: https://crest-tq.eveonline.com/regions/ as an example.