An sdk for https://magicthegathering.io/ written in Typescript. Works for JavaScript and TypeScript development.
As of February 19th, 2018, all features of https://magicthegathering.io/ are supported.
npm install mtgsdk-ts
In the following examples, requiring the package is assumed.
import Magic = require("mtgsdk-ts");
Gets a single card from its ID.
Magic.Cards.find("08618f8d5ebdc0c4d381ad11f0563dfebb21f4ee").then(result => console.log(result.name)); // Blood Scrivener
Gets multiple cards. Truncated to 100 cards. If more than 100 cards are needed, see Cards.all
below.
In the following example, the cards are filtered by name. To see all options, visit the API documentation.
Magic.Cards.where({name: "Nicol"}).then(results => {
for (const card of results) console.log(card.name);
});
Gets all cards. You can set the number of cards to include in each "page" of results, and the page to start on (the first page is 1, not 0). See here for more information about the MagicEmitter.
In the following example, the cards are filtered by type. To see all options, visit the API documentation.
Magic.Cards.all({type: "Planeswalker", page: 2, pageSize: 30}).on("data", card => {
console.log(card.name);
}).on("end", () => {
console.log("done");
});
Gets a single set from its ID.
Magic.Sets.find("HOU").then(result => console.log(result.name)); // Hour of Devastation
Gets multiple sets.
In the following example, the sets are filtered by block. To see all options, visit the API documentation.
Magic.Sets.where({block: "Kaladesh"}).then(results => {
for (const set of results) console.log(set.name);
});
Gets all sets. You can set the number of sets to include in each "page" of results, and the page to start on (the first page is 1, not 0). See here for more information about the MagicEmitter.
In the following example, the sets are not filtered, but can be. To see all options, visit the API documentation.
Magic.Sets.all({page: 5, pageSize: 30}).on("data", set => {
console.log(set.name);
}).on("end", () => {
console.log("done");
});
Generates a booster from the cards of a set.
Magic.Sets.generateBooster("HOU").then(result => {
for (const card of result) console.log(card.name);
});
Gets a list of all Types that have been printed.
Magic.Types.all().then(result => {
for (const type of result) console.log(type);
});
Gets a list of all Subtypes that have been printed.
Magic.Subtypes.all().then(result => {
for (const type of result) console.log(type);
});
Gets a list of all Supertypes that have been printed.
Magic.Supertypes.all().then(result => {
for (const type of result) console.log(type);
});
Gets a list of all official Formats.
Magic.Formats.all().then(result => {
for (const format of result) console.log(format);
});
Adds a listener for when data has been received. This method returns the emitter object.
Adds a listener for when all data has been received. This method returns the emitter object.
Adds a listener for when emitting data has been cancelled. This method returns the emitter object.
Adds a listener for when the emitter errors. This method returns the emitter object.
Cancels emitting data. Only emits the "cancel" event, not the "end" event.
Thanks for wanting to help out! Here's the setup you'll have to do:
git clone https://github.com/Yuudaari/mtg-sdk-typescript
git clone https://github.com/Yuudaari/tslint.json
cd mtg-sdk-typescript
npm install
You can now make changes to the repository.
To compile:
gulp ts
To test:
gulp mocha
To compile, then test:
gulp compile-test
To compile and then test on every file change:
gulp watch
If you want to make large, complex changes, make an issue before creating a PR. If I disagree with the changes you want to make, and you've already made them all in a PR, it'll feel a lot worse than being shot down in an issue, before you've written it all.
Pull Requests may be rejected if outside of the scope of the SDK, or not following the formatting rules. If tslint complains, I will complain. Please don't be mad.
If you add a new feature, please include a test for it in your PR.
Thanks again!