Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var key = "98C77A5A-330F-F74B-8946-8A24E66D50FD3FA1F803-7446-4B24-8CFC-C62D5F7679AF"
- function getMaterials() {
- var myUrl = "https://api.guildwars2.com/v2/account/materials?access_token=" + escape(key);
- var jsonData = UrlFetchApp.fetch(myUrl);
- var jsonString = jsonData.getContentText();
- return jsonString;
- }
- var data = getMaterials();
- // Map each object by ID
- function getMaterialIdMap(data){
- var materials = {};
- for(var i = 0; i < data.length; i++ ){
- var material = data[i];
- if(material.hasOwnProperty('id')){ // Ensure we only get objects with ids
- materials[material.id] = material;
- }
- }
- return materials
- }
- // Map just the count to id
- function getIdToCountMap(data){
- var materials = {};
- for(var i = 0; i < data.length; i++ ){
- var material = data[i];
- if(material.hasOwnProperty('id') && material.hasOwnProperty('count')){ // Ensure we only get objects with counts and ids
- materials[material.id] = material.count;
- }
- }
- return materials
- }
- var materialMap = getMaterialIdMap(data);
- // For just the counts
- var materialCountMap = getIdToCountMap(data);
- // For the full object by id
- function countFromId (id){
- return materialCountMap[id];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement