示例#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));
     });
 }
示例#2
0
 public function testRequestCredentialsToken()
 {
     $expected = array('grant_type' => 'client_credentials', 'scope' => 'user-read-email');
     $headers = array('Authorization' => 'Basic Yjc3NzI5MmFmMGRlZjIyZjkyNTc5OTFmYzc3MGI1MjA6NmEwNDE5ZjQzZDBhYTkzYjJhZTg4MTQyOWI2YjliYzI=');
     $return = array('body' => get_fixture('access-token'));
     $stub = $this->setupStub('POST', '/api/token', $expected, $headers, $return);
     $session = new SpotifyWebAPI\Session($this->clientID, $this->clientSecret, $this->redirectURI, $stub);
     $result = $session->requestCredentialsToken(array('user-read-email'));
     $this->assertTrue($result);
     $this->assertNotEmpty($session->getAccessToken());
     $this->assertEquals(time() + 3600, $session->getTokenExpiration());
 }