1#!/usr/bin/env bash
2
3function atfile.http.download() {
4 uri="$1"
5 out_path="$2"
6
7 atfile.say.debug "$uri\nā³ $out_path" "GET: "
8
9 curl -s -X GET "$uri" \
10 -H "User-Agent: $(atfile.util.get_uas)" \
11 -o "$out_path"
12}
13
14function atfile.http.get() {
15 uri="$1"
16 auth="$2"
17 type="$3"
18
19 [[ -n $auth ]] && auth="Authorization: $auth"
20 [[ -z $type ]] && type="application/json"
21
22 atfile.say.debug "$uri" "GET: "
23
24 curl -s -X GET "$uri" \
25 -H "$auth" \
26 -H "Content-Type: $type" \
27 -H "User-Agent: $(atfile.util.get_uas)"
28}
29
30function atfile.http.post() {
31 uri="$1"
32 data="$2"
33 auth="$3"
34 type="$4"
35
36 [[ -n $auth ]] && auth="Authorization: $auth"
37 [[ -z $type ]] && type="application/json"
38
39 atfile.say.debug "$uri\nā³ $data" "POST: "
40
41 curl -s -X POST "$uri" \
42 -H "$auth" \
43 -H "Content-Type: $type" \
44 -H "User-Agent: $(atfile.util.get_uas)" \
45 -d "$data"
46}
47
48function atfile.http.upload() {
49 uri="$1"
50 file="$2"
51 auth="$3"
52 type="$4"
53
54 [[ -n $auth ]] && auth="Authorization: $auth"
55 [[ -z $type ]] && type="*/*"
56
57 atfile.say.debug "$uri\nā³ $file" "POST: "
58
59 # shellcheck disable=SC2154
60 curl -s -X POST "$_server/xrpc/$lexi" \
61 -H "$auth" \
62 -H "Content-Type: $type" \
63 -H "User-Agent: $(atfile.util.get_uas)" \
64 --data-binary @"$file" | jq
65}