mglinski/eve-api-php

为EVE API提供API协商层。

v1.2.3 2016-03-20 21:49 UTC

This package is auto-updated.

Last update: 2024-09-24 08:53:27 UTC


README

这是一个使消耗EVE API的EveApi变得非常简单的事情。它消除了原始API调用之间的任何歧义,并呈现了一个干净、简单的API。

基本思想是,所有API DataScopes都作为类实现,每个可用的API函数都作为该类的静态方法实现。要从EVE API获取角色表格,您将URL构造如下:

https://api.eveonline.com/char/CharacterSheet.xml.aspx?characterId=9999999&keyID=999999&vCode=______

此结构现在直接转换为静态类方法调用。对于API方法,如果公共/私有数据访问参数模糊或令人困惑,或需要API密钥来返回数据,这些都将硬编码到方法构造函数中。

<?php

// characterID of a character provided by the API Key
$characterID = 99999999;

// Create an ApiKey Object with the known key details
$api_key = new Eve\Api\ApiKey('KEY_ID', 'KEY_vCODE');

// Execute an API request.
$char = Eve\Character::CharacterSheet($characterID, $api_key);

// get the data returned from the API call.
echo $char->name;

文档

我尚未编写非代码文档。大多数函数都在代码文档块中进行了详细说明。请查看并请随时贡献一些文档。

待办事项

  • 文档
  • 社区请求

示例用法

这是一个API系统工作的示例,包括配置选项和错误检查。

<?php

// Imports
use Eve\Api\Config as EveApiConfig;
use Eve\Api\ApiKey as EveApiKey;
use Eve\Character as CharacterApi;

use Monolog\Logger;
use Monolog\Handler\StreamHandler as LogStreamHandler;

// EveApi Config Object
$config = EveApiConfig::Instance();
$config->user_agent = 'MY SITE NAME (v1.0) [email@domain.com]';
$config->log_handler = new LogStreamHandler('path/to/your.log', Logger::WARNING);

// Create an ApiKey Object with api key info
$key = new EveApiKey('KEY_ID', 'KEY_vCODE');

// Execute the API request.
$character = CharacterApi::CharacterSheet($characterID, $key);

// Get the character name from the returned data
if (!$key->getKeyError()) {
    echo $character->name;
}
else {
    throw new \Exception('EVE Api Exception: '.$key->getKeyErrorMessage());
}

版权

© 2015 Matthew Glinski和贡献者

在标准MIT许可证下发布