Skip to content
WDI Fullstack Project 2
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bin
config
db
lib/tasks
public
scripts
spec
.editorconfig
.gitignore
.remarkrc
.rubocop.yml
.ruby-version
CONTRIBUTING.md
Gemfile
Gemfile.lock
LICENSE
Procfile
README.md
Rakefile
STYLE.md
config.ru
wakemydyno.txt

README.md

Poker Tracker API

A Rails API that handles User Authentication and storing 'Players' assocaited to a user.

API Link - https://pokertracker.herokuapp.com

Structure

This template follows the standard project structure in Rails 4.

curl command scripts are stored in scripts with names that correspond to API actions.

API

This API handles Authentication and storing 'Players'

Scripts are included in scripts to test built-in actions.

Authentication

Verb URI Pattern Controller#Action
POST /sign-up users#signup
POST /sign-in users#signin
PATCH /change-password/:id users#changepw
DELETE /sign-out/:id users#signout

POST /sign-up

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/sign-up"
curl "${API}${URL_PATH}" \
  --include \
  --request POST \
  --header "Content-Type: application/json" \
  --data '{
    "credentials": {
      "email": "'"${EMAIL}"'",
      "name": "'"${NAME}"'",
      "password": "'"${PASSWORD}"'",
      "password_confirmation": "'"${PASSWORD}"'"
    }
  }'
EMAIL=ava@bob.com PASSWORD=hannah NAME=hannah scripts/sign-up.sh

Response:

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8

{
  "user": {
    "id": 1,
    "email": "ava@bob.com",
    "name": "hannah"
  }
}

POST /sign-in

Request:

curl http://localhost:4741/sign-in \
  --include \
  --request POST \
  --header "Content-Type: application/json" \
  --data '{
    "credentials": {
      "email": "'"${EMAIL}"'",
      "password": "'"${PASSWORD}"'"
    }
  }'
EMAIL=ava@bob.com PASSWORD=hannah scripts/sign-in.sh

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "user": {
    "id": 1,
    "email": "ava@bob.com",
    "name": "hannah",
    "token": "BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f"
  }
}

PATCH /change-password/:id

Request:

curl --include --request PATCH "http://localhost:4741/change-password/$ID" \
  --header "Authorization: Token token=$TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "passwords": {
      "old": "'"${OLDPW}"'",
      "new": "'"${NEWPW}"'"
    }
  }'
ID=1 OLDPW=hannah NEWPW=elle TOKEN=<token> scripts/change-password.sh

Response:

HTTP/1.1 204 No Content

DELETE /sign-out/:id

Request:

curl http://localhost:4741/sign-out/$ID \
  --include \
  --request DELETE \
  --header "Authorization: Token token=$TOKEN"
ID=1 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/sign-out.sh

Response:

HTTP/1.1 204 No Content

Players

Verb URI Pattern Controller#Action
GET /players players#index
POST /players/create players#create
PATCH /player players#show
PATCH /players/save players#update
DELETE /players/:id players#destroy

GET /players

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/players"
curl "${API}${URL_PATH}" \
  --include \
  --request GET \
  --header "Authorization: Token token=$TOKEN"
TOKEN=<token> scripts/get-players.sh

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "players":[]
}

POST /players/create

Only fires on frontend the first time the user sits at a table.

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/players/create"
curl "${API}${URL_PATH}" \
  --include \
  --request POST \
  --header "Authorization: Token token=${TOKEN}" \
  --header "Content-Type: application/json" \
  --data '{
    "player": {
      "name": "Example"
    }
  }'
TOKEN=<token> scripts/create_user_player.sh

Response:

HTTP/1.1 201 CREATED
Content-Type: application/json; charset=utf-8

{
  "player":{
    "id":1,
    "name":"Example",
    "hand_count":0,
    "call_preflop":0,
    "raise_preflop":0,
    "call_or_raise_preflop":0,
    "reraise_preflop":0,
    "call_to_reraise_preflop":0,
    "fold_on_reraise_preflop":0
    }
}

PATCH /player

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/player"
curl "${API}${URL_PATH}" \
  --include \
  --request PATCH \
  --header "Authorization: Token token=$TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "player": {
      "name": "Example"
    }
  }'
TOKEN=<token> scripts/get-player.sh

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "player":{
    "id":1,
    "name":"Example",
    "hand_count":0,
    "call_preflop":0,
    "raise_preflop":0,
    "call_or_raise_preflop":0,
    "reraise_preflop":0,
    "call_to_reraise_preflop":0,
    "fold_on_reraise_preflop":0
    }
}

/players/save

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/players/save"
curl "${API}${URL_PATH}" \
  --include \
  --request PATCH \
  --header "Authorization: Token token=${TOKEN}" \
  --header "Content-Type: application/json" \
  --data '{
    "player": {
      "name": "Example",
      "call_or_raise_preflop": "5",
      "call_preflop": "5",
      "call_to_reraise_preflop": "5",
      "fold_on_reraise_preflop": "5",
      "hand_count": "10",
      "raise_preflop": "5",
      "reraise_preflop": "5"
    }
  }'
TOKEN=<token> scripts/save_player.sh

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "player":{
    "id":1,
    "name":"Example",
    "hand_count":10,
    "call_preflop":5,
    "raise_preflop":5,
    "call_or_raise_preflop":5,
    "reraise_preflop":5,
    "call_to_reraise_preflop":5,
    "fold_on_reraise_preflop":5
    }
}

DELETE /players/:id

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/players/1"
curl "${API}${URL_PATH}" \
  --include \
  --request DELETE \
  --header "Authorization: Token token=${TOKEN}"
TOKEN=<token> scripts/delete_player.sh

Response:

HTTP/1.1 204 No Content
You can’t perform that action at this time.