-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathroutes.php
executable file
·96 lines (82 loc) · 2.6 KB
/
routes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @author Andrew Zappella < http://www.suisseo.ch/ >
* @copyright 2012 Suisseo SARL
* @license http://creativecommons.org/licenses/by-sa/3.0/
* @package Google API PHP Client (Laravel Bundle)
* @version 0.2.1 - 2013-03-17
*/
require_once __DIR__.'/google-api-php-client.php';
Route::get('(:bundle)', function()
{
$google = IoC::resolve('google-api-php-client');
if ( Input::has('code') )
{
$google->authenticate();
Session::put('token', $google->getAccessToken());
return Redirect::to('google-api');
}
if ( Session::has('token') )
{
$google->setAccessToken(Session::get('token'));
return View::make(Bundle::prefix(BUNDLE_NAME).'index')->with('services', Google::services());
}
if ( $google->getAccessToken() )
{
Session::put('token', $google->getAccessToken());
return View::make(Bundle::prefix(BUNDLE_NAME).'index')->with('services', Google::services());
}
// if token is not set, print Google API Auth link
else
{
$data = array(
'google_auth_url' => $google->createAuthUrl());
return View::make(Bundle::prefix(BUNDLE_NAME).'index', $data);
}
});
Route::get('(:bundle)/(:any)', function($service)
{
$google = IoC::resolve('google-api-php-client');
$class_name = 'Google_'.ucfirst($service).'Service';
$class_file = $class_name . ".php";
$classes = Google::services();
if ( Session::has('token') )
{
$google->setAccessToken(Session::get('token'));
try {
if (in_array($class_file, $classes)) {
$service = new $class_name($google);
}
else {
throw new Exception('Google API Service not found');
}
} catch (apiServiceException $e) {
print 'There was an API service error '
. $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
print 'There was a general API error '
. $e->getCode() . ':' . $e->getMessage();
} catch (Exception $e) {
print 'There was a general error '
. $e->getCode() . ':' . $e->getMessage();
}
}
if ( $google->getAccessToken() )
{
Session::put('token', $google->getAccessToken());
return View::make(Bundle::prefix(BUNDLE_NAME).'index');
}
// if token is not set, print Google API Auth link
else
{
$data = array('google_auth_url' => $google->createAuthUrl());
return View::make(Bundle::prefix(BUNDLE_NAME).'index', $data);
}
});
Route::get('(:bundle)/logout', function()
{
if ( Session::has('token') )
{
Session::forget('token');
}
});