|
12345678910111213141516171819202122232425262728 |
- #!/bin/bash
- #
- # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
- #
- if [[ -z "${BUBBLE_MAILGUN_API_KEY}" ]] ; then
- echo "BUBBLE_MAILGUN_API_KEY not defined in environment"
- exit 1
- fi
-
- API_BASE=https://api.mailgun.net/v3/
-
- URI="${1:?no uri}"
- POST_FILE="${2}"
- HTTP_METHOD=${3}
-
- function auth () {
- echo -n "Authorization: Basic $(echo -n "api:${BUBBLE_MAILGUN_API_KEY}" | base64)"
- }
-
- if [[ -n "${POST_FILE}" ]] ; then
- if [[ -z "${HTTP_METHOD}" ]] ; then
- curl -d @${POST_FILE} -s -H 'Content-Type: multipart/form-data' -H "$(auth)" ${API_BASE}${URI}
- else
- curl -d @${POST_FILE} -X ${HTTP_METHOD} -s -H 'Content-Type: multipart/form-data' -H "$(auth)" ${API_BASE}${URI}
- fi
- else
- curl -s -H "$(auth)" ${API_BASE}${URI}
- fi
|