Giter Site home page Giter Site logo

php_surveygizmo_api's Introduction

Official PHP library for SurveyGizmo API

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock

Summary

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).

Requirements

  • PHP 5.3+
  • cURL
  • Active SurveyGizmo Account

Recommended Installation

This library is now available in packagist, and you can include surveygizmo/surveygizmo-api in your composer configuration files to autoload it:

$ 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

Manual Installation

  1. Download the library and add it to your project.
  2. Include the SurveyGizmoAutoLoader.php file, replacing <LIBRARY_PATH> with the appropriate path.
require_once "<LIBRARY_PATH>/SurveyGizmoAutoLoader.php";

Configuration

  1. If you are not using our US data center, you will need to choose the appropriate region (US, CA, or EU). If you are not sure if you are using the US, EU, or CA API, see: https://apihelp.surveygizmo.com/help/us-eu-or-ca-api
try {
	\SurveyGizmo\SurveyGizmoAPI::setRegion('EU');
} catch (Exception $e) {
	die('Region not available');
}
  1. Authenticate using your SurveyGizmo API Key and Secret.
try {
	\SurveyGizmo\SurveyGizmoAPI::auth("<YOUR API_KEY>", "<YOUR API_SECRET>");
} catch (Exception $e) {
	die("Error Authenticating");
}
  1. If needed, configure rate limiting.
//set max retries of requests to 10, when request is rate limited it will be retried after 5 seconds.
\SurveyGizmo\ApiRequest::setRepeatRateLimitedRequest(10);
  1. If needed, configure the request timeout duration (in seconds, defaults to 35 if not specified)
//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);

Code Samples

Please refer to the Samples folder for more thorough example use cases.

To use these samples, copy the example file and then supply your own credentials:

$ 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
Supported Objects
  • Survey
    • Responses
    • Questions
    • Pages
    • Statistics
    • Reports
    • Campaigns
      • EmailMessages
  • Account
    • Users
    • Teams
  • Contacts
  • ContactLists
    • Contacts

API Object Reference

This Library uses the version 5 SurveyGizmo API, please refer to our API Documentation for more information.

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

Surveys

Fetching Surveys

See filter and paging below.

$surveys = \SurveyGizmo\Resources\Survey::fetch(<FILTER>,<OPTIONS>);
Getting a Single Survey
$survey_id = <SURVEY_ID>;
$survey = \SurveyGizmo\Resources\Survey::get(survey_id);
Updating a Survey
$survey->title = "TEST UPDATE FROM API LIBRARY";
$survey->save();
Creating a Survey
$survey = new \SurveyGizmo\Resources\Survey();
$survey->title = "NEW SURVEY";
$results = $survey->save();
Deleting a Survey
$survey = $survey->delete();

Survey Helper Functions

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->getStatisticsByID($question_id);
	//get campaigns
	$survey->getCampaigns();
	$survey->getCampaign($id);
	//get email messages
	$survey->getCampaign($id)->getEmailMessages();
	$survey->getCampaign($id)->getEmailMessage($email_id);

Questions

To access the questions on a survey you'll need an instance of a \SurveyGizmo\Resources\Survey object.

Get all Survey Questions
$questions = $survey->getQuestions();
Getting and Updating a Survey Question
$question = $survey->getQuestion(<QUESTION question_id>);
$question->title->English = "LIBRARY TEST";
$ret = $question->save();

Responses

To access the responses for a survey you'll need an instance of a \SurveyGizmo\Resources\Survey object. See filter and paging below.

Get all Survey Responses
$responses = $survey->getResponses(<FILTER>,<OPTIONS>);
Get a Single Responses
$responses = $survey->getResponse(<RESPONSE_ID);
Update a Responses
$response->survey_data[$question_id]['answer'] = 'YES';
$ret = $response->save();

Filtering & Paging Objects

All fetch methods take both optional $filter and $options arguments.

Filtering
$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);
Paging Collections

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);

Error Messages & Responses

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)

Simple API request

To perform a API call without going through a specific resource class, use \SurveyGizmo\ApiRequest::call.

$response = \SurveyGizmo\ApiRequest::call('contactlist', null, null, null);

Tests

Unit tests are included under the /Tests directory. They can be run by calling PHPUnit within the Tests folder:

$ phpunit

Contributors

The library was developed and is maintained by the SurveyGizmo Development Team.

License

This project is licensed under the terms of the MIT license.

php_surveygizmo_api's People

Contributors

amcastror avatar burnhamrobertp avatar gonzie avatar surveygizmoofficial avatar wvdongen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

php_surveygizmo_api's Issues

[BUG] Filtering Issue on URL variable

Can't filter survey responses by URL variable.

Here is sample code

require_once "../PHP_SurveyGizmo_Api-master/SurveyGizmoAutoLoader.php";
$surveyId=$argv[1];


//Set Region
try {
        \SurveyGizmo\SurveyGizmoAPI::setRegion('EU');
} catch (Exception $e) {
        $agi->verbose("Region Not Avaliable $e");
}


//Auth
try {
        \SurveyGizmo\SurveyGizmoAPI::auth("xxxxxxxxxxxxxxx", "xxxxxx");
} catch (Exception $e) {
#       $agi->verbose("Authentication ERROR $e");
echo "Authentication ERROR $e";
}




