Giter VIP home page Giter VIP logo

surveygizmo-api-php's Introduction

SurveyGizmoApiWrapper

PHP wrapper for the SurveyGizmo REST API

Installing with Composer:

{
    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/spacenate/surveygizmo-api-php"
        }
    ],
    "require": {
        "spacenate/surveygizmo-api-php": "dev-master"
    }
}

A simple example

use spacenate\SurveyGizmoApiWrapper;

$sg = new SurveyGizmoApiWrapper($userId = "[email protected]", $secret = "5ebe2294ecd0e0f08eab7690d2a6ee69", $type = "md5");

if (!$sg->testCredentials()) {
    die("Poop! Failed to authenticate with the provided credentials.");
}

$filter = array(
    array("modifiedon", ">", "2015-01-01"),
    array("status", "=", "Launched")
);

$surveys = json_decode($sg->Survey->getList($page = 1, $limit = 10, $filter));
print_r($surveys);

Using OAuth

To use OAuth, you'll first need to provide an OAuth key, secret, and callback URL.

use spacenate\SurveyGizmoApiWrapper();

// Create wrapper object
$sg = new SurveyGizmoApiWrapper();

// Consumer key and secret obtained via SurveyGizmo OAuth Application Registration form
// Visit https://app.surveygizmo.com/account/restful-register while logged in to SurveyGizmo
$oauth_config = array(
    'consumer_key'    => 'aaaa0000aaaa0000aaaa0000',
    'consumer_secret' => 'bbbbb1111bbbb11111bbb1111',
    'oauth_callback'  => 'https://example.com'
);

// Use OAuth object's configure() method to add OAuth configuration
$sg->oauth->configure($oauth_config);

To obtain an access token, begin by getting a request token and directing the user to SurveyGizmo's Authorize page.

// Get a request token from SurveyGizmo -- Note that this is returned as an associative array!
$result = $sg->oauth->getRequestToken();

// Redirect User to SurveyGizmo Authorize page
if (isset($result["oauth_token"])) {
    header("Location: https://restapi.surveygizmo.com/head/oauth/authenticate?oauth_token=" . $result["oauth_token"]);
    die;
} else {
    die("Uh oh! Failed to get a request token from SurveyGizmo. Check your consumer key and secret.");
}

Once the user has authorized access, they will be sent to your callback URL with an oauth_token and oauth_verifier, which you can trade for an access token and secret.

// Grab parameters included when User is sent to callback URL
$oauth_token = $_GET['oauth_token'];
$oauth_verifier= $_GET['oauth_verifier'];

// Exchange for access token and secret -- Note that this is returned as an associative array!
$result = $sg->oauth->getAccessToken($oauth_token, $oauth_verifier);

// Yay credentials! Note that at this time, SurveyGizmo OAuth tokens *CANNOT* be revoked, so store these in a very safe place
$access_token = $result['oauth_token'];
$access_token_secret = $result['oauth_token_secret'];

To use an OAuth access token, use the setCredentials() method, specifying the "oauth" type.

$sg->setCredentials($access_token, $access_token_secret, $type = "oauth");

SurveyGizmo API Documentation

http://apihelp.surveygizmo.com/help

License

MIT

surveygizmo-api-php's People

Contributors

akhromium avatar spacenate avatar

Watchers

 avatar

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.