Exemple #1
0
 /**
  * Get Giantbomb ID from title
  *
  * @param string $title
  *
  * @return bool|mixed Array if no result False
  */
 public function fetchGiantBombID($title = '')
 {
     $obj = new \GiantBomb($this->publicKey);
     try {
         $fields = ["api_detail_url", "name"];
         $result = json_decode(json_encode($obj->search($title, $fields, 10, 1, ["game"])), true);
         // We hit the maximum request.
         if (empty($result)) {
             $this->maxHitRequest = true;
             return false;
         }
         if (!is_array($result['results']) || (int) $result['number_of_total_results'] === 0) {
             $result = false;
         } else {
             $this->_resultsFound = count($result['results']) - 1;
             if ($this->_resultsFound !== 0) {
                 for ($i = 0; $i <= $this->_resultsFound; $i++) {
                     similar_text(strtolower($result['results'][$i]['name']), strtolower($title), $p);
                     if ($p > 77) {
                         $result = $result['results'][$i];
                         preg_match('/\\/\\d+\\-(?<asin>\\d+)\\//', $result['api_detail_url'], $matches);
                         $this->_gameID = (string) $matches['asin'];
                         $result = $this->fetchGiantBombArray();
                         $this->_classUsed = "gb";
                         break;
                     }
                     if ($i === $this->_resultsFound) {
                         return false;
                     }
                 }
             } else {
                 return false;
             }
         }
     } catch (\Exception $e) {
         $result = false;
     }
     return $result;
 }
Exemple #2
0
<?php

require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
require_once nZEDb_LIBS . 'GiantBombAPI.php';
// Test if your giantbomb key is working.
use nzedb\ColorCLI;
use nzedb\db\Settings;
$giantbombkey = (new Settings())->getSetting('giantbombkey');
$cli = new ColorCLI();
$obj = new GiantBomb($giantbombkey, $resp = "json");
$searchgame = "South Park The Stick of Truth";
$resultsfound = 0;
$e = null;
try {
    $fields = array("deck", "description", "original_game_rating", "api_detail_url", "image", "genres", "name", "platforms", "publishers", "original_release_date", "reviews", "site_detail_url");
    $result = $obj->search($searchgame, $fields, 1);
    $result = json_decode(json_encode($result), true);
    if ($result['number_of_total_results'] != 0) {
        $resultsfound = count($result['results']);
        for ($i = 0; $i <= $resultsfound; $i++) {
            similar_text($result['results'][$i]['name'], $searchgame, $p);
            if ($p > 90) {
                $result = $result['results'][$i];
                break;
            }
        }
    }
} catch (\Exception $e) {
    $result = false;
}
if ($result !== false && !empty($result)) {