View difference between Paste ID: WiXfFwWR and Qc1UbmQr
SHOW: | | - or go back to the newest paste.
1-
Original script:
1+
2-
function GetItemSellValue(itemID) {
2+
3
  var jsonData = UrlFetchApp.fetch(myUrl);  
4-
  var jsonData = UrlFetchApp.fetch(myUrl);
4+
5
  return jsonObject;  
6-
  var jsonObject = JSON.parse(jsonString).result;
6+
7-
  var adjustedValue = (jsonObject.min_sale_unit_price / 100);
7+
8-
  return adjustedValue;  
8+
function GetItemSellValue(jsonObject) {
9
      var adjustedValue = (jsonObject.min_sale_unit_price / 100);
10
      return adjustedValue;  
11
}
12
     
13-
Separate connections:
13+
function SalePriceChangedLastHour(jsonObject) {
14
      var adjustedValue = (jsonObject.sale_price_change_last_hour / 100);
15
      return adjustedValue;  
16
}
17
     
18
function GetItemBuyValue(jsonObject) {
19
      var adjustedValue = (jsonObject.max_offer_unit_price / 100);
20
      return adjustedValue;
21-
function GetItemExchangeValue(jsonObject) {
21+
22-
  return(jsonObject.min_sale_unit_price / 100)
22+
     
23
function OfferPriceChangedLastHour(jsonObject) {
24
      var adjustedValue = (jsonObject.offer_price_change_last_hour / 100);
25
      return adjustedValue;
26
}
27-
GW2 v2 API:
27+
28-
function Test(itemID) {
28+
// functions call example for prices of Glob of Ectoplasm:
29-
  var myUrl = "https://api.guildwars2.com/v2/commerce/exchange" + escape(itemID);
29+
30-
  var jsonData = UrlFetchApp.fetch(myUrl);
30+
//get all information about that item (a single HTTP request is made) and save them in a variable
31
var ecto = GetItem(19721);
32-
  var jsonObject = JSON.parse(jsonString).result;
32+
33-
  var adjustedValue = (jsonObject.exchange /100);
33+
//get adjusted values passing already downloaded object info to adjusting functions
34-
  return adjustedValue;  
34+
var sell=GetItemSellValue(ecto);
35-
}
35+
var sall_changed=SalePriceChangedLastHour(ecto);
36
var buy=GetItemBuyValue(ecto);
37
var buy_changed=OfferPriceChangedLastHour(ecto);