Skip to content

Commit

Permalink
add bin dir to sample
Browse files Browse the repository at this point in the history
  • Loading branch information
qmacro committed Sep 21, 2022
1 parent 0bb54fb commit 4589b5e
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sample/bin/autorebuildfilter
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
#!/usr/bin/env bash

ls filter.md | entr ./bin/buildhtml /_ ./app/filter.html
10 changes: 10 additions & 0 deletions sample/bin/ba-discontinue
Original file line number Diff line number Diff line change
@@ -0,0 1,10 @@
#!/usr/bin/env bash

declare product="${1:-1}"

curl \
--header 'Content-Type: application/json' \
--silent \
--fail \
--request POST \
--url "http://localhost:4004/northwind-model/Products/$product/NorthwindModel.discontinue"
8 changes: 8 additions & 0 deletions sample/bin/bf-addressLine
Original file line number Diff line number Diff line change
@@ -0,0 1,8 @@
#!/usr/bin/env bash

declare supplier="${1:-1}"
curl \
--silent \
--fail \
--request GET \
--url "http://localhost:4004/northwind-model/Suppliers/$supplier/NorthwindModel.addressLine()"
7 changes: 7 additions & 0 deletions sample/bin/buildhtml
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
#!/usr/bin/env bash

pandoc \
-f markdown-smart \
-t html \
--ascii \
"${1:?Specify source file}" > "${2:?Specify target file}"
12 changes: 12 additions & 0 deletions sample/bin/getentityset
Original file line number Diff line number Diff line change
@@ -0,0 1,12 @@
#!/usr/bin/env bash

# Downloads a complete Northwind entityset into a file
# <entityset>.json.

# Combines the northwindentitysets and slurp scripts which
# are assumed to be in the same directory as this script.

declare here="${0%/*}"
declare entityset
entityset="$("$here/northwindentitysets" | fzf)"
"$here/slurp" "$entityset" > "$entityset.json"
19 changes: 19 additions & 0 deletions sample/bin/northwindentitysets
Original file line number Diff line number Diff line change
@@ -0,0 1,19 @@
#!/usr/bin/env bash

# Returns a list of entity sets in the Northwind V4 OData service

set -euo pipefail

declare serviceroot='https://services.odata.org/v4/northwind/northwind.svc/'

main() {

curl \
--silent \
--fail \
--url "${serviceroot}?\$format=json" \
| jq -r '.value[]|select(.kind == "EntitySet").url'

}

main "$@"
4 changes: 4 additions & 0 deletions sample/bin/showedmx
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
#!/usr/bin/env bash

declare servicefile="${1:-$(find srv/ -name '*.cds' | head -1)}"
cds compile --to edmx "$servicefile" | bat --plain
37 changes: 37 additions & 0 deletions sample/bin/slurp
Original file line number Diff line number Diff line change
@@ -0,0 1,37 @@
#!/usr/bin/env bash

# Slurps an entire Northwind entity set (collection) by
# following @odata.nextLink references. Produces JSON output
# in the same shape as the core JSON data in the entityset,
# i.e. { "value": [ <entity object>, <entity object>, ... ] }

# Requires an entity set name to be specified (e.g. Products).

set -euo pipefail

declare serviceroot='https://services.odata.org/v4/northwind/northwind.svc/'
declare entityset="${1:?Specify Northwind entity set name e.g. Products}"
declare pause=0.5

main() {

local tempfile
tempfile="$(mktemp)"
local nextlink="$entityset"
{
while [[ -n $nextlink ]]; do
curl \
--silent \
--location \
--fail \
--url "${serviceroot}${nextlink}" \
> "$tempfile"
jq --raw-output '.value' "$tempfile"
nextlink="$(jq --raw-output '.["@odata.nextLink"]' "$tempfile")"
if [[ -n $nextlink ]]; then sleep "$pause"; fi
done
} | jq --slurp '{value:flatten}'

}

main "$@"
8 changes: 8 additions & 0 deletions sample/bin/ua-submitOrder
Original file line number Diff line number Diff line change
@@ -0,0 1,8 @@
#!/usr/bin/env bash

declare product="${1:-1}"
declare quantity="${2:-1}"
curl \
--header 'Content-Type: application/json' \
--data '{"product":'"$product"',"quantity":'"$quantity"'}' \
--url 'http://localhost:4004/northwind-model/submitOrder'
7 changes: 7 additions & 0 deletions sample/bin/uf-randomProduct
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
#!/usr/bin/env bash

curl \
--silent \
--fail \
--url 'http://localhost:4004/northwind-model/randomProduct()' \
| jq .

0 comments on commit 4589b5e

Please sign in to comment.