1.5.0 • Published 8 months ago
leghe-fantacalcio v1.5.0
Leghe Fantacalcio Client
A Typescript client to interact with https://leghe.fantacalcio.it/
Installation
npm i leghe-fantacalcio
Configuration
Create a file credentials.json in a conf directory.
{
"username": "YOUR_USERNAME",
"password": "YOUR_PASSWORD",
"appkey": "APP_KEY",
"webkey": "WEB_KEY"
}
Examples
Get your leagues
const FantasyFootballClient = require("leghe-fantacalcio").default;
const conf = require("./conf/config.json");
const main = async () => {
const client = new FantasyFootballClient(
conf.appkey,
conf.webkey
);
let user = await client.login(conf.username, conf.password);
let leagues = await client.getLeagues(user.token);
console.log(leagues);
};
main()
Get league by id
const FantasyFootballClient = require("leghe-fantacalcio").default;
const conf = require("./conf/config.json");
const main = async () => {
const client = new FantasyFootballClient(
conf.appkey,
conf.webkey
);
let user = await client.login(conf.username, conf.password);
let leagues = await client.getLeagues(user.token);
let league = await client.getLeague(user.token, leagues[0].id);
console.log(league);
};
main()
Get League's Teams
const FantasyFootballClient = require("leghe-fantacalcio").default;
const conf = require("./conf/config.json");
const main = async () => {
const client = new FantasyFootballClient(
conf.appkey,
conf.webkey
);
let user = await client.login(conf.username, conf.password);
let leagues = await client.getLeagues(user.token);
let league = await client.getLeague(user.token, leagues[0].id);
console.log(league.teams);
};
main()
Buy a Player
const FantasyFootballClient = require("leghe-fantacalcio").default;
const conf = require("./conf/config.json");
const main = async () => {
const client = new FantasyFootballClient(
conf.appkey,
conf.webkey
);
let user = await client.login(conf.username, conf.password);
let leagues = await client.getLeagues(user.token);
let playerId = 5453
let teamId = 2321312
let price = 20
let result = await client.buyPlayer(user.token, leagues[0].id, playerId, teamId, price)
console.log(result)
};
main()
Release a Player
const FantasyFootballClient = require("leghe-fantacalcio").default;
const conf = require("./conf/config.json");
const main = async () => {
const client = new FantasyFootballClient(
conf.appkey,
conf.webkey
);
let user = await client.login(conf.username, conf.password);
let leagues = await client.getLeagues(user.token);
let playerId = 5453
let teamId = 2321312
let price = 20
let result = await client.releasePlayer(user.token, leagues[0].id, playerId, teamId, price)
console.log(result)
};
main()