init commit

This commit is contained in:
2020-03-01 19:46:48 +01:00
parent c7121950d1
commit ef87e03ff5
17 changed files with 583 additions and 1 deletions

View File

@@ -1,3 +1,9 @@
# torn-api
Open API 3.0 description of the Torn-API.\
[see Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md)
Open API 3.0 description of the Torn API
Online Resource hosted by JotDe \[2200962\]\
[Try out](https://jotde.be/torn-api)
You can also clone the Repository to a local folder and set your API-Key as fixed value in [Index HTML](./index.html)\
The folder should be put inside your WebRoot to work properly. I didn't check if it is possible to open the HTML outside a Webserver.

4
css/swagger-ui.css Normal file

File diff suppressed because one or more lines are too long

1
css/swagger-ui.css.map Normal file

File diff suppressed because one or more lines are too long

BIN
img/favicon-16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

BIN
img/favicon-32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

64
index.html Normal file
View File

@@ -0,0 +1,64 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Torn API by JotDe [2200962]</title>
<link rel="stylesheet" type="text/css" href="./css/swagger-ui.css">
<link rel="icon" type="image/png" href="./img/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./img/favicon-16x16.png" sizes="16x16" />
<style>
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
background: #fafafa;
}
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="./js/swagger-ui-bundle.js">
</script>
<script src="./js/swagger-ui-standalone-preset.js">
</script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "torn.yaml",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
// Uncomment the following three lines for local tests with a fixed API-Key
// onComplete: () => {
// ui.preauthorizeApiKey('ApiKeyAuth', '<put your secret here>');
// }
})
// End Swagger UI call region
window.ui = ui
}
</script>
</body>
</html>

14
js/absolute-path.js Normal file
View File

@@ -0,0 +1,14 @@
/*
* getAbsoluteFSPath
* @return {string} When run in NodeJS env, returns the absolute path to the current directory
* When run outside of NodeJS, will return an error message
*/
const getAbsoluteFSPath = function () {
// detect whether we are running in a browser or nodejs
if (typeof module !== "undefined" && module.exports) {
return require("path").resolve(__dirname)
}
throw new Error('getAbsoluteFSPath can only be called within a Nodejs environment');
}
module.exports = getAbsoluteFSPath

17
js/index.js Normal file
View File

@@ -0,0 +1,17 @@
try {
module.exports.SwaggerUIBundle = require("./swagger-ui-bundle.js")
module.exports.SwaggerUIStandalonePreset = require("./swagger-ui-standalone-preset.js")
} catch(e) {
// swallow the error if there's a problem loading the assets.
// allows this module to support providing the assets for browserish contexts,
// without exploding in a Node context.
//
// see https://github.com/swagger-api/swagger-ui/issues/3291#issuecomment-311195388
// for more information.
}
// `absolutePath` and `getAbsoluteFSPath` are both here because at one point,
// we documented having one and actually implemented the other.
// They were both retained so we don't break anyone's code.
module.exports.absolutePath = require("./absolute-path.js")
module.exports.getAbsoluteFSPath = require("./absolute-path.js")

134
js/swagger-ui-bundle.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

9
js/swagger-ui.js Normal file

File diff suppressed because one or more lines are too long

1
js/swagger-ui.js.map Normal file

File diff suppressed because one or more lines are too long

68
oauth2-redirect.html Normal file
View File

@@ -0,0 +1,68 @@
<!doctype html>
<html lang="en-US">
<title>Swagger UI: OAuth2 Redirect</title>
<body onload="run()">
</body>
</html>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}
arr = qp.split("&")
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value)
}
) : {}
isValid = qp.state === sentState
if ((
oauth2.auth.schema.get("flow") === "accessCode"||
oauth2.auth.schema.get("flow") === "authorizationCode"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
});
}
if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
</script>

1
torn-api Symbolic link
View File

@@ -0,0 +1 @@
torn-api

239
torn.yaml Normal file
View File

