public function testGetJSONDataError()
 {
     $data = '{ "result": { "status": 2, "statusDetail": "error" } }';
     $webApi = $this->getMockBuilder('\\SteamCondenser\\Community\\WebApi')->setMethods(['_load'])->disableOriginalConstructor()->getMock();
     $webApi->expects($this->once())->method('_load')->with('json', 'interface', 'method', 2, ['test' => 'param'])->will($this->returnValue($data));
     $this->instance->setValue($webApi);
     $this->setExpectedException('\\SteamCondenser\\Exceptions\\WebApiException', 'The Web API request failed with the following error: error (status code: 2).');
     WebApi::getJSONData('interface', 'method', 2, ['test' => 'param']);
 }
 /**
  * Updates the item definitions of this schema using the Steam Web API
  *
  * @throws \SteamCondenser\Exceptions\WebApiException if the item schema
  *         cannot be fetched
  */
 public function internalFetch()
 {
     $params = ['language' => $this->language];
     $data = WebApi::getJSONData("IEconItems_{$this->appId}", 'GetSchema', 1, $params);
     $this->attributes = [];
     foreach ($data->attributes as $attribute) {
         $this->attributes[$attribute->defindex] = $attribute;
         $this->attributes[$attribute->name] = $attribute;
     }
     $this->effects = [];
     foreach ($data->attribute_controlled_attached_particles as $effect) {
         $this->effects[$effect->id] = $effect;
     }
     $this->items = [];
     $this->itemNames = [];
     foreach ($data->items as $item) {
         $this->items[$item->defindex] = $item;
         $this->itemNames[$item->name] = $item->defindex;
     }
     if (!empty($data->levels)) {
         $this->itemLevels = [];
         foreach ($data->item_levels as $itemLevelType) {
             $itemLevels = [];
             foreach ($itemLevelType->levels as $itemLevel) {
                 $itemLevels[$itemLevel->level] = $itemLevel->name;
             }
             $this->itemLevels[$itemLevelType->name] = $itemLevels;
         }
     }
     $this->itemSets = [];
     foreach ($data->item_sets as $itemSet) {
         $this->itemSets[$itemSet->item_set] = $itemSet;
     }
     $this->origins = [];
     foreach ($data->originNames as $origin) {
         $this->origins[$origin->origin] = $origin->name;
     }
     $this->qualities = [];
     $index = -1;
     foreach ($data->qualities as $key => $value) {
         $index++;
         if (property_exists($data->qualityNames, $key)) {
             $qualityName = $data->qualityNames->{$key};
         }
         if (empty($qualityName)) {
             $qualityName = ucwords($key);
         }
         $this->qualities[$index] = $qualityName;
     }
 }
 /**
  * Updates the contents of the backpack using Steam Web API
  */
 public function fetch()
 {
     $params = array('SteamID' => $this->steamId64);
     $result = WebApi::getJSONData("IEconItems_{$this->getAppId()}", 'GetPlayerItems', 1, $params);
     $this->items = array();
     $this->preliminaryItems = array();
     foreach ($result->items as $itemData) {
         if ($itemData != null) {
             $inventoryClass = new ReflectionClass(get_class($this));
             $itemClass = $inventoryClass->getConstant('ITEM_CLASS');
             $item = new $itemClass($this, $itemData);
             if ($item->isPreliminary()) {
                 $this->preliminaryItems[] = $item;
             } else {
                 $this->items[$item->getBackpackPosition() - 1] = $item;
             }
         }
     }
     $this->fetchDate = time();
 }