FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

adds support for cli cmds of new metadata list endpoints by adarrohn · Pull Request #4 · glassnode/glassnode-cli · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (13) .md  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
47 changes: 47 additions & 0 deletions README.md
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
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,53 @@ Show details about an asset.
gn asset describe BTC
```

### `gn asset tags`

List all asset semantic tags, optionally over a CEL-filtered subset of assets.

```bash
gn asset tags
gn asset tags --filter "asset.categories.exists(c,c=='spot')"
```

| Flag | Short | Description |
|------|-------|-------------|
| `--filter` | | CEL filter expression |

### `gn asset categories`

List all asset categories, optionally over a CEL-filtered subset of assets.

```bash
gn asset categories
gn asset categories --filter "asset.semantic_tags.exists(tag,tag=='erc20')"
```

| Flag | Short | Description |
|------|-------|-------------|
| `--filter` | | CEL filter expression |

### `gn asset blockchains`

List all blockchains on which at least one asset is supported, optionally over a CEL-filtered subset of assets.

```bash
gn asset blockchains
gn asset blockchains --filter "asset.id=='USDT'"
```

| Flag | Short | Description |
|------|-------|-------------|
| `--filter` | | CEL filter expression |

### `gn metric tags`

List all tags used across metric metadata.

```bash
gn metric tags
```

### `gn metric list`

List all available metrics, optionally filtered by [metadata query parameters](https://docs.glassnode.com/basic-api/metadata#query-parameters-1).
Expand Down
3 changes: 3 additions & 0 deletions cmd/asset.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ var assetCmd = &cobra.Command{
func init() {
assetCmd.AddCommand(assetListCmd)
assetCmd.AddCommand(assetDescribeCmd)
assetCmd.AddCommand(assetTagsCmd)
assetCmd.AddCommand(assetCategoriesCmd)
assetCmd.AddCommand(assetBlockchainsCmd)
}
17 changes: 17 additions & 0 deletions cmd/asset_blockchains.go
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/spf13/cobra"
)

var assetBlockchainsCmd = &cobra.Command{
Use: "blockchains",
Short: "List all blockchains on which at least one asset is supported",
RunE: func(cmd *cobra.Command, args []string) error {
return runNamesListCommand(cmd, "/v1/metadata/assets/blockchains", true)
},
}

func init() {
assetBlockchainsCmd.Flags().String("filter", "", "CEL filter expression")
}
72 changes: 72 additions & 0 deletions cmd/asset_blockchains_test.go
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cmd

import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
)

func TestAssetBlockchains_DryRun_IncludesEndpointAndFilter(t *testing.T) {
stdout, stderr, err := runCLINames(t, "https://api.example.com", "asset", "blockchains", "--filter", `asset.id==USDT`, "--dry-run")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}
if !strings.Contains(stdout, "/v1/metadata/assets/blockchains") {
t.Errorf("URL should contain the endpoint path: %s", stdout)
}
if !strings.Contains(stdout, "filter=") {
t.Errorf("URL should contain the filter param: %s", stdout)
}
}

func TestAssetBlockchains_ListsNames(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/metadata/assets/blockchains" {
t.Errorf("unexpected path: %s", r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":[{"name":"BTC"},{"name":"ETH"}]}`))
}))
defer server.Close()

stdout, stderr, err := runCLINames(t, server.URL, "asset", "blockchains", "-o", "json")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}

var got []string
if err := json.Unmarshal([]byte(stdout), &got); err != nil {
t.Fatalf("stdout is not JSON: %v\nstdout: %s", err, stdout)
}
if len(got) != 2 || got[0] != "BTC" || got[1] != "ETH" {
t.Errorf("got %v", got)
}
}

func TestAssetBlockchains_PassesNormalizedFilter(t *testing.T) {
var gotFilter string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotFilter = r.URL.Query().Get("filter")
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":[{"name":"ETH"}]}`))
}))
defer server.Close()

stdout, stderr, err := runCLINames(t, server.URL, "asset", "blockchains", "--filter", `asset.id==USDT`, "-o", "json")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}
if gotFilter != `asset.id=="USDT"` {
t.Errorf("filter = %q, want normalized CEL string literal", gotFilter)
}

var got []string
if err := json.Unmarshal([]byte(stdout), &got); err != nil {
t.Fatalf("stdout is not JSON: %v\nstdout: %s", err, stdout)
}
if len(got) != 1 || got[0] != "ETH" {
t.Errorf("got %v", got)
}
}
17 changes: 17 additions & 0 deletions cmd/asset_categories.go
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/spf13/cobra"
)

var assetCategoriesCmd = &cobra.Command{
Use: "categories",
Short: "List all asset categories",
RunE: func(cmd *cobra.Command, args []string) error {
return runNamesListCommand(cmd, "/v1/metadata/assets/categories", true)
},
}

func init() {
assetCategoriesCmd.Flags().String("filter", "", "CEL filter expression")
}
72 changes: 72 additions & 0 deletions cmd/asset_categories_test.go
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cmd

import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
)

func TestAssetCategories_DryRun_IncludesEndpointAndFilter(t *testing.T) {
stdout, stderr, err := runCLINames(t, "https://api.example.com", "asset", "categories", "--filter", `asset.id==BTC`, "--dry-run")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}
if !strings.Contains(stdout, "/v1/metadata/assets/categories") {
t.Errorf("URL should contain the endpoint path: %s", stdout)
}
if !strings.Contains(stdout, "filter=") {
t.Errorf("URL should contain the filter param: %s", stdout)
}
}

func TestAssetCategories_ListsNames(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/metadata/assets/categories" {
t.Errorf("unexpected path: %s", r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":[{"name":"futures"},{"name":"spot"}]}`))
}))
defer server.Close()

stdout, stderr, err := runCLINames(t, server.URL, "asset", "categories", "-o", "json")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}

var got []string
if err := json.Unmarshal([]byte(stdout), &got); err != nil {
t.Fatalf("stdout is not JSON: %v\nstdout: %s", err, stdout)
}
if len(got) != 2 || got[0] != "futures" || got[1] != "spot" {
t.Errorf("got %v", got)
}
}

func TestAssetCategories_PassesNormalizedFilter(t *testing.T) {
var gotFilter string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotFilter = r.URL.Query().Get("filter")
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":[{"name":"stablecoin"}]}`))
}))
defer server.Close()

stdout, stderr, err := runCLINames(t, server.URL, "asset", "categories", "--filter", `asset.id==BTC`, "-o", "json")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}
if gotFilter != `asset.id=="BTC"` {
t.Errorf("filter = %q, want normalized CEL string literal", gotFilter)
}

var got []string
if err := json.Unmarshal([]byte(stdout), &got); err != nil {
t.Fatalf("stdout is not JSON: %v\nstdout: %s", err, stdout)
}
if len(got) != 1 || got[0] != "stablecoin" {
t.Errorf("got %v", got)
}
}
17 changes: 17 additions & 0 deletions cmd/asset_tags.go
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/spf13/cobra"
)

var assetTagsCmd = &cobra.Command{
Use: "tags",
Short: "List all asset semantic tags",
RunE: func(cmd *cobra.Command, args []string) error {
return runNamesListCommand(cmd, "/v1/metadata/assets/tags", true)
},
}

func init() {
assetTagsCmd.Flags().String("filter", "", "CEL filter expression")
}
72 changes: 72 additions & 0 deletions cmd/asset_tags_test.go
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cmd

import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
)

func TestAssetTags_DryRun_IncludesEndpointAndFilter(t *testing.T) {
stdout, stderr, err := runCLINames(t, "https://api.example.com", "asset", "tags", "--filter", `asset.id==BTC`, "--dry-run")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}
if !strings.Contains(stdout, "/v1/metadata/assets/tags") {
t.Errorf("URL should contain the endpoint path: %s", stdout)
}
if !strings.Contains(stdout, "filter=") {
t.Errorf("URL should contain the filter param: %s", stdout)
}
}

func TestAssetTags_ListsNames(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/metadata/assets/tags" {
t.Errorf("unexpected path: %s", r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":[{"name":"erc20"},{"name":"stablecoin"}]}`))
}))
defer server.Close()

stdout, stderr, err := runCLINames(t, server.URL, "asset", "tags", "-o", "json")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}

var got []string
if err := json.Unmarshal([]byte(stdout), &got); err != nil {
t.Fatalf("stdout is not JSON: %v\nstdout: %s", err, stdout)
}
if len(got) != 2 || got[0] != "erc20" || got[1] != "stablecoin" {
t.Errorf("got %v", got)
}
}

func TestAssetTags_PassesNormalizedFilter(t *testing.T) {
var gotFilter string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotFilter = r.URL.Query().Get("filter")
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":[{"name":"stablecoin"}]}`))
}))
defer server.Close()

stdout, stderr, err := runCLINames(t, server.URL, "asset", "tags", "--filter", `asset.id==BTC`, "-o", "json")
if err != nil {
t.Fatalf("run CLI: %v\nstderr: %s", err, stderr)
}
if gotFilter != `asset.id=="BTC"` {
t.Errorf("filter = %q, want normalized CEL string literal", gotFilter)
}

var got []string
if err := json.Unmarshal([]byte(stdout), &got); err != nil {
t.Fatalf("stdout is not JSON: %v\nstdout: %s", err, stdout)
}
if len(got) != 1 || got[0] != "stablecoin" {
t.Errorf("got %v", got)
}
}
1 change: 1 addition & 0 deletions cmd/metric.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ func init() {
metricCmd.AddCommand(metricListCmd)
metricCmd.AddCommand(metricDescribeCmd)
metricCmd.AddCommand(metricGetCmd)
metricCmd.AddCommand(metricTagsCmd)
}
13 changes: 13 additions & 0 deletions cmd/metric_tags.go
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cmd

import (
"github.com/spf13/cobra"
)

var metricTagsCmd = &cobra.Command{
Use: "tags",
Short: "List all tags used across metric metadata",
RunE: func(cmd *cobra.Command, args []string) error {
return runNamesListCommand(cmd, "/v1/metadata/tags", false)
},
}
Loading
Loading

Back | FazBrowse Home | New Git URL