示例#1
0
 /**
  * Make a service call to the remote BinaryBeast API
  * 
  * @param string $svc    		Service to call (ie Tourney.TourneyCreate.Create)
  * @param array $args     		Arguments to send
  * @param int $ttl				If you configured the BBCache class, use this to define how many minutes this result should be cached
  * @param int $object_type		For caching objects: see BBCache::type_ constants
  * @param mixed $object_id		For caching objects: The id of this the object, like tourney_id or tourney_team_id
  *
  * @return object
  */
 public function call($svc, $args = null, $ttl = null, $object_type = null, $object_id = null)
 {
     //Use the new library to make the actual call, pass the request directly
     $result = $this->bb->call($svc, $args, $ttl, $object_type, $object_id);
     /**
      * Append an api_version_warning in hopes that developers
      * will update their code to use the new object oriented functionalty
      */
     $result->api_version_warning = 'You are using the old legacy wrapper method "' . $svc . '",' . 'please consider updating your code to take advantage of the new object-oriented functionality of the new API library. ' . 'Check out our github pages for examples / tutorials: https://github.com/BinaryBeast/BinaryBeast_API_PHP';
     return $result;
 }
 /**
  * Calls the BinaryBeast API using the given service name and arguments, 
  * and grabs the result code so we can locally stash it
  * 
  * @ignore
  * 
  * @param string $svc    		Service to call (ie Tourney.TourneyCreate.Create)
  * @param array $args     		Arguments to send
  * @param int $ttl				If you configured the BBCache class, use this to define how many minutes this result should be cached
  * @param int $object_type		For caching objects: see BBCache::type_ constants
  * @param mixed $object_id		For caching objects: The id of this the object, like tourney_id or tourney_team_id
  * @return object
  */
 protected function call($svc, $args = null, $ttl = null, $object_type = null, $object_id = null)
 {
     //Use BinaryBeast library to make the actual call
     $response = $this->bb->call($svc, $args, $ttl, $object_type, $object_id);
     //Finally, return the response
     return $response;
 }
示例#3
0
 /**
  * Test your callback handler, by requesting a fake callback from BinaryBeast
  * 
  * You can either define a callback, as if you were calling {@link register()}, <br />
  * Or you can provide a callback id integer to use the values of a callback that you've already registered
  * 
  * @param int $callback_id <br />
  *  <b>Note:</b> This value takes priority over all other arguments<br />
  *  If you've registered a callback, provide the callback_id, and BinaryBeast will use the event_id, url, trigger_id etc etc from your callback
  * @param int $event_id
  * <br /><b>Only used if <var>$callback_id</var> not provided</b>
  * @param int|string $trigger_id
  * <br /><b>Only used if <var>$callback_id</var> not provided</b>
  * @param string $url
  * <br /><b>Only used if <var>$callback_id</var> not provided</b>
  * @param string $action
  * <br /><b>Only used if <var>$callback_id</var> not provided</b>
  * @param boolean $recurrent
  * <br /><b>Only used if <var>$callback_id</var> not provided</b>
  * @param array|object $args
  * <br /><b>Only used if <var>$callback_id</var> not provided</b>
  * 
  * @return string|boolean
  *	<b>False</b> If BinaryBeast failed to call your URL, like non-200 result codes from your $url
  * 
  *	<br /><br />
  *	If BinaryBeast was successfully able to send data to your $url.. either your url's response will be returned,
  *	or a true boolean, in case your URL yielded an empty response
  */
 public function test($callback_id = null, $event_id = null, $trigger_id = null, $url = null, $action = 'post', $recurrent = false, $args = null)
 {
     $result = $this->bb->call(self::SERVICE_TEST, array('callback_id' => $callback_id, 'event_id' => $event_id, 'trigger_id' => $trigger_id, 'url' => $url, 'action' => $action, 'recurrent' => $recurrent, 'custom_args' => $args));
     //Failure!
     if ($result->result != BinaryBeast::RESULT_SUCCESS) {
         return false;
     }
     //Success! Return the response if available, true otherwise
     return $result->response ? $result->response : true;
 }
 /**
  * @group clear_expired_cache
  */
 public function test_clear_expired()
 {
     //Delete all tournament cache to avoid conflicts with previous tests
     $this->assertTrue($this->bb->clear_cache(null, BBCache::TYPE_TOURNAMENT));
     //Cache a tournament, specify negative ttl to auto-expire
     $result = $this->object->call('Tourney.TourneyLoad.Info', array('tourney_id' => 'xQL1302101'), -1, BBCache::TYPE_TOURNAMENT, 'xQL1302101');
     $this->assertServiceSuccessful($result);
     //Cache a second tour, with normal cache ttl
     $result = $this->object->call('Tourney.TourneyLoad.Info', array('tourney_id' => 'xSC213021613'), 2, BBCache::TYPE_TOURNAMENT, 'xSC213021613');
     $this->assertServiceSuccessful($result);
     //clear expired cache
     $this->assertTrue($this->object->clear_expired_cache());
     //Reload tour 1 - shouldn't be cached
     $result = $this->object->call('Tourney.TourneyLoad.Info', array('tourney_id' => 'xQL1302101'), -1, BBCache::TYPE_TOURNAMENT, 'xQL1302101');
     $this->assertServiceNotLoadedFromCache($result);
     //Reload tour 2 - should be cached
     $result = $this->object->call('Tourney.TourneyLoad.Info', array('tourney_id' => 'xSC213021613'), 2, BBCache::TYPE_TOURNAMENT, 'xSC213021613');
     $this->assertServiceLoadedFromCache($result);
 }
