Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. class SteamInventory {
  2.  
  3. const API_URL = 'http://steamcommunity.com/id/%s/inventory/json/753/1';
  4. const IMAGES_URL = 'http://cdn.steamcommunity.com/economy/image/';
  5.  
  6. private static $inventoryArray = array();
  7.  
  8. public static function getInventory($communityId) {
  9. $url = sprintf(self::API_URL, $communityId);
  10. $json = file_get_contents($url);
  11. $data = json_decode($json, TRUE);
  12. $games = $data['rgDescriptions'];
  13.  
  14. foreach ($games as $game) {
  15. $stGame = new stdClass();
  16.  
  17. if ($game['tradable']) {
  18. $stGame->name = $game['name'];
  19. if (count($game['descriptions']) > 1) {
  20. $stGame->desc1 = $game['descriptions'][0]['value'];
  21. $stGame->desc2 = $game['descriptions'][1]['value'];
  22. } else {
  23. $stGame->desc1 = NULL;
  24. $stGame->desc2 = $game['descriptions'][0]['value'];
  25. }
  26. $stGame->iconSmall = self::IMAGES_URL . $game['icon_url'];
  27. $stGame->iconLarge = self::IMAGES_URL . $game['icon_url_large'];
  28. $stGame->link = $game['actions']['link'];
  29. self::$inventoryArray[] = $stGame;
  30. }
  31. }
  32.  
  33. return json_encode(self::$inventoryArray);
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement