예제 #1
0
<?php

use Src\Helpers\Config;
use Src\Model\Atlas;
require_once __DIR__ . '/../../vendor/autoload.php';
// Check if the configuration value can be loaded
echo Config::getInstance()->get('atlas.api', 'key') . "\n\n";
// Check if category ID can be fetched from the Atlas API
echo Atlas::getCategoryId('Accommodation') . "\n\n";
// Check if products with params can be fetched from the Atlas API
$products = Atlas::getProducts(['cats' => 'ACCOMM', 'rg' => 'Blue Mountains']);
$product = Atlas::getProduct('9053120$53072421-f579-4ebe-822f-086c91455403');
print_r($product);
예제 #2
0
 /**
  * Gets product detail
  * @see http://govhack.atdw.com.au/API/getproductATWS.html
  *
  * @param String $productId
  *
  * @return mixed|null
  * @throws \Exception
  */
 public static function getProduct($productId)
 {
     $key = Config::getInstance()->get('atlas.api', 'key');
     $url = Config::getInstance()->get('atlas.api', 'url');
     $resource = 'product';
     $params = ['key' => $key, 'productId' => $productId];
     $apiUrl = $url . $resource . '?' . http_build_query($params);
     $response = Cache::get($apiUrl);
     if ($response == null) {
         $curl = new Curl();
         $curl->get($apiUrl);
         if ($curl->httpStatusCode >= 400) {
             throw new \Exception('Error requesting Atlas Product' . $productId . '. Status : ' . $curl->httpStatusCode);
         }
         $response = $curl->response;
         Cache::set($apiUrl, $response);
     }
     return $response;
 }