From 928b9131e917001b6da8a9d1bd11c729cab4d41d Mon Sep 17 00:00:00 2001 From: Yaacov Date: Tue, 6 Nov 2018 18:24:54 +0100 Subject: [PATCH] Add Typeform TODO: unit tests --- README.md | 1 + examples/init.example.php | 5 ++++ examples/typeform.php | 53 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 examples/typeform.php diff --git a/README.md b/README.md index 2eebab78..d0779d94 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Included service implementations - SoundCloud - Spotify - Strava + - Typeform - Ustream - Vimeo - Vkontakte diff --git a/examples/init.example.php b/examples/init.example.php index 6ab1cdb0..bb2bd146 100644 --- a/examples/init.example.php +++ b/examples/init.example.php @@ -190,6 +190,11 @@ 'key' => '', 'secret' => '', ), + 'typeform' => array( + 'key' => '', + 'secret' => '', + 'form_id' => '' + ), 'ustream' => array( 'key' => '', 'secret' => '', diff --git a/examples/typeform.php b/examples/typeform.php new file mode 100644 index 00000000..473e2e51 --- /dev/null +++ b/examples/typeform.php @@ -0,0 +1,53 @@ + + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ +use OAuth\OAuth2\Service\Typeform; +use OAuth\Common\Storage\Session; +use OAuth\Common\Consumer\Credentials; + +/** + * Bootstrap the example + */ +require_once __DIR__ . '/bootstrap.php'; + +// Session storage +$storage = new Session(); + +// Setup the credentials for the requests +$credentials = new Credentials( + $servicesCredentials['typeform']['key'], + $servicesCredentials['typeform']['secret'], + $currentUri->getAbsoluteUri() +); + +$form_id = $servicesCredentials['form_id']; + +// Instantiate the Typeform service using the credentials, http client and storage mechanism for the token +/** @var $typeformService Typeform */ +$typeformService = $serviceFactory->createService('typeform', $credentials, $storage); +if (!empty($_GET['code'])) { + + // This was a callback request from Typeform, get the token + $typeformService->requestAccessToken($_GET['code']); + + // Send a request with it + $result = json_decode($typeformService->request("/forms/$form_id/responses"), true); + + // Show some of the resultant data + echo 'Total items: ' . $result['total_items']; + +} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { + + $url = $typeformService->getAuthorizationUri(); + header('Location: ' . $url); +} else { + + $url = $currentUri->getRelativeUri() . '?go=go'; + echo "Login with Typeform!"; +}