Skip to content

Commit

Permalink
Create working CURL scripts for game storage API
Browse files Browse the repository at this point in the history
- Move user auth curl scripts to `curl-scripts/user-auth`
- Add directory `curl-scripts/game-storage` containing CURL scripts for
all game storage API actions: `create.sh`, `index.sh`, `index-over.sh`,
`index-not-over.sh`, `show.sh`, `sign-up.sh`
  • Loading branch information
terichadbourne committed Jun 11, 2018
1 parent 355eeb6 commit dcd3ac2
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 0 deletions.
25 changes: 25 additions & 0 deletions curl-scripts/game-storage/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

curl --include --request POST "https://tic-tac-toe-wdi.herokuapp.com/games" \
--header "Content-Type: application/json" \
--header "Authorization: Token token=${TOKEN}"

echo

# WORKING!!

# The create action expects a POST with an empty body (e.g '' or '{}' if JSON). If the request is successful, the response will have an HTTP Status of 201 Created, and the body will contain JSON of the created game with player_x set to the user calling create, e.g.:
#
# {
# "game": {
# "id": 3,
# "cells": ["","","","","","","","",""],
# "over": false,
# "player_x": {
# "id": 1,
# "email": "[email protected]"
# },
# "player_o": null
# }
# }
# If the request is unsuccessful, the response will have an HTTP Status of 400 Bad Request, and the response body will be JSON describing the errors.
8 changes: 8 additions & 0 deletions curl-scripts/game-storage/index-not-over.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

curl --include --request GET "https://tic-tac-toe-wdi.herokuapp.com/games?over=false" \
--header "Authorization: Token token=${TOKEN}" \

echo

# WORKING!!
8 changes: 8 additions & 0 deletions curl-scripts/game-storage/index-over.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

curl --include --request GET "https://tic-tac-toe-wdi.herokuapp.com/games?over=true" \
--header "Authorization: Token token=${TOKEN}" \

echo

# WORKING!!
8 changes: 8 additions & 0 deletions curl-scripts/game-storage/index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

curl --include --request GET "https://tic-tac-toe-wdi.herokuapp.com/games" \
--header "Authorization: Token token=${TOKEN}" \

echo

# WORKING!
28 changes: 28 additions & 0 deletions curl-scripts/game-storage/show.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

curl --include --request GET "https://tic-tac-toe-wdi.herokuapp.com/games/${ID}" \
--include \
--header "Content-Type: application/json" \
--header "Authorization: Token token=${TOKEN}" \

echo

# WORKING !!
#
#The show action is a GET specifing the id of the game to retrieve. If the request is successful the status will be 200, OK, and the response body will contain JSON for the game requested, e.g.:
#
# {
# "game": {
# "id": 1,
# "cells": ["o","x","o","x","o","x","o","x","o"],
# "over": true,
# "player_x": {
# "id": 1,
# "email": "[email protected]"
# },
# "player_o": {
# "id": 3,
# "email": "[email protected]"
# }
# }
# }
62 changes: 62 additions & 0 deletions curl-scripts/game-storage/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

curl --include --request PATCH "https://tic-tac-toe-wdi.herokuapp.com/games/${ID}" \
--header "Authorization: Token token=${TOKEN}" \
--header "Content-Type: application/json" \
--data '{
"game": {
"cell": {
"index": "'${INDEX}'",
"value": "'"${VALUE}"'"
},
"over": "'${OVER}'"
}
}'

echo

# WORKING!!

# This update action expects a PATCH with changes to to an existing game, e.g.:
#
# Using an HTML form element this may look like:
#
# <form>
# <input name="game[cell][index]" type="text" value="0">
# <input name="game[cell][value]" type="text" value="x">
# <input name="game[over]" type="text" value="false">
# </form>
# Alternatively, you may want to store the cell index in an HTML element that is not a form. To do this, you could utilize data attributes and add the value and over properties using javascript.
#
# <div data-cell-index='0'>
# </div>
# The update action expects data formatted as such:
#
# {
# "game": {
# "cell": {
# "index": 0,
# "value": "x"
# },
# "over": false
# }
# }
# If the request is successful, the response will have an HTTP Status of 200 OK, and the body will be JSON containing the modified game, e.g.:
#
# {
# "game": {
# "id": 1,
# "cells": ["x","","","","","","","",""],
# "over":false,
# "player_x": {
# "id": 1,
# "email": "[email protected]"
# },
# "player_o": {
# "id": 3,
# "email":
# "[email protected]"
# }
# }
# }
# If the request is unsuccessful, the response will have an HTTP Status of 400 Bad Request, and the response body will be JSON describing the errors.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit dcd3ac2

Please sign in to comment.