Inheritance: extends RESTfulService
Ejemplo n.º 1
0
 /**
  * Handle the event.
  *
  * @param SongLikeToggled $event
  */
 public function handle(SongLikeToggled $event)
 {
     if (!$this->lastfm->enabled() || !($sessionKey = $event->user->lastfm_session_key) || $event->interaction->song->album->artist->isUnknown()) {
         return;
     }
     $this->lastfm->toggleLoveTrack($event->interaction->song->title, $event->interaction->song->album->artist->name, $sessionKey, $event->interaction->liked);
 }
Ejemplo n.º 2
0
 /**
  * Handle the event.
  *
  * @param SongStartedPlaying $event
  */
 public function handle(SongStartedPlaying $event)
 {
     if (!$this->lastfm->enabled() || !($sessionKey = $event->user->getLastfmSessionKey()) || $event->song->album->artist->isUnknown()) {
         return;
     }
     $this->lastfm->updateNowPlaying($event->song->album->artist->name, $event->song->title, $event->song->album->name === Album::UNKNOWN_NAME ? null : $event->song->album->name, $event->song->length, $sessionKey);
 }
Ejemplo n.º 3
0
 /**
  * Serve the callback request from Last.fm.
  *
  * @param Request $request
  * @param Lastfm  $lastfm
  *
  * @return \Illuminate\Http\Response
  */
 public function callback(Request $request, Lastfm $lastfm)
 {
     abort_unless($token = $request->input('token'), 500, 'Something wrong happened.');
     // Get the session key using the obtained token.
     abort_unless($sessionKey = $lastfm->getSessionKey($token), 500, 'Invalid token key.');
     $this->auth->user()->savePreference('lastfm_session_key', $sessionKey);
     return view('api.lastfm.callback');
 }
 public function testGetSessionKey()
 {
     $client = m::mock(Client::class, ['get' => new Response(200, [], file_get_contents(dirname(__FILE__) . '/blobs/lastfm/session-key.xml'))]);
     $api = new Lastfm(null, null, $client);
     $this->assertEquals('foo', $api->getSessionKey('bar'));
 }