repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
Mirrored from https://github.com/ProjectOpenSea/opensea-skill
stars
latest
clone command
git clone gitlawb://did:key:z6MkqRzA...RfoM/ProjectOpenSea-...git clone gitlawb://did:key:z6MkqRzA.../ProjectOpenSea-...fef93001Release v2.14.011h ago| #1 | #!/usr/bin/env bash |
| #2 | set -euo pipefail |
| #3 | |
| #4 | # shellcheck source=_response-markers.sh disable=SC1091 |
| #5 | source "$(dirname "$0")/_response-markers.sh" |
| #6 | |
| #7 | if [ "$#" -lt 1 ]; then |
| #8 | echo "Usage: opensea-get.sh <path> [query]" >&2 |
| #9 | echo "Example: opensea-get.sh /api/v2/collections/cool-cats-nft" >&2 |
| #10 | exit 1 |
| #11 | fi |
| #12 | |
| #13 | path="$1" |
| #14 | query="${2-}" |
| #15 | |
| #16 | if [[ "$path" != /* ]]; then |
| #17 | echo "opensea-get.sh: path must start with /" >&2 |
| #18 | exit 1 |
| #19 | fi |
| #20 | base="${OPENSEA_BASE_URL:-https://api.opensea.io}" |
| #21 | key="${OPENSEA_API_KEY:-}" |
| #22 | |
| #23 | if [ -z "$key" ]; then |
| #24 | echo "OPENSEA_API_KEY is required" >&2 |
| #25 | exit 1 |
| #26 | fi |
| #27 | |
| #28 | url="$base$path" |
| #29 | if [ -n "$query" ]; then |
| #30 | url="$url?$query" |
| #31 | fi |
| #32 | |
| #33 | tmp_body=$(mktemp) |
| #34 | trap 'rm -f "$tmp_body"' EXIT |
| #35 | |
| #36 | max_attempts=3 |
| #37 | base_delay=2 |
| #38 | |
| #39 | for (( attempt=1; attempt<=max_attempts; attempt++ )); do |
| #40 | http_code=$(curl -sS --connect-timeout 10 --max-time 30 \ |
| #41 | -H "x-api-key: $key" \ |
| #42 | -H "User-Agent: opensea-skill/1.0" \ |
| #43 | -w '%{http_code}' \ |
| #44 | -o "$tmp_body" \ |
| #45 | "$url") || { |
| #46 | echo "opensea-get.sh: curl transport error (exit $?)" >&2 |
| #47 | exit 1 |
| #48 | } |
| #49 | |
| #50 | if [[ "$http_code" =~ ^2 ]]; then |
| #51 | emit_response "$tmp_body" |
| #52 | exit 0 |
| #53 | fi |
| #54 | |
| #55 | if [ "$http_code" = "429" ] && [ "$attempt" -lt "$max_attempts" ]; then |
| #56 | delay=$(( base_delay * (1 << (attempt - 1)) )) |
| #57 | echo "opensea-get.sh: 429 rate limited, retrying in ${delay}s (attempt $attempt/$max_attempts)" >&2 |
| #58 | sleep "$delay" |
| #59 | continue |
| #60 | fi |
| #61 | |
| #62 | echo "opensea-get.sh: HTTP $http_code error" >&2 |
| #63 | emit_response "$tmp_body" >&2 |
| #64 | exit 1 |
| #65 | done |
| #66 |