director-moav / the-kof-client
TheKofClient 是 SurveyMonkey API 的 PHP 客户端。编写时考虑了直观使用。
Requires
- php: >=7.2.0
README
TheKofClient
A PHP client for Survey Monkey API V3 https://developer.surveymonkey.com/api/v3/ Project started 7/11/2017
评论、补丁和支持请求可以通过 github 发送。
当前版本:0.01
目录
-
安装和配置
- 依赖项
- 安装
-
API 快速介绍
- 简介
- 调查
- 收集者
- 响应
-
类和方法
-
示例
安装和配置
依赖项
-
TheKofClient 使用 Zend Framework > 2.x HTTP 客户端与 SurveyMonkey 服务器通信。
此客户端的后续版本可能会支持更通用的通信方式。 -
虽然 TheKofClient 是 TalisMS 库的一部分,但只是名义上如此。它遵循相同的命名约定。但是,它是一个独立的项目。
-
在 SurveyMonkey 上拥有权限构建应用的账户。
-
在 SurveyMonkey 上定义的应用,拥有所需的权限(在使用此客户端之前,建议您熟悉 SurveyMonkey APP 和 API 使用)。
-
访问令牌,从您的应用设置屏幕复制,如下所示
P4BCgR2bIBdtj10AKrCX9sVRx.DHaoYcMgKFMAROePyn.IxS5H8Bovv4pj98M3N0xvIKVxW00o12at-mSgIzGiRR3TSPcVks4TBHp3nCxyd9Kv6Z9OFlrKD1O8UXFsXb
安装
使用 TalisMS
复制此项目中的 TheKof/src
文件夹,并将其放置在
作为独立库使用自动加载器
将 source/Talis
添加到您的 PHP 包含路径。
如果使用自动加载器,则应将命名空间分隔符 \ 和下划线 _ 转换为 URL 路径分隔符 /
并在末尾添加 .php
示例:类 \TheKof\SurveyMonkeyClient
将这样包含
require_once('Talis/Extensions/TheKof/SurveyMonkeyClient.php');
作为独立库使用简单包含
为此,将文件 boundle/thekofclient.php
复制到您的项目中,并执行 require_once(path/to/thekofclient.php)
。
API 快速介绍
简介
TheKofClient 旨在尽可能地模仿 API 本身,尽可能地自我说明,并有一个简单的入口点。以下示例是客户端使用的快速示例以及它们所做和返回的(非常简短的)解释。这些不是工作示例,目的是仅展示 API。有关工作示例,请查看 examples
文件夹。...
表示各种参数。
调查
fetch 所有您的调查。请确保您已在 Surveymonkey 应用仪表板中设置了正确的权限(范围:查看调查)
use \TheKof;
$Client = new SurveyMonkeyClient(...);
$surveys_list = $Client->surveys()->get(); //returns a collection (iterable) of your surveys. Defaults to page size of 100 (i.e. the first 100 surveys you own).
$surveys_list = $Client->surveys()->get(2,10); //returns a collection (iterable) of your surveys. Page 2 where page size is 10 surveys
$one_survey = $Client->surveys(survey_id)->get();//return survey object for survey id=survey_id
$collectors_list = $Client->surveys(survey_id)->collectors()->get();//return collection of Survey Collectors for survey id=survey_id, again, same paging rules as above apply
$one_collector = $Client->surveys(survey_id)->collectors(collector_id)->get(); //return a collector object for collector id = collector_id
dry 每个方法都有一个 *_dry()
版本,可以在没有 HTTP 客户端的情况下使用,并返回表示请求的数据结构(URL/标题/正文)
$Client = new SurveyMonkeyClient(...);
$surveys_list_request_data = $Client->surveys()->get_dry();
$surveys_list_request_data = $Client->surveys()->get_dry(2,10);
$one_survey_request_data = $Client->surveys(survey_id)->get_dry();
$collectors_list_request_data = $Client->surveys(survey_id)->collectors()->get_dry();
$one_collector_request_data = $Client->surveys(survey_id)->collectors(collector_id)->get_dry();