forked from PlayFab/API_Specs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
71 lines (62 loc) · 2.62 KB
/
fetch.js
File metadata and controls
71 lines (62 loc) · 2.62 KB
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
var https = require("https");
var fs = require('fs');
var argsDict = null;
function WriteApiFile(filename, body, descriptor) {
body = TabifyJson(body, descriptor);
var fullFileName = filename + ".json";
console.log("Begin writing: " + fullFileName);
fs.writeFile(fullFileName, body, function (err) {
if (err)
return console.log(err);
console.log("Finished writing: " + fullFileName);
});
}
function TabifyJson(inputJson, descriptor) {
console.log("Begin tabifying: " + descriptor);
var tempObj = JSON.parse(inputJson);
var output = JSON.stringify(tempObj, null, 2);
console.log("Finish tabifying: " + descriptor);
return output;
}
function GetApiFile(inputUrl, outputFilename, descriptor) {
console.log("Begin reading: " + inputUrl);
var rawResponse = "";
var postReq = https.get(inputUrl, function (res) {
res.setEncoding("utf8");
res.on("data", function (chunk) { rawResponse += chunk; });
res.on("end", function () {
console.log("Finished reading: " + inputUrl);
WriteApiFile(outputFilename, rawResponse, descriptor)
});
});
}
function ExtractArgs(args) {
var cmdArgs = args.slice(2, args.length);
var argsByName = {};
var activeKey = null;
for (var i = 0; i < cmdArgs.length; i++) {
if (cmdArgs[i].indexOf("-") === 0) {
activeKey = cmdArgs[i].substring(1);
argsByName[activeKey] = "";
} else if (activeKey == null) {
throw "Unexpected token: " + cmdArgs[i];
} else {
var temp = argsByName[activeKey];
if (temp.length > 0)
argsByName[activeKey] = temp + " " + cmdArgs[i];
else
argsByName[activeKey] = cmdArgs[i];
}
}
// Pull from environment variables?
// process.env.hasOwnProperty("varname")
return argsByName;
}
var argsDict = ExtractArgs(process.argv);
GetApiFile("https://www.playfabapi.com/apispec/ClientAPI", "Client.api", "Client-Api");
GetApiFile("https://www.playfabapi.com/apispec/ServerAPI", "Server.api", "Server-Api");
GetApiFile("https://www.playfabapi.com/apispec/AdminAPI", "Admin.api", "Admin-Api");
GetApiFile("https://www.playfabapi.com/apispec/MatchmakerAPI", "Matchmaker.api", "Matchmaker-Api");
GetApiFile("https://www.playfabapi.com/apispec/PlayStreamEventModels", "PlayStreamEventModels", "Client-Api");
GetApiFile("https://www.playfabapi.com/apispec/PlayStreamCommonEventModels", "PlayStreamCommonEventModels", "Client-Api");
GetApiFile("https://www.playfabapi.com/apispec/PlayStreamProfileModel", "PlayStreamProfileModels", "Client-Api");