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 (eg; SurveyGizmo\Resources\Survey).
- Survey
- Responses
- Questions
- Pages
- Statistics
- Reports
- Campaigns
- EmailMessages
- Account
- Users
- Teams
- Contacts
- ContactLists
- Contacts
####All objects use the following standard functions:
<OBJECT>::fetch(<FILTERS>,<OPTIONS>);
Returns an array of objects based on filter and paging options.
<OBJECT>::get($id);
Returns a single object based on id
<OBJECT>->save();
Saves a newly created or updated instance of an object
<OBJECT>->delete();
Deletes an instance of an object
require_once "<LIBRARY_PATH>/SurveyGizmoAutoLoader.php";
//set your key & secret
$api_key = "<YOUR API_KEY>";
$api_secret = "<YOUR API_SECRET>";
try {
$sg = SurveyGizmo\SurveyGizmoAPI::auth($api_key,$api_secret);
} catch (Exception $e) {
die("Error Authenticating");
}
See filter and paging below.
$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.
//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->getQuestionStatistics($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.
$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.
$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.
$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;
$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:
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.
$response = SurveyGizmo\ApiRequest::call('contactlist', null, null, null);
PHP 5.3+
CURL
Active SurveyGizmo Account
Imagination, Determination and Common Sense!
- Download the Library and add it to your project.
- Include the SurveyGizmoAutoLoader.php file
require_once "<LIBRARY_PATH>/SurveyGizmoAutoLoader.php";
- Authenticate using your SurveyGizmo API Key and Secret.
//set your key & secret
$api_key = "<YOUR API_KEY>";
$api_secret = "<YOUR API_SECRET>";
try {
$sg = SurveyGizmo\SurveyGizmoAPI::auth($api_key,$api_secret);
} catch (Exception $e) {
die("Error Authenticating");
}
This Library uses the version 5 SurveyGizmo API. API Documentation.
Unit tests are included under the /Tests directory. They can be executed by running:
$ phpunit -c bootstrap.xml
The library was developed and is maintained by the SurveyGizmo Product Development Team.
This project is licensed under the terms of the MIT license.