Example #1
0
 /**
  * Test the Bundle::prefix method.
  *
  * @group laravel
  */
 public function testPrefixMethodReturnsCorrectPrefix()
 {
     $this->assertEquals('dummy::', Bundle::prefix('dummy'));
     $this->assertEquals('', Bundle::prefix(DEFAULT_BUNDLE));
 }
Example #2
0
<?php

/**
 * @link https://github.com/lordcoste/analytics-s2s
 * @author Colao Stefano < *****@*****.** >
 */
const BUNDLE_NAME = 'analytics-s2s';
Autoloader::map(array('Analytics' => Bundle::path(BUNDLE_NAME) . 'Analytics.php', 'AnalyticsService' => Bundle::path(BUNDLE_NAME) . 'AnalyticsService.php', 'Google_Client' => Bundle::path(BUNDLE_NAME) . 'google-api' . DS . 'Google_Client.php', 'Google_AnalyticsService' => Bundle::path(BUNDLE_NAME) . 'google-api' . DS . 'contrib' . DS . 'Google_AnalyticsService.php'));
IoC::singleton('google-analytics', function () {
    $prefix = Bundle::prefix(BUNDLE_NAME);
    if (!File::exists(Config::get($prefix . 'google.certificate_path'))) {
        throw new Exception("Can't find the .p12 certificate in: " . Config::get($prefix . 'google.certificate_path'));
    }
    $config = array('oauth2_client_id' => Config::get($prefix . 'google.client_id'), 'use_objects' => Config::get($prefix . 'google.use_objects'));
    $google = new Google_Client($config);
    $google->setAccessType('offline');
    $google->setAssertionCredentials(new Google_AssertionCredentials(Config::get($prefix . 'google.service_email'), array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents(Config::get($prefix . 'google.certificate_path'))));
    return new AnalyticsService($google);
});
Analytics::init(IoC::resolve('google-analytics'));
    $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');
    } 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');
    }
});