Exemple #1
0
<?php

require '../gilt_api.php';
require '../lib/cache_http_get.php';
$api_key = file_get_contents('/etc/gilt_apikey');
//$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$cache = new CacheHttpGet('cache');
$gilt = new Gilt($api_key, $cache);
function cacheProducts($products)
{
    global $gilt, $cache;
    foreach ($products as $url) {
        $product = $gilt->getProduct($url);
        $cache->cache_put($url, $product->getJson());
        echo $url . "<br/>";
        flush();
    }
}
function cacheSales($sales)
{
    global $gilt, $cache;
    foreach ($sales as $sale) {
        $url = $sale->getSale();
        $cache->cache_put($url, $sale->getJson());
        echo $url . "<br/>";
        flush();
        cacheProducts($sale->getProducts());
    }
}
cacheSales($gilt->getActiveSales());
 public function test_getProduct()
 {
     $url = 'https://api.gilt.com/v1/products/98723426/detail.json?apikey=test_api_key';
     $response = file_get_contents('test/data/product_detail.json');
     $http_get = $this->getMockHttpGetOnce($url, $response);
     $gilt = new Gilt('test_api_key', $http_get);
     $product = $gilt->getProduct('98723426');
     $this->assertEquals('Horn Aviator Sunglasses', $product->getName());
     $this->assertEquals('https://api.gilt.com/v1/products/98723426/detail.json', $product->getProduct());
     $this->assertEquals('98723426', $product->getId());
     $this->assertEquals('Linda Farrow Luxe', $product->getBrand());
     $this->assertEquals('Linda Farrow Luxe horn acetate aviator sunglasses.  Saddle nose bridge and acetate and metal stems with cushioned ear pieces.  Embossed logo at sides of lenses and at interior temple.  Single Lens Width: 60 mm, Distance Between Lenses: 15 mm, Temple Length: 135 mm.  Comes with dust cloth and designer hard case.', $product->getDescription());
     $this->assertEquals('Acetate, Metal', $product->getMaterial());
     $this->assertEquals('Japan', $product->getOrigin());
     $this->assertEquals('http://www.gilt.com/m/public/look/?utm_medium=api&utm_campaign=bagspotting.com&utm_source=salesapi&s_id=cabe55a136143232787257042cf4347d387277926ffe81bb840d1d79fffce3e7_0_98723426', $product->getUrl());
     $imageUrls = $product->getImageUrls();
     $this->assertEquals(3, count($imageUrls));
     foreach ($imageUrls as $key => $image_url) {
         $this->assertEquals($key, $image_url->getWidth() . 'x' . $image_url->getHeight());
         $this->assertEquals(1, preg_match('#http://cdn1.gilt.com/images/share/uploads/\\d+/\\d+/\\d+/\\d+/' . $key . '.jpg#', $image_url->getUrl()));
     }
     $skus = $product->getSkus();
     $this->assertEquals(1, count($skus));
     $sku = $skus[0];
     $this->assertEquals('1373748', $sku->getId());
     $this->assertEquals('sold out', $sku->getInventoryStatus());
     $this->assertEquals('628.00', $sku->getMsrpPrice());
     $this->assertEquals('199.00', $sku->getSalePrice());
     $attributes = $sku->getAttributes();
     $this->assertEquals(1, count($attributes));
     $attribute = $attributes[0];
     $this->assertEquals('color', $attribute->name);
     $this->assertEquals('brown horn dark brown', $attribute->value);
 }