nellyt / free-to-game-api-wrapper
为 https://www.freetogame.com API提供的包装器
v1.0.2
2021-03-08 21:21 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- lukasoppermann/http-status: ^3.1
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.0.0
- codeception/module-phpbrowser: ^1.0.0
- hoa/console: ^3.17
This package is auto-updated.
Last update: 2024-09-09 05:03:12 UTC
README
这是一个针对FreeToGame API的PHP包装器
基本安装
您可以通过Composer使用以下命令安装此包:
composer require nellyt/free-to-game-api-wrapper
使用方法
基本
require ('vendor/autoload.php'); $client = new \FreeToGame\Client(); $response = $client->fetchList(); $response = $client->fetchDetails($gameId); $response->getResponse()->getStatusCode(); $response->getData();
过滤器
在获取游戏列表时使用过滤器。有三种类型的过滤器
- 平台
- 类别
- 标签
过滤器添加到FilterCollection实例中,并将其传递给客户端。
平台过滤器
$platformFilter = new \FreeToGame\Filters\PlatformFilter(new \FreeToGame\Filters\Platforms\Browser()); $filterCollection = new \FreeToGame\Filters\FilterCollection(); $filterCollection->setPlatformFilter($platformFilter); $response = $client->fetchList($filterCollection);
类别/标签过滤器
游戏列表可以通过类别或标签进行筛选,但不能同时使用两者。标签过滤器需要一个SearchTerms数组,而类别过滤器只接受一个。
类别
$categoryFilter = new \FreeToGame\Filters\CategoryFilter(new \FreeToGame\Filters\SearchTerms\Shooter()); $filterCollection = new \FreeToGame\Filters\FilterCollection(); $filterCollection->setCategoryFilter($categoryFilter); $response = $client->fetchList($filterCollection);
标签
$searchTerms = [ new \FreeToGame\Filters\SearchTerms\Shooter(), new \FreeToGame\Filters\SearchTerms\Strategy(), new \FreeToGame\Filters\SearchTerms\Racing(), ]; $tagFilter = new \FreeToGame\Filters\TagFilter($searchTerms); $filterCollection = new \FreeToGame\Filters\FilterCollection(); $filterCollection->setTagFilter($tagFilter); $response = $client->fetchList($filterCollection);
标签辅助工具
有两个辅助函数可用于构建SearchTerms数组。
$shooter = \FreeToGame\Helpers\SearchTermFactory::getSearchTerm('shooter'); $searchTerms = \FreeToGame\Helpers\SearchTermFactory::getSearchTerms(['shooter', 'zombie', 'permadeath']);
排序
可以排序游戏列表。
$sort = new \FreeToGame\Sort\AlphabeticalSort(); $response = $client->fetchList(null, $sort);
示例:多个过滤器和排序
$platformFilter = new \FreeToGame\Filters\PlatformFilter(new \FreeToGame\Filters\Platforms\Browser()); $searchTerms = [ new \FreeToGame\Filters\SearchTerms\Shooter(), new \FreeToGame\Filters\SearchTerms\Strategy(), new \FreeToGame\Filters\SearchTerms\Racing(), ]; $tagFilter = new \FreeToGame\Filters\TagFilter($searchTerms); $filterCollection = new \FreeToGame\Filters\FilterCollection(); $filterCollection->setPlatformFilter($platformFilter); $filterCollection->setTagFilter($tagFilter); $sort = new \FreeToGame\Sort\AlphabeticalSort(); $response = $client->fetchList($filterCollection, $sort);
排序选项
排序选项列表如下
- 按字母顺序排序
- 按流行度排序
- 按发布日期排序
- 按相关性排序
- 排序
搜索词
搜索词列表如下
- 操作
- 动作角色扮演游戏
- 动漫
- 大逃杀
- 卡牌
- 幻想
- 格斗
- 第一人称
- 飞行
- 恐怖
- 低配置
- 武术
- 大型多人在线
- 大型多人在线第一人称射击游戏
- 大型多人在线即时战略游戏
- 大型多人在线角色扮演游戏
- 大型多人在线第三人称射击游戏
- 军事
- 多人在线战斗竞技场
- 开放世界
- 永久死亡
- 像素
- 玩家对抗环境
- 玩家对抗玩家
- 赛车
- 航海
- 沙盒
- 科幻
- 搜索词
- 射击
- 侧滚动
- 社交
- 太空
- 体育
- 策略
- 超级英雄
- 生存
- 坦克
- 第三人称
- 三维
- 俯视视角
- 塔防
- 回合制
- 二维
- 体素
- 僵尸