sprcl
Version:
Simple API client for Clash of Clans, Clash Royale, and Brawl Stars
97 lines (91 loc) • 2.68 kB
JavaScript
class ClanMember {
constructor(tag, name, role, expLevel, trophies, arena, clanRank, previousClanRank, donations, donationsReceived, lastSeen) {
this.tag = tag;
this.name = name;
this.role = role;
this.expLevel = expLevel;
this.trophies = trophies;
this.arena = arena;
this.clanRank = clanRank;
this.previousClanRank = previousClanRank;
this.donations = donations;
this.donationsReceived = donationsReceived;
this.lastSeen = lastSeen;
}
static fromJSON(jsonObject) {
return new ClanMember(
jsonObject.tag,
jsonObject.name,
jsonObject.role,
jsonObject.expLevel,
jsonObject.trophies,
jsonObject.arena,
jsonObject.clanRank,
jsonObject.previousClanRank,
jsonObject.donations,
jsonObject.donationsReceived,
jsonObject.lastSeen
);
}
toString() {
return this.name;
}
}
class Clan {
constructor(
tag,
name,
type,
description,
location,
badgeId,
clanScore,
clanWarTrophies,
requiredTrophies,
donationsPerWeek,
clanChestStatus,
clanChestLevel,
clanChestMaxLevel,
members,
memberList
) {
this.tag = tag;
this.name = name;
this.type = type;
this.description = description;
this.location = location;
this.badgeId = badgeId;
this.clanScore = clanScore;
this.clanWarTrophies = clanWarTrophies;
this.requiredTrophies = requiredTrophies;
this.donationsPerWeek = donationsPerWeek;
this.clanChestStatus = clanChestStatus;
this.clanChestLevel = clanChestLevel;
this.clanChestMaxLevel = clanChestMaxLevel;
this.members = members;
this.memberList = memberList;
}
static fromJSON(jsonObject) {
return new Clan(
jsonObject.tag,
jsonObject.name,
jsonObject.type,
jsonObject.description,
jsonObject.location,
jsonObject.badgeId,
jsonObject.clanScore,
jsonObject.clanWarTrophies,
jsonObject.requiredTrophies,
jsonObject.donationsPerWeek,
jsonObject.clanChestStatus,
jsonObject.clanChestLevel,
jsonObject.clanChestMaxLevel,
jsonObject.members,
jsonObject.memberList?.map(ClanMember.fromJSON) || []
);
}
toString() {
return this.name;
}
}
module.exports = { Clan };