function deleteUser($gameName) { Util::throwExceptionIfNullOrBlank($gameName, "Game Name"); $encodedUserName = Util::encodeParams($gameName); $responseObj = new App42Response(); $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['gameName'] = $gameName; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/delete/" . $encodedUserName; $response = RestClient::delete($baseURL, $params, null, null, $contentType, $accept, $headerParams); $responseObj->setStrResponse($response->getResponse()); $responseObj->setResponseSuccess(true); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $responseObj; }
function getFacebookProfile($accessToken) { Util::throwExceptionIfNullOrBlank($accessToken, "Access Token"); $encodedAccessToken = Util::encodeParams($accessToken); $objUtil = new Util($this->apiKey, $this->secretKey); $body = null; try { $params = null; $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $signParams['accessToken'] = $accessToken; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/facebook/me/OAuth/" . $encodedAccessToken; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $socialResponseObj = new SocialResponseBuilder(); $socialObj = $socialResponseObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $socialObj; }
/** * Recommendations based on SlopeOne Algorithm for all Users * * @param howMany * - Specifies that how many recommendations have to be found * * @returns Recommender Object for all Users */ function slopeOneForAll($howMany) { Util::throwExceptionIfNullOrBlank($howMany, "How Many"); Util::throwExceptionIfHowManyNotValid($howMany, "How Many"); $encodedHowMany = Util::encodeParams($howMany); $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['howMany'] = $howMany; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/slopeOne/all/" . $encodedHowMany; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $recommendResponseObj = new RecommenderResponseBuilder(); $recommendObj = $recommendResponseObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $recommendObj; }
/** * Removes all the attributes for a given session id * * @param sessionId * - The session id for which the attributes has to be removed * * @return App42Response if removed successfully */ function removeAllAttributes($sessionId) { Util::throwExceptionIfNullOrBlank($sessionId, "session Id"); $encodedSessionId = Util::encodeParams($sessionId); $responseObj = new App42Response(); $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['sessionId'] = $sessionId; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/id/" . $encodedSessionId; $response = RestClient::delete($baseURL, $params, null, null, $contentType, $accept, $headerParams); $sessionResponseObj = new SessionResponseBuilder(); $sessionObj = $sessionResponseObj->buildResponse($response->getResponse()); $responseObj->setStrResponse($sessionObj); $responseObj->setResponseSuccess(true); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $responseObj; }
function getAllDevicesOfUser($userName) { Util::throwExceptionIfNullOrBlank($userName, "User Name"); $encodedUserName = Util::encodeParams($userName); $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['userName'] = $userName; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/getAllDevices/" . $encodedUserName; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $pushResponseObj = new PushNotificationResponseBuilder(); $pushObj = $pushResponseObj->buildArrayResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $pushObj; }
function getCountByQuery($dbName, $collectionName, $query) { Util::throwExceptionIfNullOrBlank($dbName, "DataBase Name"); Util::throwExceptionIfNullOrBlank($collectionName, "Collection Name"); Util::throwExceptionIfNullOrBlank($query, "query"); $encodedDbName = Util::encodeParams($dbName); $encodedCollectionName = Util::encodeParams($collectionName); $responseObj = new App42Response(); $objUtil = new Util($this->apiKey, $this->secretKey); $queryObject = null; if ($query instanceof JSONObject) { $queryObject = array(); array_push($queryObject, $query); } else { $queryObject = $query; } try { $params = null; $storageObj = new App42Response(); $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $signParams['dbName'] = $dbName; $signParams['collectionName'] = $collectionName; $signParams['jsonQuery'] = json_encode($queryObject); $queryParams['jsonQuery'] = json_encode($queryObject); $params = array_merge($queryParams, $signParams); $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/findDocsByQuery" . "/dbName/" . $encodedDbName . "/collectionName/" . $encodedCollectionName; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $storageResponseObj = new StorageResponseBuilder(); $storageObj = $storageResponseObj->buildResponse($response->getResponse()); $totalRecord = $storageObj->getRecordCount(); $body = '{"app42":{"response":{"totalRecords":"' . $totalRecord . '"}}}'; $responseObj->setStrResponse($body); $responseObj->setResponseSuccess(true); $responseObj->setTotalRecords($totalRecord); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $responseObj; }
/** * Delete the specified Geo points from Cloud. * * @param storageName * - Unique handler for storage name * * @return App42Response object containing the name of the storage that has * been deleted * * @throws App42Exception */ function deleteGeoPoints($geoStorageName, $geoPointsList) { Util::throwExceptionIfNullOrBlank($geoStorageName, "Geo Storage Name"); Util::throwExceptionIfNullOrBlank($geoPointsList, "Geo Points List"); $encodedStorageName = Util::encodeParams($geoStorageName); $responseObj = new App42Response(); $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); if (is_array($geoPointsList)) { $string = '{"app42":{ "geo": {"storage":{"points": { "point": ' . json_encode($geoPointsList) . '}}}}}'; } else { $string = '{"app42":{ "geo": {"storage":{"points": { "point": "' . $geoPointsList . '"}}}}}'; } $signParams['geoPoints'] = $string; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/points/" . $encodedStorageName; $response = RestClient::delete($baseURL, $params, null, null, $contentType, $accept, $headerParams); $geoResponseObj = new GeoResponseBuilder(); $geoObj = $geoResponseObj->buildResponse($response->getResponse()); $responseObj->setStrResponse($geoObj); $responseObj->setResponseSuccess(true); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $responseObj; }
function uploadFileForFriends($name, $userName, $filePath, $fileType, $description) { Util::throwExceptionIfNullOrBlank($name, "File Name"); Util::throwExceptionIfNullOrBlank($userName, "User Name"); Util::throwExceptionIfNullOrBlank($filePath, "FilePath"); Util::throwExceptionIfNullOrBlank($fileType, "UploadFileType"); Util::throwExceptionIfNullOrBlank($description, "Description"); $encodedUserName = Util::encodeParams($userName); $objUtil = new Util($this->apiKey, $this->secretKey); //$file = fopen($filePath, r); if (!file_exists($filePath)) { throw new App42Exception("The file with the name '{$filePath}' not found "); } $body = null; try { $params = null; $uploadTypeObj = new UploadFileType(); if ($uploadTypeObj->isAvailable($fileType) == "null") { throw new App42Exception("The file with type '{$fileType}' does not Exist "); } $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $postParams = array(); $postParams['name'] = $name; $postParams['userName'] = $userName; $postParams['type'] = $fileType; $postParams['description'] = $description; $params = array_merge($postParams, $signParams); $signature = urlencode($objUtil->sign($params)); //die(); $params['uploadFile'] = "@" . $filePath; $headerParams['signature'] = $signature; //CONTENT_TYPE == "multipart/form-data" $contentType = "multipart/form-data"; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/" . "friendsAll/" . $encodedUserName; $response = RestClient::post($baseURL, $params, null, null, $contentType, $accept, $body, $headerParams); $uploadResponseObj = new UploadResponseBuilder(); $uploadObj = $uploadResponseObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $uploadObj; }
function getActivityCountByUser($userId) { Util::throwExceptionIfNullOrBlank($userId, "UserId"); $encodedUserId = Util::encodeParams($userId); $objUtil = new Util($this->apiKey, $this->secretKey); $bravoObj = new App42Response(); try { $params = null; $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $signParams['userId'] = $userId; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/activity/userId/" . $encodedUserId . "/count"; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $bravoObj->setStrResponse($response->getResponse()); $bravoObj->setResponseSuccess(true); $bravoResponseObj = new BravoBoardResponseBuilder(); $bravoObj->setTotalRecords($bravoResponseObj->getTotalRecords($response->getResponse())); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $bravoObj; }
function updatePhoto($userName, $albumName, $photoName, $photoDescription, $path) { Util::throwExceptionIfNullOrBlank($userName, "User Name"); Util::throwExceptionIfNullOrBlank($albumName, "Album Name"); Util::throwExceptionIfNullOrBlank($photoName, "Photo Name"); Util::throwExceptionIfNullOrBlank($photoDescription, "Description"); Util::throwExceptionIfNullOrBlank($path, "Path"); Util::throwExceptionIfNotValidImageExtension($path, "Photo Path"); $encodedUserName = Util::encodeParams($userName); $objUtil = new Util($this->apiKey, $this->secretKey); if (!file_exists($path)) { throw new App42Exception("File Not Found"); } try { $params = null; $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $postParams = array(); $postParams['userName'] = $userName; $postParams['albumName'] = $albumName; $postParams['name'] = $photoName; $postParams['description'] = $photoDescription; $params = array_merge($postParams, $signParams); $signature = urlencode($objUtil->sign($params)); //die(); $params['imageFile'] = "@" . $path; $headerParams['signature'] = $signature; $contentType = "multipart/form-data"; $body = null; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/update/" . $encodedUserName; $response = RestClient::post($baseURL, $params, null, null, $contentType, $accept, $body, $headerParams); $photoResponseObj = new AlbumResponseBuilder(); $photoObj = $photoResponseObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $photoObj; }
function getUsersWithScoreRange($gameName, $minScore, $maxScore) { Util::throwExceptionIfNullOrBlank($gameName, "Game Name"); $encodedGameName = Util::encodeParams($gameName); $encodedMinScore = Util::encodeParams($minScore); $encodedMaxScore = Util::encodeParams($maxScore); $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; $signParams['minScore'] = $minScore; $signParams['maxScore'] = $maxScore; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/" . $encodedGameName . "/range/" . $minScore . "/" . $maxScore; $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; }
/** * History of Carts and Payments for a User. It gives all the carts which * are in AUTHORIZED, DECLINED, PENDING state. * * @params userId * - User Id for whom payment history has to be fetched * * @returns List containing Cart objects. Payment history can be retrieved * from individual Cart object. */ function getPaymentHistoryByUser($userId) { Util::throwExceptionIfNullOrBlank($userId, "User Id"); $encodedUserId = Util::encodeParams($userId); $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['userId'] = $userId; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/payment/history/" . $encodedUserId; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $cartResponseObj = new CartResponseBuilder(); $cartObj = $cartResponseObj->buildArrayResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $cartObj; }
/** * Gets the list of Users based on Profile Data * * @param profileData * - Profile Data key/value for which Users need to be retrieved * * @return List of User Object for the specified profile data */ function getUsersByProfileData(Profile $profileData) { Util::throwExceptionIfNullOrBlank($profileData, "profile Data"); $objUtil = new Util($this->apiKey, $this->secretKey); $parameters = $this->fillParamsWithProfileData($profileData); $encodedParameters = Util::encodeParams($parameters); try { $params = null; $userObj = new App42Response(); $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/profile/" . $encodedParameters; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $userResponseObj = new UserResponseBuilder(); $userObj = $userResponseObj->buildArrayResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $userObj; }
/** * Fetch count of log messages based on Date range * * @param startDate * - Start date from which the count of log messages have to be * fetched * @param endDate * - End date upto which the count of log messages have to be * fetched * * @return App42Response object containing count of fetched messages */ function fetchLogCountByDateRange($startDate, $endDate) { Util::throwExceptionIfNullOrBlank($startDate, "Start Date"); Util::throwExceptionIfNullOrBlank($endDate, "End Date"); $validateStartDate = Util::validateDate($startDate); $validateEndDate = Util::validateDate($endDate); $encodedStartDate = Util::encodeParams($startDate); $encodedEndDate = Util::encodeParams($endDate); $objUtil = new Util($this->apiKey, $this->secretKey); try { $params = null; $strStartDate = date("Y-m-d\\TG:i:s", strtotime($startDate)) . substr((string) microtime(), 1, 4) . "Z"; $strEndDate = date("Y-m-d\\TG:i:s", strtotime($endDate)) . substr((string) microtime(), 1, 4) . "Z"; $logObj = new App42Response(); $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $signParams['startDate'] = $strStartDate; $signParams['endDate'] = $strEndDate; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/startDate/" . $strStartDate . "/endDate/" . $strEndDate . "/count"; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $logObj->setStrResponse($response->getResponse()); $logObj->setResponseSuccess(true); $logResponseObj = new LogResponseBuilder(); $logObj->setTotalRecords($logResponseObj->getTotalRecords($response->getResponse())); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $logObj; }