Giter Club home page Giter Club logo

magic-api's Introduction

magic-api

magic-api is a Magic: The Gathering card database and API for PHP.

Overview

MtG card information is available from the official Gatherer reference, but it doesn't provide an API. magic-api requests cards from Gatherer, strips the page down to the card data, and caches it in a MySQL database. If the user's search string is new and unique, that is also cached (in a seperate table known as the 'map'), so we can route future searches directly to the DB entry for a card.

The Scry front-end is also included in this repo. This is the name given to my personal installation, Scry.me.uk, which you can freely re-brand and re-publish (preferably using a different service name).

Try it

Scry is my pet installation of magic-api. It has learnt that "Tajic", and "Blade of the legion" both unambiguously refer to 'Tajic, blade of the legion'. Here, you can simulate a user search for "Tajic": http://scry.me.uk/api.php?metrics=1&name=Tajic

Features

  • Search for cards by name
  • Returns JSON object of card (see API)
  • Provides autocomplete for front-end development
  • 2-10 seconds to initially fetch a card from Wizards' Gatherer
  • About 0.01 seconds to return a cached card

Setup

Requires PHP5 and a php.ini with allow_url_fopen Put your database connection information in db.php and install all the files together in a directory. api.php is the linker; check out the required files in there.

Run the create scripts from the /sql folder on your MySQL DB. If you change the table names from the defaults, alter the table name variables at the top of DAL.php. Map records have a datetime -- if you want to use a timezone other than UTC, alter the $db_now variable in DAL.php

API

Input

Parameters: name, metrics
Example: http://scry.me.uk/api.php?name=Forest or http://scry.me.uk/api.php?name=Forest&metrics=1
N.b. metrics is really lazy... if you specify anything that can be loosely interpreted as true then it will activate.

Output

A JSON object. I recommend JSONview for Firefox or Chrome to view the returned values from magic-api. Fields with no value will not appear in the returned object:

Success:

name,
mana_cost,
converted_mana_cost,
types,
card_text,
flavor_text,
watermark,
power_toughness,
expansion,
rarity,
card_number,
artist,
request_time

When metrics is on, there will be an additional caching field which can contain: 'found in map', 'added to map', 'mapping failed', 'added to cache and map', 'cache or map failed'.

Error:

error,
request_time

Error text is user-friendly and can be output as-is.

Encoding

Anything represented with an icon on Gatherer (such as Mana and Tap/Untap) will be parsed using the original alt-text, and placed in {braces}. Single-coloured mana is shortened to a single letter: W/U/B/R/G (U is blue). The icon 'Variable colorless' is shorted to {X} as it appears on cards. Multi-coloured mana is represented like {Red or White} and is not shortened. Phyrexian mana comes out like {Phyrexian Green}.

Lines of card text are delimited by an underscore flanked by spaces, for example:

"card_text": "Flying _ Lifelink (Damage dealt by this creature also causes you to gain that much life.)"

You can easily split/explode the strings on '_' to get seperate lines.
Quotes are escaped with backslashes:

"flavor_text": "\"One day every pillar will be a tree and every hall a glade.\"—Trostani"

Support

People occassionally email me for help and advice on setting up an MtG related website. Feel free to send any queries to [email protected]. If you would like me to host a private magic-api node to power your mobile app or something, I can arrange that for £1 per month ($1.70).

Amaze such magic? so web? wow plz send much dogecoin: DUPMGGzzZYr1qihXy7EhYtPjxaevAjvsEc


Stephen Griffiths - @SteGriff - [email protected]

magic-api's People

Contributors

aloisdg avatar stegriff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

magic-api's Issues

Investigate some searches timing out

Some searches like 'Staunch hearted warrior' are running endlessly. Real card name is 'staunch-hearted warrior'. Will investigate -- probably a bug in the card_extractor.

Card text field size may be insufficient for some cards

~~I made a design assumption that card texts would not be longer than 255 characters. Some cards, for example, "Varolz, the Scar-Striped", exceed this limit.

I'll write a database alteration to expand card text to a new limit.~~

The character limit is now 500, but it remains to be seen if there are cards with longer text. This is not well documented.

Card name field can not contain longest card name

The longest card name is "Our Market Research Shows That Players Like Really Long Card Names So We Made this Card to Have the Absolute Longest Card Name Ever Elemental" from Unhinged.

This is 141 characters long. The field is currently varchar(50), so it needs to be expanded.

[http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=74237]

MTG image no longer exists

The Scry frontend tries to load images from mtgimage.com which was taken down due to a copyright claim by WotC (fair enough).

Remove this functionality

Duplicate cards going into database

Assume Ætherling is in the database (first character is unicode combined AE). If a user searches for Aetherling (using regular ASCII), the database search does not find the existing entry. As a result, Ætherling is downloaded again, and put in a new record.

This also happens with partial names of long, unambiguous card names. For example, 'Our Market Research Shows' will keep downloading new copies of the long-name card.

Remedy ideas:

  • DB field for 'original query' to store the search string which downloaded the record. Can compare against this before card name when searching for cards.
  • Do character conversion some way to fix comparisons with Unicode, and use LIKE statements to catch long card names

Include the multiverse ID

Having the multiverse ID available in the API would be a huge help. This would allow a developer to link to the gatherer page, look up card images from mtgimage, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.