示例#5
0
 /**
  * Can be used in place of $bb->call, this method will check the local
  * cache table for any results from previous identical calls
  * 
  * It does not match arguments, but it matches tourney_id or tourney_team_id with the service
  * 
  * @param string        $svc
  * @param array         $args
  * @param int           $ttl                In minutes, how long to keep the result as valid
  * @param int           $object_type        Tournament, game, etc - use BBCache::TYPE_ constants for values
  * @param int|string    $object_id
  * 
  * @return boolean
  */
 public function call($svc, $args = null, $ttl = null, $object_type = null, $object_id = null)
 {
     //Build the WHERE clause to try to find a cacheed response in the local database
     $where = $this->build_where($svc, $object_type, $object_id);
     //First step - try to find an already cached response - if expired, remember the ID and we'll update later
     $id = null;
     $result = $this->db->query("\n            SELECT id, result, TIMESTAMPDIFF(MINUTE, UTC_TIMESTAMP(), expires) AS minutes_remaining\n            FROM {$this->config->cache_db_table}\n            {$where}\n        ");
     //Found it! is ist still valid??
     if ($result->rowCount() > 0) {
         $row = $result->fetchObject();
         //Success!
         if (intval($row->minutes_remaining) > 0) {
             //Add a value "from_cache" just FYI
             $result = $this->decompress($row->result);
             $result->from_cache = true;
             return $result;
         } else {
             $id = $row->id;
         }
     }
     //We don't have a valid cached response, call the API now
     $api_result = $this->bb->call($svc, $args);
     //Compress the result into a string we can save in the database
     $result_compressed = $this->compress($api_result);
     //If null, convert to string 'NULL' for database, otherwise surround with quores
     $object_type = is_null($object_type) ? 'NULL' : $object_type;
     $object_id = is_null($object_id) ? 'NULL' : "'{$object_id}'";
     //If we have an id, update it now
     if (!is_null($id)) {
         $this->update($id, $result_compressed, $ttl);
     } else {
         $this->insert($svc, $object_type, $object_id, $ttl, $result_compressed);
     }
     //Return the direct result from $bb
     return $api_result;
 }
 /**
  * @covers BinaryBeast::call
  */
 public function testCall()
 {
     $this->assertServiceListSuccessful($this->object->call('Tourney.TourneyList.Creator', array('page_size' => 1)));
 }