Official PHP library for SurveyGizmo API
The library is intended to make integrating with SurveyGizmo easier and quicker than using the API directly. The following objects are supported via this library and are all namespaced under SurveyGizmo (e.g. \SurveyGizmo\Resources\Survey)., (*2)
This library is now available in packagist, and you can include surveygizmo/surveygizmo-api in your composer configuration files to autoload it:, (*3)
$ composer require surveygizmo/surveygizmo-api Using version ^1.0 for surveygizmo/surveygizmo-api ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing surveygizmo/surveygizmo-api (v1.0.3-stable): Loading from cache Writing lock file Generating autoload files
<LIBRARY_PATH>
with the appropriate path.require_once "<LIBRARY_PATH>/SurveyGizmoAutoLoader.php";
try { \SurveyGizmo\SurveyGizmoAPI::setRegion('EU'); } catch (Exception $e) { die('Region not available'); }
try { \SurveyGizmo\SurveyGizmoAPI::auth("<YOUR API_KEY>", "<YOUR API_SECRET>"); } catch (Exception $e) { die("Error Authenticating"); }
//set max retries of requests to 10, when request is rate limited it will be retried after 5 seconds. \SurveyGizmo\ApiRequest::setRepeatRateLimitedRequest(10);
//this is the maximum wait period before aborting requests, you may need to //increase this from the default of 35 seconds if working with oversize surveys \SurveyGizmo\ApiRequest::setRequestTimeout(60);
Please refer to the Samples folder for more thorough example use cases., (*4)
To use these samples, copy the example file and then supply your own credentials:, (*5)
$ cd Samples $ cp .credentials.example .credentials $ vi .credentials # then supply your credentials accordingly $ php new_survey.php # run once prior to running manipulate_survey.php $ php manipulate_survey.php
This Library uses the version 5 SurveyGizmo API, please refer to our API Documentation for more information., (*6)
<OBJECT>::fetch(<FILTERS>,<OPTIONS>);
Returns an array of objects based on filter and paging options., (*7)
<OBJECT>::get($id);
Returns a single object based on id, (*8)
<OBJECT>->save();
Saves a newly created or updated instance of an object, (*9)
<OBJECT>->delete();
Deletes an instance of an object, (*10)
See filter and paging below., (*11)
$surveys = \SurveyGizmo\Resources\Survey::fetch(<FILTER>,<OPTIONS>);
$survey_id = <SURVEY_ID>; $survey = \SurveyGizmo\Resources\Survey::get(survey_id);
$survey->title = "TEST UPDATE FROM API LIBRARY"; $survey->save();
$survey = new \SurveyGizmo\Resources\Survey(); $survey->title = "NEW SURVEY"; $results = $survey->save();
$survey = $survey->delete();
The Survey object provides a few help functions to easily access related collections and objects., (*12)
//get questions $survey->getQuestions(<FILTER>,<PAGE>); $survey->getQuestion($question_id); //get responses $survey->getResponses(<FILTER>,<PAGE>); $survey->getResponse($id); //get reports $survey->getReports(<FILTER>,<PAGE>); $survey->getReport($id); //get statistics $survey->getStatistics(); $survey->getStatisticsByID($question_id); //get campaigns $survey->getCampaigns(); $survey->getCampaign($id); //get email messages $survey->getCampaign($id)->getEmailMessages(); $survey->getCampaign($id)->getEmailMessage($email_id);
To access the questions on a survey you'll need an instance of a \SurveyGizmo\Resources\Survey object., (*13)
$questions = $survey->getQuestions();
$question = $survey->getQuestion(<QUESTION question_id>); $question->title->English = "LIBRARY TEST"; $ret = $question->save();
To access the responses for a survey you'll need an instance of a \SurveyGizmo\Resources\Survey object. See filter and paging below., (*14)
$responses = $survey->getResponses(<FILTER>,<OPTIONS>);
$responses = $survey->getResponse(<RESPONSE_ID);
$response->survey_data[$question_id]['answer'] = 'YES'; $ret = $response->save();
All fetch methods take both optional $filter and $options arguments., (*15)
$filter = new \SurveyGizmo\Helpers\Filter(); $filter_item = new \SurveyGizmo\Helpers\FilterItem(); $filter_item->setField('title'); $filter_item->setOperator('='); $filter_item->setCondition('TEST from API'); $filter->addFilterItem($filter_item); $surveys = \SurveyGizmo\Resources\Survey::fetch($filter);
Sometimes you will need to page through collections of objects. To accommodate this use the optional $options argument on any fetch method;, (*16)
$options = array( 'page' => 3, 'limit' => 100 ); $surveys = \SurveyGizmo\Resources\Survey::fetch($filter,$options);
In the case of an error we will return the following responses and status codes:, (*17)
Method not implemented (404) Method not supported (405) Not Authorized (401)
To perform a API call without going through a specific resource class, use \SurveyGizmo\ApiRequest::call., (*18)
$response = \SurveyGizmo\ApiRequest::call('contactlist', null, null, null);
Unit tests are included under the /Tests
directory. They can be run by calling PHPUnit within the Tests folder:, (*19)
$ phpunit
The library was developed and is maintained by the SurveyGizmo Development Team., (*20)
This project is licensed under the terms of the MIT license., (*21)