Esempio n. 1
0
 /**
  * Retrieves the game by the specified name
  *
  * @param gameName
  *            - Name of the game that has to be fetched
  *
  * @return Game object containing the game which has been created
  */
 function getGameByName($gameName)
 {
     Util::throwExceptionIfNullOrBlank($gameName, "Game Name");
     $encodedGameName = Util::encodeParams($gameName);
     $objUtil = new Util($this->apiKey, $this->secretKey);
     try {
         $params = null;
         $headerParams = array();
         $queryParams = array();
         $signParams = $this->populateSignParams();
         $metaHeaders = $this->populateMetaHeaderParams();
         $headerParams = array_merge($signParams, $metaHeaders);
         $signParams['name'] = $gameName;
         $signature = urlencode($objUtil->sign($signParams));
         //die();
         $headerParams['signature'] = $signature;
         $contentType = $this->content_type;
         $accept = $this->accept;
         $baseURL = $this->url;
         $baseURL = $baseURL . "/" . $encodedGameName;
         $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams);
         $gameResponseObj = new GameResponseBuilder();
         $gameObj = $gameResponseObj->buildResponse($response->getResponse());
     } catch (App42Exception $e) {
         throw $e;
     } catch (Exception $e) {
         throw new App42Exception($e);
     }
     return $gameObj;
 }
Esempio n. 2
0
 /**
  * Deducts the score from users account for a particular Game
  *
  * @param gameName
  *            - Name of the game for which scores have to be deducted
  * @param gameUserName
  *            - The user for whom scores have to be deducted
  * @param gameScore
  *            - The scores that have to be deducted
  *
  * @return Game object containing the scores that has been deducted
  */
 function deductScore($gameName, $gameUserName, $gameScore)
 {
     Util::throwExceptionIfNullOrBlank($gameName, "Game Name");
     Util::throwExceptionIfNullOrBlank($gameUserName, "User Name");
     Util::throwExceptionIfNullOrBlank($gameScore, "Score");
     $objUtil = new Util($this->apiKey, $this->secretKey);
     try {
         $params = null;
         $headerParams = array();
         $queryParams = array();
         $signParams = $this->populateSignParams();
         $metaHeaders = $this->populateMetaHeaderParams();
         $headerParams = array_merge($signParams, $metaHeaders);
         $body = null;
         $body = '{"app42":{"game":{"name":"' . $gameName . '", "scores":{"score":{"userName":"******","value":"' . $gameScore . '"}}}}}';
         $signParams['body'] = $body;
         $signature = urlencode($objUtil->sign($signParams));
         //die();
         $headerParams['signature'] = $signature;
         $contentType = $this->content_type;
         $accept = $this->accept;
         $baseURL = $this->url;
         $baseURL = $baseURL . "/deduct";
         $response = RestClient::post($baseURL, $params, null, null, $contentType, $accept, $body, $headerParams);
         $gameResponseObj = new GameResponseBuilder();
         $gameObj = $gameResponseObj->buildResponse($response->getResponse());
     } catch (App42Exception $e) {
         throw $e;
     } catch (Exception $e) {
         throw new App42Exception($e);
     }
     return $gameObj;
 }