Code Monkey home page Code Monkey logo

obb-api's Introduction

OBB API

![Gitter](https://badges.gitter.im/Join Chat.svg) Build Status Coverage Status Dependency Status Uptime

This API is used by Orion's Belt BattleGrounds to persist and process battles and the core game's funcionality. The game has several APIs available:

API Description
OBB API Persistent game functionality
OBB Auth API Allows to trade auth credentials for an auth token, recognized by all services
OBB Rules API (Stateless) Battle information: units metadata, turn processing and other utilities

HTTP API

Available at api.orionsbelt.eu.

GET / api version and generic information

> curl http://api.orionsbelt.eu/
{"name":"obb-api"}

GET /game/:id

Gets the game with the given id. If the game is in deploy state, then the stash and elements will be removed, to prevent a player to have information about the opponent's deploy before time. However, if you pass the player's token, the information specific to the given player will be present.

> curl http://api.orionsbelt.eu/game/545790d6e4b0406f6fc19315
{  
   "viewed-by":null,
   "_id":"545790d6e4b0406f6fc19315",
   "battle":{  
      "state":"deploy",
      "stash":{
          "p2":{},
          "p1":{}
      },
      "width":8,
      "height":8,
      "terrain":"rock",
      "elements":{}
   },
   "p2":{ "name":"Pyro" },
   "p1":{ "name":"donbonifacio" }
}

GET /lobby/open-games gets the games on the lobby

Returns the games on the lobby, that may be joined by players.

GET /player/latest-games lists latest created games

Returns the last games created for the player with the provided token.

curl -XGET http://api.orionsbelt.eu/player/latest-games?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkb25ib25pZmFjaW8iLCJleHAiOjE0MTQ2MTYxMTIsImlhdCI6MTQxNDcwMjUxMn0.lisfjmr4ShsYJt2FX8FfJrQ828HVbPGFKF5BL9GMEbw
[
   {
      "_id":"545790d6e4b0406f6fc19315",
      "state":"deploy",
      "p1":{"name":"donbonifacio"},
      "p2":{"name":"Pyro"}
   }
   ...
]

POST /game/create/friendly creates a friendly match

Creates a match bettween two players. Returns the board ready to be deployed. You can specify per player starting stash. The the opponent isn't provided, the game is opened and may me joined later.

curl -XPOST http://api.orionsbelt.eu/game/create/friendly?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkb25ib25pZmFjaW8iLCJleHAiOjE0MTQ2MTYxMTIsImlhdCI6MTQxNDcwMjUxMn0.lisfjmr4ShsYJt2FX8FfJrQ828HVbPGFKF5BL9GMEbw \
     -H "Content-Type: application/json" \
     -d '{"challenger" : "donbonifacio", "opponent" : "Pyro", "stash" : {"challenger": {"rain":1}, "opponent": {"kamikaze":1}}}'

If you ommit the stash, a random stash with 8 units will be generated.

curl -XPOST http://api.orionsbelt.eu/game/create/friendly?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkb25ib25pZmFjaW8iLCJleHAiOjE0MTQ2MTYxMTIsImlhdCI6MTQxNDcwMjUxMn0.lisfjmr4ShsYJt2FX8FfJrQ828HVbPGFKF5BL9GMEbw \
     -H "Content-Type: application/json" \
     -d '{"challenger" : "donbonifacio", "opponent" : "Pyro"}'
{  
   "battle":{  
      "state":"deploy",
      "stash":{  
         "p2":{  
            "anubis":100,
            "heavy-seeker":25,
            "nova":25,
            "kamikaze":50,
            "rain":100,
            "scarab":50,
            "worm":50,
            "crusader":25
         },
         "p1":{  
            "anubis":100,
            "heavy-seeker":25,
            "nova":25,
            "kamikaze":50,
            "rain":100,
            "scarab":50,
            "worm":50,
            "crusader":25
         }
      },
      "width":8,
      "height":8,
      "terrain":"terrest",
      "elements":{}
   },
   "p2":{ "name":"Pyro" },
   "p1":{ "name":"donbonifacio" },
   "_id":"54565621300418dc8ed15cf1"
}

PUT /game/:id/join joins a friendly match

When a game is created without an opponent, another player can join the game.

curl -XPUT http://api.orionsbelt.eu/game/some_id/join?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkb25ib25pZmFjaW8iLCJleHAiOjE0MTQ2MTYxMTIsImlhdCI6MTQxNDcwMjUxMn0.lisfjmr4ShsYJt2FX8FfJrQ828HVbPGFKF5BL9GMEbw
{  
   "battle":{  
      "state":"deploy",
      "stash":{  
         "p2":{  
            "anubis":100,
            "heavy-seeker":25,
            "nova":25,
            "kamikaze":50,
            "rain":100,
            "scarab":50,
            "worm":50,
            "crusader":25
         },
         "p1":{  
            "anubis":100,
            "heavy-seeker":25,
            "nova":25,
            "kamikaze":50,
            "rain":100,
            "scarab":50,
            "worm":50,
            "crusader":25
         }
      },
      "width":8,
      "height":8,
      "terrain":"terrest",
      "elements":{}
   },
   "p2":{ "name":"Pyro" },
   "p1":{ "name":"donbonifacio" },
   "_id":"54565621300418dc8ed15cf1"
}

PUT /game/:id/deploy performs deploy actions

Performs the deploy actions for the game with the given :id. It's mandatory that the auth token be given and that belongs to one of the players. When both players have both deployed, the game will auto start and the first one will be randomly selected.

curl -XPUT http://api.orionsbelt.eu/game/some_id/deploy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkb25ib25pZmFjaW8iLCJleHAiOjE0MTQ2MTYxMTIsImlhdCI6MTQxNDcwMjUxMn0.lisfjmr4ShsYJt2FX8FfJrQ828HVbPGFKF5BL9GMEbw \
     -H "Content-Type: application/json" \
     -d '{ actions : [ ["deploy", 10, "rain", [8, 8]] ]}'
{  
   "battle":{  
      "state":"deploy",
      "stash":{  
         "p2":{  
            "anubis":100,
            "heavy-seeker":25,
            "nova":25,
            "kamikaze":50,
            "rain":100,
            "scarab":50,
            "worm":50,
            "crusader":25
         },
         "p1":{}
      },
      "width":8,
      "height":8,
      "terrain":"terrest",
      "elements":{
         "[8 8" : {
            "unit" : "rain",
            "coordinate" : [8, 8],
            "player" : "p1",
            "quantity" : 10
         }
      }
   },
   "p2":{ "name":"Pyro" },
   "p1":{ "name":"donbonifacio" },
   "_id":"54565621300418dc8ed15cf1"
}

GET /auth/verify verifies the OBB token

Given a token, will analyse it and output information about it, for example if it's considered valid.

> curl http://api.orionsbelt.eu/auth/verify?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkb25ib25pZmFjaW8iLCJleHAiOjE0MTQ2MTYxMTIsImlhdCI6MTQxNDcwMjUxMn0.lisfjmr4ShsYJt2FX8FfJrQ828HVbPGFKF5BL9GMEbw
{
  "header": {
    "alg": "HS256",
    "typ": "JWT"
  },
  "claims": {
    "iss": "donbonifacio",
    "exp": 1414616112,
    "iat": 1414702512
  },
  "signature": "lisfjmr4ShsYJt2FX8FfJrQ828HVbPGFKF5BL9GMEbw",
  "valid": true
}

GET /auth/enforce enforces the OBB token

The same interface as /auth/verify but will return a 401 Unauthorized if the token is invalid.

GET /auth/anonymize?username=:anon generates a token for an anonymous user

The :anon param must be in the format of anonymous:<random_identifier>.

{
   "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhbm9ueW1vdXM6MTQyMzc0NDc5Mzk4MC1qb2lsbXVpdnVwYiIsImV4cCI6MTQyNDYwODc5NCwiaWF0IjoxNDIzNzQ0Nzk0fQ.sAWiatJmuSnzXIm96VIa5sqH1gpvQlcto2ATMl0zZAE"
}

obb-api's People

Contributors

donbonifacio avatar

Watchers

James Cloos avatar Roma Chi avatar

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.