insites-consulting/decipher-api

FocusVision Decipher REST Api 的 PHP 包装器

2.5 2022-07-11 07:28 UTC

This package is auto-updated.

Last update: 2024-09-11 12:14:25 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 InsitesConsulting\DecipherApi\Decipher;use InsitesConsulting\DecipherApi\Factories\Client;

$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 条件,就像您在调查逻辑或交叉表中输入一样。例如,“合格且 q3.r2” 仅检索合格且回答 q3 为 r2 的参与者。
  • getSurveyStructure(string $format) - 获取调查可用的问题的结构,并以指定格式返回。有效的格式是:html、json、text、tab
  • getSurveyData(array $fields = ['all'], string $return_format = 'json', bool $raw = false, $start = null, $end = null) - 从 Decipher 获取传递到 $fields 的问题 ID 的响应。注意:uuid 和状态字段始终返回。
    将 $raw 设置为 true 将返回原始 Guzzle 响应对象,而不是 $response->getBody()。
    $start 和 $end 可以设置为 ISO 8601 格式的日期字符串(例如,使用 Carbons 的 toIso8601ZuluString() 方法),以限制返回的响应的日期范围。
    使用 ::setCondition() 设置的任何条件都将应用。
  • getSurveyFile(string $filename) - 作为字符串检索名为 $filename 的调查文件。