try {


$survey = \SurveyGizmo\Resources\Survey::get($surveyId);


$filter = new \SurveyGizmo\Helpers\Filter();
$filter_item = new \SurveyGizmo\Helpers\FilterItem();

$filter_item->setField("url(\"uid\")");
$filter_item->setOperator('=');
$filter_item->setCondition("10020");
$filter->addFilterItem($filter_item);


$options = null; #array( 'page' => 1, 'limit' => 1 );

$surveys = \SurveyGizmo\Resources\Survey::fetch($filter);

print_r($filter);

echo "****************\n";


$responses = $survey->getResponses($filter,$options);
print_r($responses);


} catch (Exception $e) {

        echo "General ERROR, $e";
}

It returns all responses from survey

SurveyGizmo Grid question types

Hi,

I've been trying to figure out how to use this Library to create Table-radio, Table-checkbox etc. I can add the options (Columns) but cannot seem to add the Rows (sub_questions), please help?

Best,
Vincent

[ENHANCEMENT] Configurable API Request Timeout Duration

Is your feature request related to a problem? Please describe.
There is an artificial timeout set within the ApiRequest library within your SDK.

It is hardcoded to timeout after 35 seconds: https://github.com/SurveyGizmoOfficial/PHP_SurveyGizmo_Api/blob/master/ApiRequest.php#L134

SurveyGizmo's API response times have degraded in the past 6 months to far past 35 seconds, causing the SDK in the end to return a fully "nulled out" response.

Describe the solution you'd like
Set the timeout to an option or at least perhaps a static class property to modify.

Describe alternatives you've considered
I modified our SDK directly to just set the timeout to unlimited.

Additional context
https://github.com/SurveyGizmoOfficial/PHP_SurveyGizmo_Api/blob/master/ApiRequest.php#L134

Bug get surveys

Hi, I'm following the example to get surveys filtered by title, and I get the following error:

screen shot 2018-02-21 at 7 35 56 pm

My code is very simple:

require __DIR__ . '/../vendor/autoload.php';

try {
	\SurveyGizmo\SurveyGizmoAPI::auth("key", "secret");
} catch (Exception $e) {
	dump("Error Authenticating");
}

$filter = new \SurveyGizmo\Helpers\Filter();
$filter_item = new \SurveyGizmo\Helpers\FilterItem();
$filter_item->setField('title');
$filter_item->setOperator('=');
$filter_item->setCondition('test');
$filter->addFilterItem($filter_item);
$surveys = \SurveyGizmo\Resources\Survey::fetch($filter);

dump($surveys);

Am I doing something wrong? Thanks a lot.

PS: this are my dependencies:

{
    "repositories": [
    ],
    "autoload": {
        "psr-4": {"": "src/"}
    },
    "require": {
  		"surveygizmo/surveygizmo-api": "^1.0",
  		"symfony/var-dumper": "~3.2"
    }
}

SurveyGizmo api integration

Hi,

I'm trying to integrate this library to my internal system but I've kind of hit a brick wall. Is there like a function to use in adding survey questions after creating a new survey?

regards,
Vincent

getResponses function in Survey

Cannot pass the $page to getResponses function in Survey and $filter is useless in this function.
public function getResponses($filter = null)
{
return $this->getSubObjects("SurveyGizmo\Resources\Survey\Response");
}

Updating surveyoption requireother v5 not working

Hi, I am trying to update a surveyoption's requireother = true.
var texturl = "https://restapi.surveygizmo.com/v5/survey/4162127/surveyquestion/27/surveyoption/10048?"+api_str+"&_method=POST"
var o = {
'properties[requireother]' : 'True',
'properties[na]' : 'False'
};
$.post(texturl, // url
o, // data to be submit
function(data, status, jqXHR) {// success callback
console.log("data",JSON.stringify(data));
//$('p').append('status: ' + status + ', data: ' + data);
},"jsonp")
The data fetched back is {"result_ok":true,"data":{"id":10048,"title":{"English":"toto specify"},"value":"2","properties":{"disabled":false,"piping_exclude":"false","show_rules":null,"show_rules_logic_map":":5c80a55dbe3d5,5c80a55dbe489,5c80a55dbe489","na":"False","requireother":"True","other":false}}}

But my surveyoption is still not requireother.
Please kindly help.

Packagist Release?

We currently have a client with an immediate need to integrate with the SurveyGizmo API, but I noticed that this SDK has not yet been published to Packagist (although there seems to have been some work on the Composer file).

Is this something planned for the near future?

If not, I would be happy to assist or provide guidance on releasing and managing an official Composer package.

Response Fetch

The fetch function in Response, $filter should be changed to $filters.

public static function fetch($survey_id, $filters = null, $options = null) {
if ($survey_id < 1) {
throw new SurveyGizmoException(500, "Missing survey ID");
}
$response = self::_fetch(array('id' => '', 'survey_id' => $survey_id), $filter, $options);
return $response;
}

How to post survey answer to surverygizmo server

Hi,
I have implemented your code to my site, which is developed in PHP. I am able to fetch servery question form using \SurveyGizmo\Resources\Survey::get($survey_id); method, but how do I post user submitted answers to surveygizmo server. Kindly give me some guide line.

Thanks,
Ankit Kumar

[ENHANCEMENT] setting the Metaonly flag

Hi,
I can't find a way to set the flag "metaonly" when requesting a survey.

I think it would be sufficient if you could set the flag with the options parameter in the ApiRequest::call methode.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.