This repository was archived by the owner on Jan 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Deck Builder JSON API
TheBuzzSaw edited this page Jul 16, 2015
·
6 revisions
The endpoint /api/decks/submit accepts POST data in the form of a JSON document. If a new deck is being submitted, the deck ID is omitted.
{
"name": "Jawa X-Wings of DOOM",
"description": "This deck has never lost... because I never use it.",
"strategy": "Deploy Jawas into X-wings. What else?",
"is_light_side": true,
"is_public": true,
"cards": [
{ "card_id": 15, "deck_count": 1, "start_count": 0 },
{ "card_id": 200, "deck_count": 1, "start_count": 0 },
{ "card_id": 438, "deck_count": 2, "start_count": 0 },
{ "card_id": 505, "deck_count": 1, "start_count": 0 }
]
}
If an existing deck is being edited, the deck ID is included.
{
"deck_id": 78,
"name": "Jawa X-Wings of DOOM",
"description": "This deck has never lost... because I never use it.",
"strategy": "Deploy Jawas into X-wings. What else?",
"is_light_side": true,
"is_public": true,
"cards": [
{ "card_id": 15, "deck_count": 1, "start_count": 0 },
{ "card_id": 200, "deck_count": 1, "start_count": 0 },
{ "card_id": 438, "deck_count": 1, "start_count": 0 },
{ "card_id": 679, "deck_count": 2, "start_count": 0 }
]
}
Deck updates use SQL transactions to simplify the process and ensure that the entire update succeeds or fails as a whole.
BEGIN TRANSACTION
UPDATE decks SET ... WHERE deck_id = 78;
DELETE FROM deck_cards WHERE deck_id = 78;
INSERT INTO deck_cards ...;
COMMIT
If the transaction succeeds, it returns status 200; otherwise it returns status 500 and performs a rollback. If the deck ID is included and the card list omitted, it only updates the deck meta data; no cards are added or removed.
{
"deck_id": 78,
"name": "Jawa X-Wings of DOOM",
"description": "This deck has never lost... because I never use it.",
"strategy": "Deploy Jawas into X-wings. What else?",
"is_light_side": true,
"is_public": true
}
Only an UPDATE statement to the deck table is necessary.