// Deps
var utils = require('../utils');
var config = require('../config');
var Acuity = require('../../');


// App:
var app = utils.express({views: __dirname}); 


// Router:
app.get('/', function (req, res) {
  res.render('index.html');
});

app.get('/authorize', function (req, res) {
	// Redirect the user to the Acuity authorization endpoint.  You must
	// choose a scope to work with.
  var acuity = Acuity.oauth(config);
  acuity.authorizeRedirect(res, {scope: 'api-v1'});
});

app.get('/oauth2', function (req, res) {

  var options = Object.create(config);
  options.accessToken = config.accessToken || req.session.accessToken;
  var acuity = Acuity.oauth(options);
  var response = res;
  var query = req.query;

  if (!query.code || query.error) {
    response.render('oauth2.html', {
      error: query.error,
      query: JSON.stringify(query, null, '  ')
    });
  }

	// 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.
  acuity.requestAccessToken(query.code, function (err, tokenResponse) {

    if (err) return console.error(err);

    // Store that access token somewhere:
    if (tokenResponse.access_token) {
      req.session.accessToken = tokenResponse.access_token;
    }

    // Make a sample request:
    acuity.request('me', function (err, res, me) {

      if (err) return console.error(err);

      response.render('oauth2.html', {
        query: JSON.stringify(query, null, '  '),
        tokenResponse: JSON.stringify(tokenResponse, null, '  '),
        me: JSON.stringify(me, null, '  ')
      });
    });
  });
});


// Server:
var server = utils.start(app);

@@ -282,17 +282,18 @@
  res) %7B%0A
-%09
+  
 // Redir
@@ -353,17 +353,18 @@
 ou must%0A
-%09
+  
 // choos
@@ -878,17 +878,18 @@
 );%0A  %7D%0A%0A
-%09
+  
 // Excha
@@ -906,18 +906,18 @@
 thorizat
-o
 i
+o
 n code f
@@ -952,9 +952,10 @@
  it%0A
-%09
+  
 // s

Fix typos in sample oauth example