Skip to content

Commit d3ddaea

Browse files
added crypto investors tokens endpoint action
1 parent 40eb782 commit d3ddaea

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import tokenMetrics from "../../token_metrics.app.mjs";
2+
import { ENDPOINTS, FILTER_DEFINITIONS } from "../../common/constants.mjs";
3+
import { buildParams, generateFilterSummary } from "../../common/utils.mjs";
4+
5+
const endpoint = ENDPOINTS.CRYPTO_INVESTORS;
6+
7+
export default {
8+
key: "token_metrics-get-crypto-investors",
9+
name: "Get Crypto Investors",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/crypto-investors)`,
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
tokenMetrics,
15+
// Pagination props
16+
limit: {
17+
propDefinition: [
18+
tokenMetrics,
19+
"limit",
20+
],
21+
description: "Limit the number of items in response. Defaults to 50",
22+
default: 50,
23+
},
24+
page: {
25+
propDefinition: [
26+
tokenMetrics,
27+
"page",
28+
],
29+
description: "Enables pagination and data retrieval control by skipping a specified number of items before fetching data. Page should be a non-negative integer, with 1 indicating the beginning of the dataset. Defaults to 1",
30+
default: 1,
31+
},
32+
},
33+
async run({ $ }) {
34+
// Build parameters using utility function
35+
const params = buildParams(this, endpoint.filters);
36+
37+
try {
38+
const response = await this.tokenMetrics.getCryptoInvestors({
39+
$,
40+
params,
41+
});
42+
43+
// Generate summary using utility function
44+
const filterSummary = generateFilterSummary(this, endpoint.filters);
45+
46+
// Use $ context for export
47+
if ($ && $.export) {
48+
const dataLength = response.data?.length || 0;
49+
$.export("$summary", `Successfully retrieved ${dataLength} crypto investors${filterSummary}`);
50+
}
51+
52+
return response;
53+
} catch (error) {
54+
// Enhanced error handling
55+
const errorMessage = error.response?.data?.message || error.message || "An error occurred";
56+
const statusCode = error.response?.status;
57+
58+
if ($ && $.export) {
59+
$.export("$summary", `Error: ${errorMessage}`);
60+
}
61+
62+
// Throw a more descriptive error
63+
throw new Error(`Token Metrics API Error (${statusCode || 'Unknown'}): ${errorMessage}`);
64+
}
65+
},
66+
};

components/token_metrics/common/constants.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ export const ENDPOINTS = {
140140
"symbol",
141141
],
142142
},
143+
CRYPTO_INVESTORS: {
144+
path: "/crypto-investors",
145+
description: "Get the latest list of crypto investors and their scores",
146+
filters: [],
147+
},
143148
};
144149

145150
// Common filter definitions that can be reused across endpoints

components/token_metrics/token_metrics.app.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,15 @@ export default {
201201
params,
202202
});
203203
},
204+
async getCryptoInvestors({
205+
$ = this,
206+
params = {},
207+
}) {
208+
return this.makeApiCall({
209+
$,
210+
endpoint: "/crypto-investors",
211+
params,
212+
});
213+
},
204214
},
205215
};

0 commit comments

Comments
 (0)