evemarket/eve-market-details

EveOnline是一个公开的crest API库,它使获取API端点更加容易。

0.15.3 2016-07-25 01:23 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:42 UTC


README

Build Status Packagist Maintenance Made With Love

注意:永远不要相信packagist图标徽章。版本:0.15.0

composer require evemarket/eve-market-details

Eve Online Public Crest是一个库,允许您获取市场详情和历史详情。我们允许访问区域、订单、市场价格、历史数据、市场组、物品类型等。

该库的API简单、直接、易于理解。重要的是要理解,Eve的Public Crest API只允许20个并发连接,我们只创建18个。

您可以使用此库与Eve Public Crest Laravel Bridge Extension一起使用。您只需通过composer安装扩展程序,注册提供者和相关外观,然后即可开始。

您可以将此库作为独立库使用。这里的关键是,如果您使用Laravel,那么您将使用ClassName::methodName()而不是创建类的实例。

API密钥?

您无需令牌或API密钥即可访问EVE Online Public Crest API。

返回值

以下所有API调用将返回一个GuzzleHttp\Psr7\Response对象,形式为回调或数据容器。

某些方法需要传递成功和拒绝的回调函数,并带有适当的参数,如以下所述。

我们建议您将所有相关数据(如href特定数据)保存到数据库中。这允许您从数据库中提取href并获取其他数据。您不需要自己构造URL,因为大多数相关数据都在响应中。此库的组件旨在协同工作,以获取您需要的任何特定信息。

这个库不是什么

此库不是设计来获取击杀报告或Eve的任何其他与市场无关的方面的。

日志给我一堆Curl 52错误

这是不可避免的。它们很难追踪,更难处理。您无法在try catch中捕获它们。这似乎是EVE Online Public Crest API或Guzzle或您环境的问题。

但是,Eve Public Crest允许我们在基于池的请求中进行20个并发连接。我们只做18个,以避免达到速率限制。如果您看到任何503错误,则我们已达到速率限制,这是我们的问题。

我该如何处理curl 52错误?

我不确定。如果您有解决方案,我将非常乐意接受PR。

物品特定信息

Eve中的每个物品都可以从下面的Market Types类中获取。但是,如果您需要特定物品的详细信息,您可以使用物品的href,例如:https://crest-tq.eveonline.com/types/18/您不需要每次都自己构造此URL。

当您使用下面的市场类型类时,您会收到包含具有type->href属性的对象的响应。该属性可用于获取物品的具体信息。

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

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

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

上述内容应该很容易理解。我们将一个新的客户端注入到类实例中,然后根据它的href获取物品的详细信息,在回调中我们可以对返回的响应进行处理。响应将是一个GuzzleHttp\Psr7\Response对象。

市场类

以下文档化的市场类包含MarketGroupsMarketHistoryOrderPricesTypes等类。

这些类都与市场有关,返回的数据可以是响应对象,也可以是数据容器,您可以将它们保存到数据库中或按您希望的方式处理。

请注意,您绝对不需要自己构造URL。所有与市场相关的类在其响应或容器对象中都会包含某种href,允许您将其传递到另一个API调用中。

市场组

获取Eve中所有可用的组。这个操作可能需要一段时间,因此我们建议使用作业系统。不过基本原理很简单

// 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]]]

在这个阶段,您需要自己进行筛选,只保存您想要的组。无法直接查询公共纹章API。我们的API返回所有组和相关页面。

市场历史

如果您想从特定区域获取一组特定或多个物品的历史数据,那么您需要这个类。我们强烈建议您使用区域类和市场类型类来获取此类函数的相关信息。

首先,您需要从数据库中获取区域ID和物品ID。这些不是数据库ID,这些是Eve的ID。例如:Eve区域有一个id字段:例如:id: 11000001

Eve类型包含一个对象数组,每个对象都有一个id字段:例如:id: 18。这些就是您想要的ID。您可以使用上面建议的类来获取这些ID,并将相关数据保存到数据库中。

// 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.
});

市场订单

市场订单允许您获取特定区域特定物品的买卖订单。

我们强烈建议您使用区域类和市场类型类来获取此类函数的相关信息。

您需要物品类型href,您可以从市场类型的响应中获得,以及区域href,您也可以从区域的响应中获得。

注意!

您应该存储您获取的订单。虽然可能会有新的订单,但您可能还需要历史数据。

您应该只在需要时获取数据,而不是尝试获取所有物品和所有区域的所有订单。这将是非常计算密集型的。

// 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.

市场价格

这是一个相对简单的调用。我们调用https://crest-tq.eveonline.com/market/prices/来获取EVE中的所有市场价格。这些价格每24小时更新一次,所以请确保您已经设置了一个cron作业来运行。

这也是CCP在游戏中用来显示您查看市场详情时市场价格列表的端点。

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

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

市场类型

市场类型为您提供EVE中所有已知物品的信息。游戏中共有超过10,000个可用的物品,总共大约有12,000个物品,包括可用的、不可用的和CCP的测试物品。请确保进行适当的筛选。

当您需要获取有关物品的信息,如ID、href等时,应使用此类。请确保将相关信息存储在数据库中。

// 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.

我们将从https://crest-tq.eveonline.com/market/types/获取每个页面,并返回一个数组数组,其中主数组中的每个数组都包含该页面的JSON响应。

区域

这个调用相当简单,就像市场类型一样,我们强烈建议您将此信息存储在数据库中,以便在获取市场数据(如历史数据或区域买卖订单)时供其他类调用。

// 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.

我们将获取所有已知的区域。您需要过滤掉所有名称中带有连字符的区域。这些区域要么是虫洞,要么是CCP特定的区域。这将为您留下大约62个玩家可以与之交互的区域数组。