Skip to content

Commit 7668376

Browse files
added technology grades tokens endpoint action
1 parent 43fa7ca commit 7668376

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.TECHNOLOGY_GRADES;
6+
7+
export default {
8+
key: "token_metrics-get-technology-grades",
9+
name: "Get Technology Grades",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/technology-grade)`,
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
tokenMetrics,
15+
// Filter props based on endpoint configuration and API documentation
16+
tokenId: {
17+
...FILTER_DEFINITIONS.token_id,
18+
description: "Click here to access the list of token IDs. Example: 3375",
19+
},
20+
tokenName: {
21+
...FILTER_DEFINITIONS.token_name,
22+
description: "Crypto Asset Names (e.g., Bitcoin, Ethereum). Click here to access the list of token names.",
23+
},
24+
symbol: {
25+
...FILTER_DEFINITIONS.symbol,
26+
description: "Click here to access the list of token symbols. Example: BTC,ETH",
27+
},
28+
// Pagination props
29+
limit: {
30+
propDefinition: [
31+
tokenMetrics,
32+
"limit",
33+
],
34+
description: "Limit the number of items in response. Defaults to 50",
35+
default: 50,
36+
},
37+
page: {
38+
propDefinition: [
39+
tokenMetrics,
40+
"page",
41+
],
42+
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",
43+
default: 1,
44+
},
45+
},
46+
async run({ $ }) {
47+
// Build parameters using utility function
48+
const params = buildParams(this, endpoint.filters);
49+
50+
try {
51+
const response = await this.tokenMetrics.getTechnologyGrades({
52+
$,
53+
params,
54+
});
55+
56+
// Generate summary using utility function
57+
const filterSummary = generateFilterSummary(this, endpoint.filters);
58+
59+
// Use $ context for export
60+
if ($ && $.export) {
61+
const dataLength = response.data?.length || 0;
62+
$.export("$summary", `Successfully retrieved technology grades for ${dataLength} tokens${filterSummary}`);
63+
}
64+
65+
return response;
66+
} catch (error) {
67+
// Enhanced error handling
68+
const errorMessage = error.response?.data?.message || error.message || "An error occurred";
69+
const statusCode = error.response?.status;
70+
71+
if ($ && $.export) {
72+
$.export("$summary", `Error: ${errorMessage}`);
73+
}
74+
75+
// Throw a more descriptive error
76+
throw new Error(`Token Metrics API Error (${statusCode || 'Unknown'}): ${errorMessage}`);
77+
}
78+
},
79+
};

components/token_metrics/common/constants.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ export const ENDPOINTS = {
104104
"end_date",
105105
],
106106
},
107+
TECHNOLOGY_GRADES: {
108+
path: "/technology-grade",
109+
description: "Get Technology Grade insights for a token, including activity score, security score, repository score, collaboration score, and DeFi scanner score",
110+
filters: [
111+
"token_id",
112+
"token_name",
113+
"symbol",
114+
],
115+
},
107116
};
108117

109118
// 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
@@ -161,5 +161,15 @@ export default {
161161
params,
162162
});
163163
},
164+
async getTechnologyGrades({
165+
$ = this,
166+
params = {},
167+
}) {
168+
return this.makeApiCall({
169+
$,
170+
endpoint: "/technology-grade",
171+
params,
172+
});
173+
},
164174
},
165175
};

0 commit comments

Comments
 (0)