arnapou / gw2apiclient
该包已被废弃,不再维护。未建议替代包。
Arnapou GW2 API 客户端
v2.0
2019-02-27 14:35 UTC
Requires
- php: >=7.0
- mongodb/mongodb: 1.0
This package is auto-updated.
Last update: 2024-09-05 17:52:44 UTC
README
此项目可以通过 PHP 请求 GW2 API。
我编写的类都很健壮:当 API 响应不佳时进行重试,它管理着长列表的 ID(发送多个请求并返回整个响应),等等。
初始化对象
// init Environment
$env = new Arnapou\GW2Api\Environment();
// init cache (here it is a Mongo cache, but it can be a file cache or whatever you want)
$mongo = MongoDB\Client('mongodb://localhost:27017', [], ['typeMap' => ['root' => 'array', 'document' => 'array']]);
$mongoDB = $mongo->selectDatabase("my_db");
$cache = new Arnapou\GW2Api\Cache\MongoCache($mongoDB);
$env->setCache($cache);
// init storage (optional, but recommended, here, we used the same mongo database as before)
$storage = new Arnapou\GW2Api\Storage\MongoStorage($mongoDB);
$env->setStorage($storage);
// set lang (en, fr, de, es)
$env->setLang('en');
// set access token
$env->setAccessToken('A7B98574-1757-8048-B640-55C2D3F46727BB6E108E-E011-4501-B0BB-B2731E90785D');
通过对象浏览账户(如果设置,则使用存储)
$account = new Arnapou\GW2Api\Model\Account($env);
$account->getWorld()->getName();
$account->getCharacter('My Character Name')->getEquipment('Helm')->getName();
使用 API 获取原始 API 数据(忽略存储,仅使用缓存)
$env->getClientVersion1()->apiColors();
$env->getClientVersion2()->apiItems([21141,65230]);
完全自定义使用
// get api raw data
$data = $env->getClientVersion2()->apiPets([28]);
// instanciate object with data and use it as you wish
$pet = new Arnapou\GW2Api\Model\Pet($env, $data[0]);
$pet->getName();
要求
- PHP 7+
- PECL 扩展 mongodb 版本 >=1.1.0 且 < 2.0.0