コード例 #1
0
 public function register(Application $app)
 {
     $app['spotify.api'] = $app->share(function () use($app) {
         $api = new ThirdPartApi();
         if (!($auth_token = $app['predis']->get('spotify:auth'))) {
             $session = new \SpotifyWebAPI\Session(Credentials::CLIENT_ID, Credentials::CLIENT_SECRET, '');
             $session->requestCredentialsToken(array());
             $auth_token = $session->getAccessToken();
             $app['predis']->set('spotify:auth', $auth_token);
             $app['predis']->expire('spotify:auth', $session->getExpires() - 60);
         }
         $api->setAccessToken($auth_token);
         return new RuntimeCacheDecorator(new SpotifyApi($api));
     });
 }