1.0.5 • Published 5 months ago
active_deck v1.0.5
ActiveDeck JS SDK
Integrate ActiveDeck into your website or web application with the ActiveDeck JS SDK.
Installation
yarn add activedeck
Usage
Decks
const deck = await activeDeck.decks.create();
const cards = await activeDeck.decks.draw(39, {
count: 2,
});
const deck = await activeDeck.decks.setup(40, {
shuffle: true,
});
const deck = await activeDeck.decks.fetch(40);
const decks = await activeDeck.decks.fetchAll();
const deck = await activeDeck.decks.destroy(40);
The Deck Object
{
"id": 184,
"endpoint": "/api/v1/decks/184",
"cards_left": 52,
"cards": [
{
"rank": "Queen",
"suit": "Clubs",
"deck_id": 184,
"position": 1,
"image_url": "https://lbp.nyc3.cdn.digitaloceanspaces.com/cards/QC.png",
"dealt": false
},
{
"rank": "10",
"suit": "Clubs",
"deck_id": 184,
"position": 2,
"image_url": "https://lbp.nyc3.cdn.digitaloceanspaces.com/cards/0C.png",
"dealt": false
},
...
],
"drawn_cards": []
}
Players
let player = await activeDeck.players.create({
name: "Bob Hope",
turn: true,
score: 0,
dealer: false,
chips_attributes: [
{
value: 1000,
},
],
});
player = await activeDeck.players.update(29, {
name: "Bob Hope Sr.",
turn: true,
score: 1,
chips_attributes: [
{
value: 2500,
},
],
});
player = await activeDeck.players.fetch(29);
console.log(player);
The player object
{
"id": 29,
"name": "Bobbyyyy",
"dealer": false,
"turn": true,
"score": 1,
"game_id": 12,
"balance": 2500,
"formatted_balance": "$2,500.00",
"endpoint": "/api/v1/players/32",
"cards": [],
"chips": [
{
"value": 2500,
"formatted_value": "$2,500.00",
"holder_id": 29,
"holder_type": "Player"
}
],
"bets": []
}
Games
const game = await activeDeck.games.create({
game: {
decks: 1,
players_attributes: [
{
name: "Bobbyyyy",
chips_attributes: [
{
value: 2500,
},
],
},
],
},
});
const game = await activeDeck.games.fetch(21);
The game object
{
"id": 21,
"endpoint": "/api/v1/games/21",
"decks_count": 1,
"players_count": 1,
"players": [
{
"id": 41,
"name": "Bobbyyyy",
"dealer": false,
"turn": false,
"score": 0,
"game_id": 21,
"balance": 2500.0,
"formatted_balance": "$2,500.00",
"endpoint": "/api/v1/players/41",
"cards": [],
"chips": [
{
"value": 2500.0,
"formatted_value": "$2,500.00",
"holder_id": 41,
"holder_type": "Player"
}
],
"bets": []
}
],
"decks": [
{
"id": 50,
"endpoint": "/api/v1/decks/50",
"cards_left": 52,
"cards": [
{
"rank": "3",
"suit": "Spades",
"deck_id": 50,
"position": 1,
"image_url": "https://lbp.nyc3.cdn.digitaloceanspaces.com/cards/3S.png",
"dealt": false
},
{
"rank": "9",
"suit": "Spades",
"deck_id": 50,
"position": 2,
"image_url": "https://lbp.nyc3.cdn.digitaloceanspaces.com/cards/9S.png",
"dealt": false
},
...
],
"drawn_cards": []
}
],
"bets": []
}
Bets
const bet = await activeDeck.bets.create({
bet: {
player_id: 12,
amount: 10,
},
});
const bet = await activeDeck.bets.update(1, {
status: "won",
});
console.log(bet);
The bet object
{
"id": 33,
"amount": "10",
"status": "placed",
"endpoint": "/api/v1/bets/33",
"player": {
"endpoint": "/api/v1/players/111",
"id": 111,
"new_balance": 2490.0,
"new_balance_formatted": "$2,490.00"
},
"game": {
"endpoint": "/api/v1/games/83",
"id": 83
}
}