@@ -0,0 +1,239 @@
openapi: '3.0.2'
info:
title: Torn API by JotDe [2200962]
version: '1.0'
description: Open API 3.0 description of the Torn-API.
servers:
- url: https://api.torn.com
paths:
/user:
summary: Get information from your own user.
get:
parameters:
- in: query
name: selections
explode: false
schema:
$ref: '#/components/schemas/User'
- $ref: '#/components/parameters/From'
- $ref: '#/components/parameters/To'
responses:
'200':
$ref: '#/components/responses/ChedResponse'
/user/{id}:
summary: Get information from another user.
get:
parameters:
- $ref: '#/components/parameters/Id'
- in: query
name: selections
explode: false
schema:
$ref: '#/components/schemas/User'
- $ref: '#/components/parameters/From'
- $ref: '#/components/parameters/To'
responses:
'200':
$ref: 'torn.yaml#/components/responses/ChedResponse'
/property:
summary: Get information from your own properties.
get:
parameters:
- in: query
name: selections
explode: false
schema:
$ref: "#/components/schemas/Property"
- $ref: '#/components/parameters/From'
- $ref: '#/components/parameters/To'
responses:
"200":
$ref: "#/components/responses/ChedResponse"
/property/{id}:
summary: Get information from properties by id.
get:
parameters:
- $ref: '#/components/parameters/Id'
- in: query
name: selections
explode: false
schema:
$ref: '#/components/schemas/Property'
- $ref: '#/components/parameters/From'
- $ref: '#/components/parameters/To'
responses:
'200':
$ref: '#/components/responses/ChedResponse'
/faction:
summary: Get information from your own faction.
get:
parameters:
- in: query
name: selections
explode: false
schema:
$ref: "#/components/schemas/Faction"
- $ref: '#/components/parameters/From'
- $ref: '#/components/parameters/To'
responses:
"200":
$ref: "#/components/responses/ChedResponse"
/faction/{id}:
summary: Get information from faction by id.
get:
parameters:
- $ref: '#/components/parameters/Id'
- in: query
name: selections
explode: false
schema:
$ref: '#/components/schemas/Faction'
- $ref: '#/components/parameters/From'
- $ref: '#/components/parameters/To'
responses:
'200':
$ref: '#/components/responses/ChedResponse'
/company:
summary: Get information from your own Company.
get:
parameters:
- in: query
name: selections
explode: false
schema:
$ref: "#/components/schemas/Company"
responses:
"200":
$ref: "#/components/responses/ChedResponse"
/company/{id}:
summary: Get information from Company by id.
get:
parameters:
- $ref: '#/components/parameters/Id'
- in: query
name: selections
explode: false
schema:
$ref: '#/components/schemas/Company'
responses:
'200':
$ref: '#/components/responses/ChedResponse'
/market/{id}:
description: Get information from Item Market by id.
get:
parameters:
- $ref: '#/components/parameters/Id'
- in: query
name: selections
explode: false
schema:
$ref: '#/components/schemas/Market'
responses:
'200':
$ref: '#/components/responses/ChedResponse'
/torn:
summary: Get basic information from Torn.
get:
parameters:
- in: query
name: selections
explode: false
schema:
$ref: "#/components/schemas/Torn"
responses:
"200":
$ref: "#/components/responses/ChedResponse"
/torn/{id}:
summary: Get basic information from Torn by id.
get:
parameters:
- $ref: '#/components/parameters/Id'
- in: query
name: selections
explode: false
schema:
$ref: '#/components/schemas/Torn'
responses:
'200':
$ref: '#/components/responses/ChedResponse'
components:
schemas:
Torn:
type: array
items:
type: string
enum: [items, medals, honors, organisedcrimes, gyms, companies, properties, education, stats, stocks,
factiontree, territory, rackets, bank, pawnshop, timestamp]
Market:
type: array
items:
type: string
enum: [bazaar, itemmarket, pointsmarket, timestamp]
Company:
type: array
items:
type: string
enum: [profile, detailed, stock, employees, news, newsfull, timestamp]
Faction:
type: array
items:
type: string
enum: [basic, territory, chain, currency, weapons, armor, temporary, medical, drugs, boosters, cesium,
mainnews, mainnewsfull, attacknews, attacknewsfull, fundsnews, fundsnewsfull, armorynews,
armorynewsfull, crimenews, crimenewsfull, membershipnews, membershipnewsfull, crimes, attacks,
attacksfull, revives, revivesfull, upgrades, stats, contributors, donations, chains, timestamp]
Property:
type: array
items:
type: string
enum: [property, timestamp]
User:
type: array
items:
type: string
enum: [networth, bazaar, display, inventory, hof, travel, events, receivedevents, messages, education,
medals, honors, notifications, personalstats, workstats, crimes, icons, cooldowns, money, perks,
battlestats, bars, profile, basic, attacks, attacksfull, revives, revivesfull, stocks, properties,
jobpoints, merits, refills, weaponexp, ammo, discord, gym, timestamp]
parameters:
Id:
in: path
name: id
description: Id for selected Path
required: true
schema:
type: integer
minimum: 1
From:
in: query
name: from
description: UNIX timestamp can be passed to filter some selections
schema:
type: integer
minimum: 0
To:
in: query
description: UNIX timestamp can be passed to filter some selections
name: to
schema:
type: integer
minimum: 0
responses:
ChedResponse:
description: OK, or not OK, that is the question. (William Chedspeare) - Expect everything.
securitySchemes:
ApiKeyAuth:
type: apiKey
in: query
name: key
security:
- ApiKeyAuth: []
externalDocs:
description: Learn more about user operations provided by this API.
url: https://www.torn.com/api.html