Пример #1
0
<?php

require_once __DIR__ . '/../../src/AcuitySchedulingOAuth.php';
// OAuth Version
require_once '../utils.php';
// Config:
$config = loadConfig();
list($method, $path) = getRouteInfo();
// Instantiate OAuth API class.  Once we have connected to Acuity,
// we'll store the accessToken in the session for future page visits.
$acuity = new AcuitySchedulingOAuth(array('accessToken' => $_SESSION['accessToken'], 'clientId' => $config['clientId'], 'clientSecret' => $config['clientSecret'], 'redirectUri' => $config['redirectUri'], 'base' => $config['base']));
// Example app:
if ($method === 'GET' && $path === '/') {
    include 'index.html';
    // If we're already connected, make a request:
    $response = $acuity->request('me');
    echo '<h1>GET /api/v1/me:</h1>';
    echo '<pre>';
    print_r($response);
    echo '</pre>';
} else {
    if ($method === 'GET' && $path === '/authorize') {
        // Redirect the user to the Acuity authorization endpoint.  You must
        // choose a scope to work with.
        $acuity->authorizeRedirect(array('scope' => 'api-v1'));
    } else {
        if ($method === 'GET' && $path === '/oauth2') {
            // Exchange the authorizatoin code for an access token and store it
            // somewhere.  You'll need to pass it to the AcuitySchedulingOAuth
            // constructor to make calls later on.
            $tokenResponse = $acuity->requestAccessToken($_GET['code']);
<?php

require_once 'vendor/autoload.php';
require_once 'config.php';
ini_set('session.save_path', '');
session_start();
// Acuity OAuth Connection
$acuity = new AcuitySchedulingOAuth(['accessToken' => $_SESSION['acuityAccessToken'], 'clientId' => CLIENT_ID, 'clientSecret' => CLIENT_SECRET, 'redirectUri' => REDIRECT_URI]);
// Router:
$method = $_SERVER['REQUEST_METHOD'];
$path = $_SERVER['PATH_INFO'] ? $_SERVER['PATH_INFO'] : '/';
if ($method === 'GET' && $path === '/') {
    if ($acuity->isConnected()) {
        $me = $acuity->request('me');
        $today = strftime('%Y-%m-%d');
        $agenda = $acuity->request('appointments', ['query' => ['minDate' => $today, 'maxDate' => $today]]);
    } else {
        $authorizationUrl = $acuity->getAuthorizeUrl(['scope' => 'api-v1']);
    }
    include 'templates/index.tpl.php';
} else {
    if ($method === 'GET' && $path === '/oauth2') {
        $response = $acuity->requestAccessToken($_GET['code']);
        $accessToken = $response['access_token'];
        if ($accessToken) {
            $_SESSION['acuityAccessToken'] = $accessToken;
            header('Location: /');
        }
    } else {
        if ($method === 'GET' && $path === '/disconnect') {
            session_destroy();