-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.sh
executable file
·50 lines (41 loc) · 1.33 KB
/
request.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# Send a generic request to Twilio API using cUrl
#
# Parameters:
# $1 - string, name of the HTTP method: 'GET', 'POST', 'DELETE',...
# $2 - string, name of the API end-point
# ... - API parameters in the form name='value',
# where the value is URL-encoded and quoted if needed for safety
#
# Reference:
# [1] Twilio REST API
# https://www.twilio.com/docs/api/rest
#
cd "$(dirname "$0")"
. ./lib/die.sh
httpMethod="$1"
twilioApiName="$2"
test -n "$httpMethod" -a -n "$twilioApiName" \
|| die "Usage: $0 httpMethod twilioApiName [param='value']..."
. ./config.sh
test -n "$twilioApiBaseUrl" \
|| die 'twilioApiBaseUrl is missing from config'
test -n "$twilioApiResponseFormat" \
|| die 'twilioApiResponseFormat is missing from config'
test -n "$twilioAccountSid" -a -n "$twilioAuthToken" \
|| die \
'twilioAccountSid and twilioAuthToken must be set in your configuration file'
twilioRequestUrl="$twilioApiBaseUrl/Accounts/$twilioAccountSid/$twilioApiName"
if test "$twilioApiResponseFormat" != 'xml'
then
twilioRequestUrl="$twilioRequestUrl.$twilioApiResponseFormat"
fi
{
echo "$twilioRequestUrl"
echo "-u '$twilioAccountSid:$twilioAuthToken'"
shift 2
for twilioParameterAndValue
do
echo "--data-urlencode \"$twilioParameterAndValue\""
done
} | xargs curl --silent --show-error --request "$httpMethod"