Skip to content

Instantly share code, notes, and snippets.

@andrewmh
Created November 29, 2016 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewmh/a9176837ae1ebd6a39d27e1636f58789 to your computer and use it in GitHub Desktop.
Save andrewmh/a9176837ae1ebd6a39d27e1636f58789 to your computer and use it in GitHub Desktop.
#!/bin/bash
CLIENT_ID=$1
CLIENT_SECRET=$2
echo "generating auth token"
RESULT=$(curl "https://uat.dwolla.com/oauth/v2/token" \
-H "Content-Type: application/json" \
-d "{\"client_id\":\"$CLIENT_ID\",\"client_secret\":\"$CLIENT_SECRET\",\"grant_type\":\"client_credentials\"}")
ACCESS_TOKEN_RE="\"access_token\":\"([^\"]*)\""
if [[ $RESULT =~ $ACCESS_TOKEN_RE ]]; then
ACCESS_TOKEN=${BASH_REMATCH[1]}
else
exit 1;
fi
echo "retrieved auth token"
TIMESTAMP=$(date +"%s")
EMAIL="test-$TIMESTAMP@example.com"
curl "https://api-uat.dwolla.com/customers" \
-H "Accept: application/vnd.dwolla.v1.hal+json" \
-H "Content-Type: application/vnd.dwolla.v1.hal+json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d "{\"firstName\":\"Bob\",\"lastName\":\"Somebody\",\"email\":\"$EMAIL\",\"ipAddress\":\"127.0.0.1\"}" \
--dump-header ./result_headers
echo "customer created"
CREATE_HEADERS=$(cat ./result_headers)
LOCATION_RE="Location: (\S*)"
if [[ $CREATE_HEADERS =~ $LOCATION_RE ]]; then
RESOURCE_URL=${BASH_REMATCH[1]};
else
exit 2;
fi
CUSTOMER=$(curl $RESOURCE_URL \
-H "Accept: application/vnd.dwolla.v1.hal+json" \
-H "Authorization: Bearer $ACCESS_TOKEN")
EDIT_RE="\"edit\":\{\"href\":\"([^\"]*)\""
if [[ $CUSTOMER =~ $EDIT_RE ]]; then
EDIT_URL=${BASH_REMATCH[1]}
else
exit 3;
fi
echo "customer resource retrieved"
echo "ERROR MESSAGE:"
curl $EDIT_URL \
-H "Accept: application/vnd.dwolla.v1.hal+json" \
-H "Content-Type: application/vnd.dwolla.v1.hal+json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d "{\"firstName\":\"Bob\",\"lastName\":\"Somebody\",\"email\":\"$EMAIL\",\"ipAddress\":\"127.0.0.1\",\"type\":\"business\",\"address1\":\"123 Fake St\",\"city\":\"Fakesville\",\"state\":\"UT\",\"postalCode\":\"84057\",\"dateOfBirth\":\"1970-1-1\",\"ssn\":\"1234\",\"businessClassification\":\"9ed3cf61-7d6f-11e3-a622-5404a6144203\",\"businessType\":\"corporation\",\"businessName\":\"Corporation Co.\",\"ein\":\"12-1234567\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment