Ajout createAgent, getAgent, listAgents, getPublicAgent, getWaypoint, getMarket et correction de listSystems et de listWaypointsInSystems

michael
Makaci Michael Gabriel ago%!(EXTRA string=1 year)
parent 8fe3f4c54f
commit c91a3b6f72
  1. 2
      .gitignore
  2. 16
      index.html
  3. 84
      scripts/agent.js
  4. 29
      scripts/main.js
  5. 113
      scripts/systems.js
  6. 72
      systems.js

2
.gitignore vendored

@ -1,2 +0,0 @@
index.html
script.js

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script
src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
crossorigin="anonymous"
></script>
<script type="module" src="./scripts/main.js" defer></script>
<title>SpaceTraders</title>
</head>
<body></body>
</html>

@ -0,0 +1,84 @@
export async function createAgent(symbol, faction) {
let agent;
await $.ajax("https://api.spacetraders.io/v2/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
data: JSON.stringify({
symbol: symbol,
faction: faction,
}),
success: function (response) {
agent = response.data;
},
error: function (error) {
console.log(error);
},
});
return agent;
}
export async function getAgent(token) {
let agent;
await $.ajax("https://api.spacetraders.io/v2/my/agent", {
method: "GET",
headers: {
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
success: function (response) {
agent = response.data;
},
error: function (error) {
console.log(error);
},
});
return agent;
}
export async function listAgents(limit, page) {
let agents;
await $.ajax("https://api.spacetraders.io/v2/agents", {
method: "GET",
headers: {
Accept: "application/json",
},
data: {
limit: limit,
page: page,
},
success: function (response) {
agents = response.data;
},
error: function (error) {
console.log(error);
},
});
return agents;
}
export async function getPublicAgent(agentSymbol) {
let agent;
await $.ajax(`https://api.spacetraders.io/v2/agents/${agentSymbol}`, {
method: "GET",
headers: {
Accept: "application/json",
},
success: function (response) {
agent = response.data;
},
error: function (error) {
console.log(error);
},
});
return agent;
}

@ -0,0 +1,29 @@
"use strict";
import { createAgent } from "./agent.js";
import { getAgent } from "./agent.js";
import { listAgents } from "./agent.js";
import { getPublicAgent } from "./agent.js";
import { listSystems } from "./systems.js";
import { getSystem } from "./systems.js";
import { listWaypointsInSystem } from "./systems.js";
import { getWaypoint } from "./systems.js";
import { getMarket } from "./systems.js";
const token =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiVEVTVDUzNTYiLCJ2ZXJzaW9uIjoidjIuMS4yIiwicmVzZXRfZGF0ZSI6IjIwMjMtMTEtMTgiLCJpYXQiOjE3MDA4MzEzOTEsInN1YiI6ImFnZW50LXRva2VuIn0.H4C3rNwgaBf6ych4txV7WO3jwt-ZAsb6jWSnQ3EMZfO7BgVbUW00a3uMtiQ7qCBuZ91YnmtUL8PZSRnR1RzCAjUd6Y64Kwt8cARgSZ56a08zIreXQ66WsXpm-pVXHKlrD7LeA9sHzZGhD9yADnghbJmCy6UoiYhgr8I7OwL9EIf-nb3B5l2UTchiNHTNmKjsggycQDDaK2yCcKXhy6rro8-ptogU5QFFYiIbshCiEos4Sc-CHbKci-DQpzWb9FcsNntb1PdZcm2hhjGDi4KD8Q1Ccvd-m1vTH4SwV1xt66tT5SMMuBA7nblsC2DlNV682PZi27XcpibMIyWoSQ938w";
// const systemSym = "X1-KD70";
// const waypointSym = "X1-KD70-AA1X";
$(document).ready(async function () {
let systemSymbol = await listSystems(1, 1);
systemSymbol = systemSymbol[0].symbol;
let waypointSymbol = await listWaypointsInSystem(1, 1, systemSymbol);
waypointSymbol = waypointSymbol[0].symbol;
let market = await getMarket(systemSymbol, waypointSymbol, token);
console.log(market);
});

@ -0,0 +1,113 @@
export async function listSystems(limit, page) {
let systems;
await $.ajax("https://api.spacetraders.io/v2/systems/", {
method: "GET",
headers: {
Accept: "application/json",
},
data: {
limit: limit,
page: page,
},
success: function (response) {
systems = response.data;
},
error: function (error) {
console.log(error);
},
});
return systems;
}
export async function getSystem(systemSymbol) {
let system;
await $.ajax(`https://api.spacetraders.io/v2/systems/${systemSymbol}`, {
method: "GET",
headers: {
Accept: "application/json",
},
success: function (response) {
system = response.data;
},
error: function (error) {
console.log(error);
},
});
return system;
}
export async function listWaypointsInSystem(limit, page, systemSymbol) {
let waypoints;
await $.ajax(
`https://api.spacetraders.io/v2/systems/${systemSymbol}/waypoints`,
{
method: "GET",
headers: {
Accept: "application/json",
},
data: {
limit: limit,
page: page,
},
success: function (response) {
waypoints = response.data;
},
error: function (error) {
console.log(error);
},
}
);
return waypoints;
}
export async function getWaypoint(systemSymbol, waypointSymbol) {
let waypoint;
await $.ajax(
`https://api.spacetraders.io/v2/systems/${systemSymbol}/waypoints/${waypointSymbol}`,
{
method: "GET",
headers: {
Accept: "application/json",
},
success: function (response) {
waypoint = response.data;
},
error: function (error) {
console.log(error);
},
}
);
return waypoint;
}
export async function getMarket(systemSymbol, waypointSymbol, token) {
let market;
await $.ajax(
`https://api.spacetraders.io/v2/systems/X1-KD70/waypoints/X1-KD70-AA1X/market`,
{
method: "GET",
headers: {
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
success: function (response) {
console.log(response);
market = response;
},
error: function (error) {
console.log(error);
},
}
);
return market;
}

@ -1,72 +0,0 @@
export async function listSystems(limit, pages){
let systems = [];
for(let page = 1; page <= pages; page++){
await $.ajax('https://api.spacetraders.io/v2/systems/', {
method: 'GET',
headers: {
Accept: 'application/json',
},
data: {
limit: limit,
page: page
},
success: function(response){
response.data.forEach(sytem => {
systems.push(sytem);
});
},
error: function(error){
console.log(error);
}
});
}
return systems;
}
export async function getSystem(systemSymbol){
let system;
await $.ajax(`https://api.spacetraders.io/v2/systems/${systemSymbol}`, {
method: 'GET',
headers: {
Accept: 'application/json'
},
success: function(response){
system = response.data;
},
error: function(error){
console.log(error);
}
});
return system;
}
export async function listWaypointsInSystem(limit, pages, systemSymbol){
let waypoints = [];
for(let page = 1; page <= pages; page++){
await $.ajax(`https://api.spacetraders.io/v2/systems/${systemSymbol}/waypoints`, {
method: 'GET',
headers: {
Accept: 'application/json',
},
data: {
limit: limit,
page: page
},
success: function(response){
response.data.forEach(waypoint => {
waypoints.push(waypoint);
});
},
error: function(error){
console.log(error);
}
});
}
return waypoints;
}
Loading…
Cancel
Save