Untitled
unknown
java
2 years ago
3.3 kB
5
Indexable
public Item[] getCardsInventory(){ try { //Getting JSON JSONObject body = cardsJSON(authenticatedClient()); //This one for amount of cards JSONObject cardAmount = body.getJSONObject("rgInventory"); HashMap<String,Integer> classID = new HashMap<>(); //Iterating for amount of cards for each class id for (Iterator i = cardAmount.keySet().iterator(); i.hasNext();){ String key = (String) i.next(); JSONObject id = cardAmount.getJSONObject(key); String hash = id.get("classid").toString(); int amount = Integer.parseInt(id.get("amount").toString()); if(classID.containsKey(hash)){ amount = classID.get(hash)+1; } classID.put(hash,amount); } List<Item> items = new ArrayList<>(); //This one is for cards info JSONObject cards = body.getJSONObject("rgDescriptions"); //Iterating for each card info for (Iterator i = cards.keySet().iterator(); i.hasNext ();){ String key = (String) i.next (); JSONObject val = (JSONObject) cards.get(key); if(val.get("type").toString().contains("Profile") || val.get("type").toString().contains("Emoticon")) continue; Item card = new Item(); //Getting amount of cards from HashMap String id = val.get("classid").toString(); card.amount = classID.get(id).toString(); //Every other Item attribute card.icon = val.get("icon_url").toString(); card.type = val.get("type").toString(); card.assetid = val.get("market_fee_app").toString(); card.name = val.get("name").toString(); if(val.get("tradable").toString() == "0"){ card.tradable = false; }else { card.tradable = true; } if(!val.keySet().contains("owner_actions")) continue; if(val.get("owner_actions") == null) continue; String contextID = val.getJSONArray("owner_actions").toString(); card.contextId = StringUtils.substringBetween(contextID,""+card.assetid+", ",","); if(card.contextId == null) continue; items.add(card); } } catch (Exception e) { throw new RuntimeException(e); } return null; } private JSONObject cardsJSON(CloseableHttpAsyncClient client)throws Exception{ client.start(); try { //Just getting the JSON Response HttpGet request = new HttpGet("https://steamcommunity.com/id/"+this.getProfileName(authenticatedClient())+"/inventory/json/753/6/"); HttpResponse response = client.execute(request, null).get(); HttpEntity ent = response.getEntity(); JSONObject invJSON = new JSONObject(EntityUtils.toString(ent)); return invJSON; }finally { client.close(); } }
Editor is loading...