mrdth/decipher-api

此包已被弃用且不再维护。未建议替代包。

FocusVision Decipher REST Api 的 PHP 包装器

1.1.1 2020-12-03 13:07 UTC

README

此包为 FocusVision Decipher API 提供 PHP 包装器,并包含用于 Laravel 应用的绑定。

安装

使用 composer 安装

composer require mrdth/decipher-api

Laravel 中的使用

添加两个新的环境变量

包将自动注册,可以通过其外观访问。

所有通过包装器调用 API 的操作应在 try-catch 块内执行;包装器不处理底层 Guzzle 客户端抛出的任何异常。

$directory = 'selfserve/99d';
$survey_id = '12345';

\Decipher::setServerDirectory($directory)->setSurveyId($survey_id);

try {
    $survey_structure = \Decipher::getSurveyStructure('json');
  
    // Do whatever with $survey object
} catch (\GuzzleHttp\Exception\RequestException $e) {
    echo 'Error making request, server responded: ' . $e->getCode();
}

作为独立 PHP 包的使用

use MrDth\DecipherApi\Factories\Client;
use MrDth\DecipherApi\Decipher;

$api_uri = 'https://v2.decipherinc.com/api/v1/';
$api_key = 'OBVIOUSLYFAKEAPIKEY';
$directory = 'selfserve/99d';
$survey_id = '12345';

$client = new Client($api_uri, $api_key);
$decipher = new Decipher($client, $api_uri, $api_key);

所有通过包装器调用 API 的操作应在 try-catch 块内执行;包装器不处理底层 Guzzle 客户端抛出的任何异常。

$decipher->setServerDirectory($directory)->setSurveyId($survey_id);

try {
    $survey_structure = $decipher->getSurveyStructure('json');
  
    // Do whatever with $survey object
} catch (\GuzzleHttp\Exception\RequestException $e) {
    echo 'Error making request, server responded: ' . $e->getCode();
}

包装器公开的方法

  • getSurveyList() - 获取当前 API 密钥下所有可用的调查列表。
  • setServerDirectory(string $directory) - Decipher 服务器上存储您的项目的目录
  • setSurveyId(int $id) - 设置要与之一起工作的当前调查的 ID。
  • setCondition(string $condition) - 获取参与者所需的条件。这是一个 Python 条件,就像你会在调查逻辑或交叉表中输入一样。例如,“qualified and q3.r2”仅检索符合资格且回答 q3 为 r2 的参与者。
  • getSurveyStructure(string $format) - 获取调查的可用问题结构,以指定格式返回。有效的格式有:html、json、text、tab
  • getSurveyData(array $fields = ['all'], string $format = 'json') - 从 Decipher 获取传递到 $fields 中的问题 ID 的响应。注意:uuid 和状态字段将始终返回。使用 ::setCondition() 设置的任何条件都将应用。
  • getSurveyFile(string $filename) - 将名为 $filename 的调查文件作为字符串检索。