musicjerm/oneapiphpsdk

PHP SDK 用于简化从 The One Ring API 获取数据的操作

dev-main 2023-07-15 22:14 UTC

This package is auto-updated.

Last update: 2024-09-16 01:03:09 UTC


README

Author Source Code Software License php 8.0+

统治万物的 One SDK(适用于 PHP)

你是 PHP 开发者吗?你想要一个易于使用并从统治万物的单一源 API 获取数据的库吗?你害怕穿越莫多尔的险境以获取自己的 API 数据吗?别再找了。One API(适用于 PHP)为你提供了支持。这就像是你的山姆wise Gamgee,帮助你穿越莫多尔 API 的可怕壕沟。

实际上并没有那么可怕,但我们在这里是为了给你提供帮助,让这个过程更加容易。

安装

要安装,请使用 composer require musicjerm/oneapiphpsdk

如何使用这个神奇的 SDK

请从 https://the-one-api.dev/ 获取你的 API 密钥

安装完成后,只需包含 Client 库并按照以下列表进行调用即可!是的,就这么简单!

<?php

namespace Your\App;

use Musicjerm\OneApiPhpSdk\Model\Client;

class yourClass
{
    private string $apiKey = 'put_your_api_key_here';

    public function getSomeData()
    {
        // create the client
        $oneApiClient = new Client($this->apiKey);

        // submit your query and access it using the ->getJsonData method
        $oneClient->oneQuery('quote', '5cd96e05de30eff6ebcce9ba');
        $response = $oneClient->getJsonData();

        // response is a json encoded string
        // decode it if necessary
        $arrayData = json_decode($response, false, 512, JSON_THROW_ON_ERROR)->docs;
        
        print_r($arrayData);
    }
}

Client->oneQuery() 接受三个参数。只需第一个是必需的。

Client->oneQuery(string $mediaType, string $mediaId, string $quote);

有效的参数如下

  • $mediaType - book, movie, character, quote, chapter
  • $mediaId - 这是上述电影类型之一的 ID,通常看起来像一串字符
  • $quote - 这必须是 moviecharacter,并且 在传递此参数之前,必须先传递前两个参数。这将列出电影或角色的所有引用。如果第一个参数不是这些之一,此参数将被忽略。

一个有效的请求可能看起来像 $oneClient->oneQuery('quote', '5cd96e05de30eff6ebcce9ba');

测试

PHPUnit 测试包含在 /tests 目录下。要运行它们

  1. 请确保已安装 PHPUnit composer require --dev phpunit/phpunit
  2. tests/OneClientTest.php 中更新 api 密钥。
  3. 在项目目录下,只需运行 ./vendor/bin/phpunit ./vendor/musicjerm/oneapiphpsdk/tests

有关 PHPUnit 的更多信息,请访问 https://docs.phpunit.de/en/10.2/index.html