-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcitadelmarket.gs
110 lines (78 loc) · 2.9 KB
/
citadelmarket.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
see https://www.fuzzwork.co.uk/2017/03/14/using-esi-googledocs/ for install details.
Needs work, as it reauths for each call. As it can't store the access token or expiry in the sheet.
*/
function getSetup() {
var config={};
var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getNamedRanges();
for (var i = 0; i < namedRanges.length; i++) {
switch (namedRanges[i].getName()) {
case 'clientid':
config.clientid=namedRanges[i].getRange().getCell(1, 1).getValue() ;
break;
case 'secret':
config.secret=namedRanges[i].getRange().getCell(1, 1).getValue() ;
break;
case 'refresh':
config.refreshtoken=namedRanges[i].getRange().getCell(1, 1).getValue() ;
break;
}
}
var documentProperties = PropertiesService.getDocumentProperties();
config.expires = documentProperties.getProperty('oauth_expires');
config.access_token = documentProperties.getProperty('access_token')
return config;
}
function getAccessToken(config) {
if (Date.now()>config.expires) {
var url = 'https://login.eveonline.com/oauth/token?'
+ 'grant_type=refresh_token'
+ '&refresh_token='+config.refreshtoken;
var code=Utilities.base64Encode(config.clientid+':'+config.secret);
var headers = {
'Authorization': 'Basic '+code,
'Content-Type': 'application/x-www-form-urlencoded',
};
var parameters = {
'method': 'post',
'headers': headers,
};
var response = UrlFetchApp.fetch(url, parameters).getContentText();
var json = JSON.parse(response);
var access_token = json['access_token'];
config.access_token=access_token;
config.expires=Date.now()+1200000
var documentProperties = PropertiesService.getDocumentProperties();
documentProperties.setProperty('access_token',access_token)
documentProperties.setProperty('oauth_expires',config.expires)
}
return config;
}
function getCitadel(citadelid) {
var config=getSetup();
config=getAccessToken(config);
var url = 'https://esi.tech.ccp.is/latest/markets/structures/'+citadelid+'/';
var parameters = {method : "get", headers : {'Authorization':'Bearer '+ config.access_token}};
var jsonFeed = UrlFetchApp.fetch(url, parameters).getContentText();
var json = JSON.parse(jsonFeed);
var prices=[];
prices.push(['duration','buy','issued','location','min volume','order id','price','range','typeid','volume remaining','total volume'])
if(json) {
for(i in json) {
var price=[json[i].duration,
json[i].is_buy_order,
json[i].issued,
json[i].location_id,
json[i].min_volume,
json[i].order_id,
json[i].price,
json[i].range,
json[i].type_id,
json[i].volume_remain,
json[i].volume_total
];
prices.push(price);
}
}
return prices;
}