Skip to content

Instantly share code, notes, and snippets.

@mdirkse
Last active May 8, 2018 22:10
Show Gist options
  • Save mdirkse/0d5cae7d6a49b65ac69b1aa62cf59400 to your computer and use it in GitHub Desktop.
Save mdirkse/0d5cae7d6a49b65ac69b1aa62cf59400 to your computer and use it in GitHub Desktop.
Get Wiremock stub data from the football-data.org API
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DATADIR="data"
#
# NOTE: This script requires curl and docker
#
# Delete the data dir if it exists and create a new one
rm -fr "${SCRIPTDIR:?}/${DATADIR}"
mkdir "${SCRIPTDIR}/${DATADIR}"
# Delete any existing wiremock container and start a new one
docker rm -f wm > /dev/null || true
echo "Launching Wiremock"
docker run -d --name wm \
-p 8080:8080 \
-v "${SCRIPTDIR}/${DATADIR}:/home/wiremock" \
-u "$(id -u):$(id -g)" \
rodolpheche/wiremock:2.17.0-alpine > /dev/null
printf "Waiting for Wiremock to start "
until curl --output /dev/null --silent --head --fail http://localhost:8080/__admin; do
printf '.'
sleep 0.5
done
printf " done.\n"
# Tell wiremock to start proxying and recording requests
echo "Putting Wiremock in 'record' mode"
curl -s -X POST --data "{ \"targetBaseUrl\": \"http://api.football-data.org\" }" http://localhost:8080/__admin/recordings/start > /dev/null
declare -a stub_urls=(
"/v1/competitions/?season=2016"
"/v1/competitions/398/teams"
"/v1/competitions/398/leagueTable"
"/v1/competitions/449/fixtures?matchday=32"
"/v1/fixtures" #warning, differs from day to day
"/v1/fixtures/149461"
"/v1/teams/66/fixtures" #warning, differs from day to day
"/v1/teams/66"
"/v1/teams/66/players"
)
echo "Doing ${#stub_urls[@]} requests to get stub data:"
for i in "${stub_urls[@]}"; do
printf "\t Fetching [%s]\n" "${i}"
curl -s -X GET -H "X-Response-Control: minified" "http://localhost:8080${i}" > /dev/null
done
# Stop recording
curl -s -X POST http://localhost:8080/__admin/recordings/stop > /dev/null
echo "Done!"
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DATADIR="data"
#
# NOTE: This script requires docker
#
# Check to see if the data dir exists, and bail if it doesn't
if [ ! -d "${SCRIPTDIR}/${DATADIR}" ]; then
echo "Stub data directory not found. (should have been at [${SCRIPTDIR}/${DATADIR}])"
echo "Please get the API stub data first! (ie run get-fd-stub-data.sh)"
exit 1;
fi
# Delete any existing wiremock container and start a new one
docker rm -f wm > /dev/null || true
echo "Launching Wiremock"
docker run -ti --name wm \
-p 8080:8080 \
-v "${SCRIPTDIR}/${DATADIR}:/home/wiremock" \
-u "$(id -u):$(id -g)" \
rodolpheche/wiremock:2.17.0-alpine --verbose
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment