Skip to content

Commit 16d20af

Browse files
author
Rohan Likhite
authored
Merge pull request #66 from imRohan/develop
Live Dashboards and Client Libraries
2 parents 25cf38f + 78b1a7d commit 16d20af

File tree

15 files changed

+881
-187
lines changed

15 files changed

+881
-187
lines changed

client-libraries/Bash/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Bash-script to access [Pantry](https://getpantry.cloud/) [API](https://documenter.getpostman.com/view/3281832/SzmZeMLC)
2+
3+
Source the library first
4+
5+
```bash
6+
. ./pantry-client.bash "Your_Pantry_ID_here"
7+
```
8+
9+
Or, better yet, put the above command inside the file `~/.bashrc`. This would make Bash source the library automatically on startup.
10+
11+
### Usage:
12+
13+
- Create/replace basket
14+
15+
```bash
16+
pantry_create <name of basket>
17+
```
18+
19+
- Add contents to / update contents of basket
20+
21+
```bash
22+
echo '{"newKey":"newVal","oldKey":"newerVal"}' | pantry_update <name of basket>
23+
```
24+
25+
- Retrieve all contents of basket
26+
27+
```bash
28+
pantry_retrieve <name of basket>
29+
```
30+
31+
- Delete basket
32+
33+
```bash
34+
pantry_delete <name of basket>
35+
```
36+
37+
38+
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Library of bash-functions to access https://getpantry.cloud/ API
2+
#
3+
# To avail the functions listed herein, source this script as
4+
#
5+
# source ./pantry-client.bash "Your_Pantry_ID_here"
6+
#
7+
# Tip: Put the above command inside ~/.bashrc to avoid sourcing manually everytime
8+
#
9+
# Author: Somajit Dey <dey.somajit@gmail.com> 2021
10+
11+
export PANTRY_ID="${1:-"${PANTRY_ID}"}"
12+
13+
[[ -z "${PANTRY_ID}" ]] && \
14+
echo 'Warning: PANTRY_ID not set
15+
Execute command: export PANTRY_ID="Your_Pantry_ID_here"'
16+
17+
pantry_curl(){
18+
# Common cURL parameters to avoid code duplication
19+
# Usage: pantry_curl POST|GET|PUT|DEL <basket name>
20+
#
21+
# Note: PANTRY_BASE_URL is available globally for later use, if any, after a single
22+
# invocation of this function
23+
24+
[[ -n "${PANTRY_ID}" ]] || \
25+
{ echo "Please set the environment variable PANTRY_ID with your Pantry ID" && return 1;}
26+
27+
declare -xg PANTRY_BASE_URL="https://getpantry.cloud/apiv1/pantry/${PANTRY_ID}"
28+
29+
local method="${1}"
30+
local basket="${2}"
31+
shift;shift
32+
local endpoint_url="${PANTRY_BASE_URL}/basket/${basket}"
33+
curl -fsSL -H 'Content-Type: application/json' -X "${method}" "${endpoint_url}" $@
34+
35+
}; export -f pantry_curl
36+
37+
pantry_create(){
38+
# Create/Replace basket passed as parameter
39+
40+
local basket="${1}"
41+
pantry_curl POST "${basket}"
42+
43+
}; export -f pantry_create
44+
45+
pantry_update(){
46+
# Update basket passed as parameter. Read payload json from stdin.
47+
48+
local basket="${1}"
49+
pantry_curl PUT "${basket}" -d @-
50+
51+
}; export -f pantry_update
52+
53+
pantry_retrieve(){
54+
# Return full contents of basket passed as parameter.
55+
56+
local basket="${1}"
57+
pantry_curl GET "${basket}"
58+
59+
}; export -f pantry_retrieve
60+
61+
pantry_delete(){
62+
# Delete basket passed as parameter.
63+
64+
local basket="${1}"
65+
pantry_curl DELETE "${basket}"
66+
67+
}; export -f pantry_delete

0 commit comments

Comments
 (0)