/** Call an API method which needs to be signed. * * @param string $method API method to call. (Required) * @param array $params Request parameters to send. (Optional) * @param Session $session A session obtained by {@link de.felixbruns.lastfm.Auth#getSession Auth::getSession} or {@link de.felixbruns.lastfm.Auth#getMobileSession Auth::getMobileSession}. (Optional) * @param string $requestMethod Request-method for calling (defaults to 'GET'). (Optional) * @return SimpleXMLElement A SimpleXMLElement object. * * @access public */ public function signedCall($method, array $params = array(), $session = null, $requestMethod = 'GET') { /* Set call parameters */ $callParams = array('method' => $method, 'api_key' => $this->apiKey); /* If session is set, add session key */ if ($session != null) { $callParams['sk'] = $session->getKey(); } /* Add call parameters to other request parameters */ $params = array_merge($callParams, $params); $params = Util::toUTF8($params); /* Add API signature */ $params['api_sig'] = Auth::getApiSignature($params, $this->apiSecret); /* Call API */ return $this->internalCall($params, $requestMethod); }
/** * @test */ public function shouldGetLoggedOnUser() { // given if (Session::getInstance()->isSignedIn()) { Session::getInstance()->signOut(); } $username = '******'; $password = '******'; $this->createUser($username, $password); // when $login = new Session(); $login->signIn(array('username' => $username, 'password' => md5($password))); $this->mockCookie($login->getKey()); $user = $login->getUser(); // then $this->assertNotNull($user); $this->assertEquals(2, $user->getId()); $this->assertEquals("username", $user->getUsername()); $player = new CurrentPlayer(); $this->assertEquals($user->getValues(), $player->getValues()); }
/** * @covers AbiosGaming\Session::getKey */ public function testGetKey() { $this->getsData(200, '{"session_id":"FAKESESSION"}'); $session = new Session($this->api); $this->assertEquals($session->getKey(), 'FAKESESSION', 'The session key should be returned'); }
$app->response->setStatus(200); Helpers::sendJson(array('error' => array('error_code' => $e->getCode(), 'error_msg' => $e->getMessage()))); }); $app->notFound(function () use($app) { $app->response->setStatus(200); Helpers::sendJson(array('error' => array('error_code' => 404, 'error_msg' => 'Not Found'))); $app->stop(); }); $app->get('/login', function () use($app, $db, $session) { $code = $app->request->get('code'); $redirect_uri = $app->request->get('redirect_uri'); $client = Config::oauth(); $api = new Kneu\Api(); $token = $api->oauthToken($client['id'], $client['secret'], $code, $redirect_uri); $session->init($token, $api); Helpers::sendJson(array('token' => $session->getKey(), 'user_type' => $session->getUserType(), 'timeout' => $session->getTimeout(), 'is_test_completed' => $session->getUser()->getIsTestCompleted())); }); $app->get('/logout', function () use($session) { if (!checkAuth()) { return; } $status = $session->logout(); Helpers::sendJson(array('status' => $status)); }); $app->get('/answers', function () use($session) { if (!checkAuth()) { return; } Helpers::sendJson($session->getUser()->getAnswers()); }); $app->post('/answers', function () use($session) {
/** Fetch XSPF playlists using a last.fm playlist url. * * @param string $playlist A lastfm protocol playlist url ('lastfm://playlist/...'). (Required) * @param string $streaming Weather to fetch a playlist for streaming. (Optional) * @param string $fod Weather to fetch a playlist with free on demand tracks. (Optional) * @param Session $session A session obtained by {@link de.felixbruns.lastfm.Auth#getSession Auth::getSession} or {@link de.felixbruns.lastfm.Auth#getMobileSession Auth::getMobileSession}. (Optional) * @return Playlist A Playlist object. * * @static * @access public * @throws Error */ public static function fetch($playlist, $streaming = null, $fod = null, $session = null) { if ($session == null) { $xml = CallerFactory::getDefaultCaller()->call('playlist.fetch', array_filter(array('playlistURL' => $playlist, 'streaming' => $streaming, 'fod' => $fod))); } else { $xml = CallerFactory::getDefaultCaller()->call('playlist.fetch', array_filter(array('playlistURL' => $playlist, 'streaming' => $streaming, 'fod' => $fod, 'sk' => $session->getKey()))); } return Playlist::fromSimpleXMLElement($xml); }
public function save($userDetails) { parent::save($userDetails); $this->setDefaultValuesForNewPlayers(); $this->commit(); $rememberMe = isset($userDetails['rememberMe']) ? true : false; $session = new Session(); $session->signIn(array("username" => $this->getUsername(), "password" => $this->getPassword(), "rememberMe" => $rememberMe)); return array('token' => $session->getKey(), 'access' => $this->getUserAccess()); }