private static function _doUrlRequest($httpVerb, $url, array $requestBody = array()) { $curl = curl_init(); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_ENCODING, 'UTF-8'); curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json', 'User-Agent: GameRocket PHP ' + GameRocket_Version::get(), 'X-ApiVersion: ' + GameRocket_Configuration::API_VERSION)); if (GameRocket_Configuration::sslOn()) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($curl, CURLOPT_CAINFO, GameRocket_Configuration::caFile()); } if (!empty($requestBody)) { curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($requestBody)); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if (GameRocket_Configuration::sslOn()) { if ($httpStatus == 0) { throw new GameRocket_Exception_SSLCertificate(); } } return array('status' => $httpStatus, 'body' => $response); }
public static function run($id, $attribs = array()) { $response = GameRocket_Http::post('/games/' . GameRocket_Configuration::apikey() . '/actions/' . $id . '/run', $attribs); if (isset($response['error'])) { return new GameRocket_Result_Error($response); } else { return new GameRocket_Result_Successful(GameRocket_Map::factory($response)); } }
<?php require_once 'vendor/workbandits/gamerocket-php/lib/GameRocket.php'; GameRocket_Configuration::environment('production'); GameRocket_Configuration::apiKey('your_api_key'); GameRocket_Configuration::secretKey('your_secret_key'); $result = GameRocket_Player::create(array( 'name' => $_POST["Name"], 'locale' => 'en_US' )); if ($result->success) { print_r("success!: " . $result->player->id); } else { print_r("Validation errors: \n"); print_r($result->errors->deepAll()); } ?>
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; GameRocket_Configuration::environment('production'); GameRocket_Configuration::apikey('16a9d25c079f46b29d1e7e2193ae7ae0'); GameRocket_Configuration::secretkey('41b12432741b4f028ed39cc23afab8d4'); $app = new Silex\Application(); $app->get('/', function () { include 'views/form.php'; return ''; }); $app->post('/create_player', function (Request $request) { $result = GameRocket_Player::create(array('name' => $request->get('name'), 'locale' => $request->get('locale'))); if ($result->success) { // Create the customer in your database with a field which contains Player ID for next calls return new Response("<h1>Success! Anasazi Player ID: " . $result->player->id . "</h1>", 200); } else { return new Response("<h1>Error: " . $result->message . "</h1>", 200); } }); $app->run(); return $app;
public static function reset() { self::$_cache = array('environment' => '', 'apikey' => '', 'secretkey' => ''); }
public static function create($attribs = array()) { GameRocket_Util::verifyKeys(self::createSignature(), $attribs); return self::_doCreate('/games/' . GameRocket_Configuration::apikey() . '/players', $attribs); }
<?php require_once 'gamerocket/lib/GameRocket.php'; GameRocket_Configuration::environment('production'); GameRocket_Configuration::apiKey('6c16df9febf142bf8eb3891c3255ae7d'); GameRocket_Configuration::secretKey('d94931fd34c247e19cc605cfe5a4a22b'); $result = GameRocket_Player::create(array( 'name' => $_POST["name"], 'locale' => $_POST["locale"] )); if ($result->success) { print_r("success!: " . $result->player->id); } else { print_r("Validation errors: \n"); print_r($result->errors->deepAll()); } ?>