source of /modules/HarborAndSprout/Controllers/HarborController.php<?php namespace SproutModules\Karmabunny\HarborAndSprout\Controllers; use Exception; use LogicException; use SproutModules\Karmabunny\HarborAndSprout\Helpers\GoogleDriveApi; use SproutModules\Karmabunny\HarborAndSprout\Helpers\ShopifyApi; use Sprout\Controllers\Controller; use Sprout\Helpers\AdminAuth; use Sprout\Helpers\Notification; use Sprout\Helpers\Url; use Sprout\Helpers\View; class HarborController extends Controller { /** * Render Shopify API test form * Viewable from within dbtools * * @return void Echos HTML directly */ public function shopifyApiForm() { $view = new View('modules/HarborAndSprout/admin/shopify_api_form'); $view->methods = ShopifyApi::$methods; $view->output = ''; $view->output = print_r(json_decode(ShopifyApi ::request($_POST['method'], $_POST['endpoint'], $params), true), true); } echo $view->render(); } /** * Render Google Drive API test form * Viewable from within dbtools * * @return void Echos HTML directly */ public function driveApiForm() { $view = new View('modules/HarborAndSprout/admin/drive_api_form'); $view->output = ''; $view->connected = (bool) GoogleDriveApi::getToken(); try { $resp = GoogleDriveApi::apiRequest($_POST['method'], GoogleDriveApi::$domain . $_POST['endpoint'], $params); $view->output = print_r($resp, true); } catch (Exception $ex) { $view->output = $ex->getMessage(); } } if (empty($_POST['endpoint'])) $_POST['endpoint'] = '/files'; echo $view->render(); } /** * Render Google OAuth form * * @return void Redirects */ public function googleAuthConnect() { AdminAuth::checkLogin(); GoogleDriveApi::requestOauthCode(); } /** * Handle Oauth2 callback. Saves Oauth2 token * * @return void Redirects */ public function googleAuthAction() { AdminAuth::checkLogin(); if (isset($_GET['error'])) { Notification ::error(sprintf('Authentication error: %s', $_GET['error'])); } else { Notification::confirm('Connected'); GoogleDriveApi::saveOauthToken($_GET['code']); } Url::redirect('dbtools'); } }
|