-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_counter_api_ninja
More file actions
46 lines (37 loc) · 1.09 KB
/
run_counter_api_ninja
File metadata and controls
46 lines (37 loc) · 1.09 KB
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
#!/usr/bin/env bash
# refactor this script
COUNTER_KEY=$1
API_KEY=$2
function md5_to_short_hash() {
md5_hash="$1"
# Take the first 20 characters out of the input parameter bc ninjas's limitation
truncated_hash=${md5_hash:0:20}
echo "$truncated_hash"
}
getPluginVersionInCountApiByNinjas() {
API_URL="https://api.api-ninjas.com/v1/counter"
HEADER_KEY_X_API_KEY="X-Api-Key"
namespace="$1"
API_KEY="$2"
response=$(curl -s -X GET "$API_URL" \
-H "$HEADER_KEY_X_API_KEY: $API_KEY" \
-G \
--data-urlencode "id=$namespace" \
--data-urlencode "hit=true")
value=$(echo "$response" | jq '.value')
if [[ "${value}" == "1" ]]; then
response=$(curl -s -X GET "$API_URL" \
-H "$HEADER_KEY_X_API_KEY: $API_KEY" \
-G \
--data-urlencode "id=$namespace" \
--data-urlencode "value=1")
value=$(echo "$response" | jq '.value')
fi
echo "$value"
}
ninjia_COUNTER_KEY=$(md5_to_short_hash "$COUNTER_KEY")
if [[ -n "${3}" ]]; then
echo "${ninjia_COUNTER_KEY}"
fi
count=$(getPluginVersionInCountApiByNinjas "$ninjia_COUNTER_KEY" "${API_KEY}")
echo "$count"