View difference between Paste ID: XRruKP8f and 9cZdH5fA
SHOW: | | - or go back to the newest paste.
1
//get all information about an item (a single HTTP request is made), and return those data
2
function GetItem(itemID) {
3
  var myUrl = "http://www.gw2spidy.com/api/v0.9/json/item/" + escape(itemID);
4
  var jsonData = UrlFetchApp.fetch(myUrl);  
5
  var jsonString = jsonData.getContentText();
6
  var jsonObject = JSON.parse(jsonString).result;
7
  return jsonObject;  
8
}
9
10
// pass downloaded item data to functions that return adjusted item value
11
12
function GetItemSellValue(jsonObject) {
13
      var adjustedValue = (jsonObject.min_sale_unit_price / 100);
14
      return adjustedValue;  
15
}
16
     
17
function SalePriceChangedLastHour(jsonObject) {
18
      var adjustedValue = (jsonObject.sale_price_change_last_hour / 100);
19
      return adjustedValue;  
20
}
21
     
22
function GetItemBuyValue(jsonObject) {
23
      var adjustedValue = (jsonObject.max_offer_unit_price / 100);
24
      return adjustedValue;
25
}
26
     
27
function OfferPriceChangedLastHour(jsonObject) {
28
      var adjustedValue = (jsonObject.offer_price_change_last_hour / 100);
29
      return adjustedValue;
30
}
31
32
33
// functions call example for prices of Glob of Ectoplasm:
34
35
//get all information about that item (a single HTTP request is made) and save them in a variable
36-
var sall_changed=SalePriceChangedLastHour(ecto);
36+
37
38
//get adjusted values passing already downloaded object info to adjusting functions
39
var sell=GetItemSellValue(ecto);
40
var sell_changed=SalePriceChangedLastHour(ecto);
41
var buy=GetItemBuyValue(ecto);
42
var buy_changed=OfferPriceChangedLastHour(ecto);