-
-
Save thbkrkr/c080eb2342db18fab91f20ca593f303e to your computer and use it in GitHub Desktop.
Simple Swift HTTP API wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -eu | |
| # | |
| # Simple Swift HTTP API wrapper | |
| # | |
| AUTH_TOKEN=?? | |
| CONTAINER_URL=https://?? | |
| CONTAINER_NAME=?? | |
| help() { | |
| echo 'Usage: o42 COMMAND | |
| Commands: | |
| ls List all files | |
| put Upload a file | |
| get Get a file | |
| rm Delete a file | |
| ' | |
| } | |
| _api() { | |
| declare uri=${1:-""} && shift | |
| curl \ | |
| -H "X-Auth-Token: $AUTH_TOKEN" \ | |
| $CONTAINER_URL/$CONTAINER_NAME$uri $@ \ | |
| -w "\n{\"status\":%{response_code},\"time\":\"%{time_total}s\"}\n"; | |
| } | |
| main() { | |
| declare cmd=${1:-help} && shift | |
| case $cmd in | |
| ls) _api "/" -XGET ;; | |
| put) _api "/" -XPUT -T $1 ;; | |
| get) _api "/$1" ;; | |
| rm) _api "/$1" -XDELETE ;; | |
| *) help ;; | |
| esac | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment