function createApp($appName, $orgName) { Util::throwExceptionIfNullOrBlank($appName, "App Name"); Util::throwExceptionIfNullOrBlank($orgName, "orgName"); $objUtil = new Util($this->apiKey, $this->secretKey); try { $params = array(); $params['apiKey'] = $this->apiKey; $params['version'] = $this->version; date_default_timezone_set('UTC'); $params['timeStamp'] = date("Y-m-d\\TG:i:s") . substr((string) microtime(), 1, 4) . "Z"; $params['App Name'] = $appName; $params['orgName'] = $orgName; $signature = urlencode($objUtil->sign($params)); //die(); $body = null; $body = '{"app42":{"app":}}'; $params['body'] = $body; $params['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $this->url = $this->url; $response = RestClient::post($this->url, $params, null, null, $contentType, $accept, $body); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $response; }
function isActive($testName) { Util::throwExceptionIfNullOrBlank($testName, "testName"); $objUtil = new Util($this->apiKey, $this->secretKey); try { $params = null; $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $signParams['testName'] = $testName; $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 . "/isActive/" . $testName; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $abTestRespObj = new ABTestResponseBuilder(); $abTestObj = $abTestRespObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $abTestObj; }
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; }
/** * Add or Update preference list on the cloud. * * @param preferenceDataList * - List of PreferenceData which contains customerId, itemId, * preference * * @return App42Response object */ function addOrUpdatePreference($preferenceDataList) { Util::throwExceptionIfNullOrBlank($preferenceDataList, "Preference Data List"); $responseObj = new App42Response(); $objUtil = new Util($this->apiKey, $this->secretKey); $dataValue = array(); $preferenceData = new PreferenceData(); if (is_array($preferenceDataList)) { foreach ($preferenceDataList as $arrayValue) { $userId = $arrayValue->getUserId(); $itemId = $arrayValue->getItemId(); $preference = $arrayValue->getPreference(); $array = array("UserId" => $userId, "itemId" => $itemId, "preference" => $preference); array_push($dataValue, $array); } } else { $userId = $preferenceDataList->getUserId(); $itemId = $preferenceDataList->getItemId(); $preference = $preferenceDataList->getPreference(); $array = array("UserId" => $userId, "itemId" => $itemId, "preference" => $preference); array_push($dataValue, $array); } try { $params = null; $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $body = null; //$body = '{"app42":{"preferences":{"preference":"' . $preferenceDataList->getUserId() . '","itemId":"' . $preferenceDataList->getItemId() . '","preference":"' . $preferenceDataList->getPreference() . '"}}}}'; $body = '{"app42":{"preferences":{"preference":' . json_encode($dataValue) . '}}}'; $signParams['body'] = $body; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/addOrUpdatePreference"; $response = RestClient::post($baseURL, $params, null, null, $contentType, $accept, $body, $headerParams); $responseObj->setStrResponse($response); $responseObj->setResponseSuccess(true); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $responseObj; }
function gocoin_callback() { global $woocommerce; $gateways = $woocommerce->payment_gateways->payment_gateways(); $logger = new WC_Logger(); if (!isset($gateways['gocoin'])) { return; } $gocoin = $gateways['gocoin']; $gocoin_setting = isset($gocoin->settings) && is_array($gocoin->settings) ? $gocoin->settings : array(); $key = isset($gocoin_setting['accessToken']) && !empty($gocoin_setting['accessToken']) ? $gocoin_setting['accessToken'] : ''; if (empty($key)) { return $logger->add('gocoin-callback', 'Api Key is blank'); } $data = Util::postData(); if (isset($data->error)) { return $logger->add('gocoin-callback', $data->error); } else { // $key = $gocoin -> settings -> accessToken; $event_id = $data->id; $event = $data->event; $invoice = $data->payload; $payload_arr = get_object_vars($invoice); ksort($payload_arr); $signature = $invoice->user_defined_8; $sig_comp = Util::sign($payload_arr, $key); $status = $invoice->status; $order_id = (int) $invoice->order_id; $order = WC_Order_Factory::get_order($order_id); if (!$order) { $msg = "Order with id: " . $order_id . " was not found. Event ID: " . $event_id; return $logger->add('gocoin-callback', $msg); } // Check that if a signature exists, it is valid if (isset($signature) && $signature != $sig_comp) { $msg = "Signature : " . $signature . "does not match for Order: " . $order_id . "{$sig_comp} | {$signature} "; } elseif (empty($signature) || empty($sig_comp)) { $msg = "Signature is blank for Order: " . $order_id; } elseif ($signature == $sig_comp) { switch ($event) { case 'invoice_created': break; case 'invoice_payment_received': switch ($status) { case 'ready_to_ship': $msg = 'Order ' . $order_id . ' is paid and awaiting payment confirmation on blockchain.'; $order->update_status('on-hold', __($msg, 'woothemes')); break; case 'paid': $msg = 'Order ' . $order_id . ' is paid and awaiting payment confirmation on blockchain.'; $order->update_status('on-hold', __($msg, 'woothemes')); break; case 'underpaid': $msg = 'Order ' . $order_id . ' is underpaid.'; $order->update_status('on-hold', __($msg, 'woothemes')); break; } break; case 'invoice_merchant_review': $msg = 'Order ' . $order_id . ' is under review. Action must be taken from the GoCoin Dashboard.'; $order->update_status('on-hold', __($msg, 'woothemes')); break; case 'invoice_ready_to_ship': $msg = 'Order ' . $order_id . ' has been paid in full and confirmed on the blockchain.'; $order->payment_complete(); break; case 'invoice_invalid': $msg = 'Order ' . $order_id . ' is invalid and will not be confirmed on the blockchain.'; $order->update_status('failed', __($msg, 'woothemes')); break; default: $msg = "Unrecognized event type: " . $event; } if (isset($msg)) { $msg .= ' Event ID: ' . $event_id; } } return $logger->add('gocoin-callback', $msg); } }
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 getFacebookProfilesFromIds($facebookIds) { Util::throwExceptionIfNullOrBlank($facebookIds, "FacebookIds"); $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); if (is_array($facebookIds)) { $headerParams['userList'] = json_encode($facebookIds); } else { $headerParams['userList'] = $facebookIds; } $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/facebook/ids"; $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; }
/** * This Service is used to send Emails. This service can be used by app to send mail to one or multiple recipients. * * @params sendTo * - The email ids to which the email has to be sent. Email can * be sent to multiple email ids. Multiple email ids can be * passed using comma as the separator e.g. sid@shephertz.com, * info@shephertz.com * @params sendSubject * - Subject of the Email which to be sent * @params sendMsg * - Email body which has to be sent * @params fromEmail * - The Email Id using which the mail(s) has to be sent * @params emailMime * - MIME Type to be used for sending mail. EmailMIME available * options are PLAIN_TEXT_MIME_TYPE or HTML_TEXT_MIME_TYPE * * @return Email object containing all the details used for sending mail */ function sendMail($fromEmail, $sendTo, $sendSubject, $sendMsg, $emailMIME) { Util::throwExceptionIfNullOrBlank($fromEmail, "Email Id"); Util::throwExceptionIfNullOrBlank($sendTo, "Send To"); Util::throwExceptionIfNullOrBlank($sendSubject, "Send Subject"); Util::throwExceptionIfNullOrBlank($sendMsg, "Send Message"); Util::throwExceptionIfNullOrBlank($emailMIME, "EmailMIME"); $objUtil = new Util($this->apiKey, $this->secretKey); try { $params = null; $emailMIMETypeObj = new EmailMIME(); if ($emailMIMETypeObj->isAvailable($emailMIME) == "null") { throw new App42Exception("The EmailMIME with type '{$emailMIME}' does not Exist "); } $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $body = null; $body = '{"app42":{"email":{"emailId":"' . $fromEmail . '","to":"' . $sendTo . '","subject":"' . $sendSubject . '","msg":"' . $sendMsg . '","mimeType":"' . $emailMIME . '"}}}'; $signParams['body'] = $body; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL; $response = RestClient::post($baseURL, $params, null, null, $contentType, $accept, $body, $headerParams); $emailResponseObj = new EmailResponseBuilder(); $emailObj = $emailResponseObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $emailObj; }
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; }
/** * Converts the format of the image. Returns the original image url and converted image url. * Images are stored on the cloud and can be accessed through the urls * Conversion is done based on the formatToConvert provided * * @param name * - Name of the image to convert * @param imagePath * - Path of the local file to convert * @param formatToConvert * - To which file needs to be converted * @return Image object containing urls for the original and converted * images * * @throws App42Exception * */ function convertFormat($name, $imagePath, $formatToConvert) { Util::throwExceptionIfNullOrBlank($name, "Name"); Util::throwExceptionIfNullOrBlank($imagePath, "Image Path"); Util::throwExceptionIfNotValidImageExtension($imagePath, "imagePath"); Util::throwExceptionIfNullOrBlank($formatToConvert, "formatToConvert"); $objUtil = new Util($this->apiKey, $this->secretKey); //$file = fopen($filePath, r); if (!file_exists($imagePath)) { throw new App42Exception(" File " . $imagePath . " does not exist"); } //$file = new File($filePath); //if(!file_exists($file)){ //throw Exception //} try { $params = null; $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $postParams = array(); $postParams['name'] = $name; $postParams['formatToConvert'] = $formatToConvert; $params = array_merge($postParams, $signParams); $signature = urlencode($objUtil->sign($params)); //die(); $params['imageFile'] = "@" . $imagePath; $headerParams['signature'] = $signature; //CONTENT_TYPE == "multipart/form-data" $contentType = "multipart/form-data"; $body = null; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/convertformat"; $response = RestClient::post($baseURL, $params, null, null, $contentType, $accept, $body, $headerParams); $imageResponseObj = new ImageProcessorResponseBuilder(); $imageObj = $imageResponseObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $imageObj; }
/** * Process payment for woocommerce checkout * * @param mixed $order_id */ function process_payment($order_id) { global $woocommerce, $wpdb; $access_token = $this->settings['accessToken']; $merchant_id = $this->settings['merchantId']; $logger = new WC_Logger(); // Check to make sure we have an access token (API Key) if (empty($access_token)) { $msg = 'Improper Gateway set up. Access token not found.'; $logger->add('gocoin', $msg); $woocommerce->add_error(__($msg)); } elseif (empty($merchant_id)) { $msg = 'Improper Gateway set up. Merchant ID not found.'; $logger->add('gocoin', $msg); $woocommerce->add_error(__($msg)); } else { // Build the WooCommerce order, is has status "Pending" $order = new WC_Order($order_id); // Handle breaking route changes for after-purchase pages if (version_compare(WOOCOMMERCE_VERSION, '2.1.0', '>=')) { $redirect_url = $this->get_return_url($this->order); } else { $redirect_url = add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id')))); } $callback_url = plugin_dir_url(__FILE__) . 'gocoin-callback.php'; $currency = get_woocommerce_currency(); $options = array("type" => 'bill', "base_price" => $order->order_total, "base_price_currency" => $currency, "callback_url" => $callback_url, "redirect_url" => $redirect_url, "order_id" => $order_id, "customer_name" => $order->shipping_first_name . ' ' . $order->shipping_last_name, "customer_address_1" => $order->shipping_address_1, "customer_address_2" => $order->shipping_address_2, "customer_city" => $order->shipping_city, "customer_region" => $order->shipping_state, "customer_postal_code" => $order->shipping_postcode, "customer_country" => $order->shipping_country, "customer_phone" => $order->shipping_phone, "customer_email" => $order->shipping_email); // Sign invoice with access token, if this fails we should still allow user to check out. if ($signature = Util::sign($options, $access_token)) { $options['user_defined_8'] = $signature; } try { $invoice = GoCoin::createInvoice($access_token, $merchant_id, $options); $url = $invoice->gateway_url; $woocommerce->cart->empty_cart(); return array('result' => 'success', 'redirect' => $url); } catch (Exception $e) { $msg = $e->getMessage(); $order->add_order_note(var_export($msg)); $logger->add('gocoin', $msg); $woocommerce->add_error(__($msg)); } } }
function getUsersByGroup($users) { $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); $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; if (is_array($users)) { $headerParams['userList'] = json_encode($users); } else { $headerParams['userList'] = $users; } $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/groupusers"; $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; }
/** * 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; }
/** * 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; }
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 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 getCurrentTime() { $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); $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/currentTime"; $response = RestClient::get($baseURL, $params, null, null, $contentType, $accept, $headerParams); $timerResponseObj = new TimerResponseBuilder(); $timerObj = $timerResponseObj->buildResponse($response->getResponse()); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $timerObj; }
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 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; }
/** * 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; }