mtg-sdk-typescript
An sdk for https://magicthegathering.io/ written in Typescript. Works for JavaScript and TypeScript development.
As of July 31st, 2017, all features of https://magicthegathering.io/ are supported.
Installation
npm install mtgsdk-ts
Examples
In the following examples, requiring the package is assumed.
;
Cards.find (id: string): Promise<Card>;
Gets a single card from its ID.
Magic.Cards.find"08618f8d5ebdc0c4d381ad11f0563dfebb21f4ee".thenconsole.logresult.name; // Blood Scrivener
Cards.where (filter: CardFilter): Promise<Card[]>;
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.then;
Cards.all (filter: CardFilter): MagicEmitter<Card>;
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.on"data", .on"end",;
Sets.find (id: string): Promise<Set>;
Gets a single set from its ID.
Magic.Sets.find"HOU".thenconsole.logresult.name; // Hour of Devastation
Sets.where (block: SetFilter): Promise<Set[]>;
Gets multiple sets.
In the following example, the sets are filtered by block. To see all options, visit the API documentation.
Magic.Sets.where.then;
Sets.all (filter: SetFilter): MagicEmitter<Set>;
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.on"data", .on"end",;
Sets.generateBooster (id: string): Promise<Card[]>;
Generates a booster from the cards of a set.
Magic.Sets.generateBooster"HOU".then;
Types.all (): Promise<string[]>;
Gets a list of all Types that have been printed.
Magic.Types.all.then;
Subtypes.all (): Promise<string[]>;
Gets a list of all Subtypes that have been printed.
Magic.Subtypes.all.then;
Supertypes.all (): Promise<string[]>;
Gets a list of all Supertypes that have been printed.
Magic.Supertypes.all.then;
Formats.all (): Promise<string[]>;
Gets a list of all official Formats.
Magic.Formats.all.then;
MagicEmitter<T>
MagicEmitter.on(event: "data", listener: (data: T) => any): MagicEmitter;
Adds a listener for when data has been received. This method returns the emitter object.
MagicEmitter.on(event: "end", listener: () => any): MagicEmitter;
Adds a listener for when all data has been received. This method returns the emitter object.
MagicEmitter.on(event: "cancel", listener: () => any): MagicEmitter;
Adds a listener for when emitting data has been cancelled. This method returns the emitter object.
MagicEmitter.on(event: "error", listener: (err: Error) => any): MagicEmitter;
Adds a listener for when the emitter errors. This method returns the emitter object.
MagicEmitter.cancel(): void;
Cancels emitting data. Only emits the "cancel" event, not the "end" event.
Contributing
Thanks for wanting to help out! Here's the setup you'll have to do:
git clone https://github.com/Yuudaari/mtg-sdk-typescriptgit clone https://github.com/Yuudaari/tslint.jsoncd mtg-sdk-typescriptnpm 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!