-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Custom API class and field to DuneClient. There is a skipped test that does run when not ignored (but its specific to user name). Sample usages was added to the README: --------- Co-authored-by: Philipp Wassibauer <[email protected]>
- Loading branch information
1 parent
70c2986
commit 9c6fda9
Showing
8 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,31 @@ | ||
import { Router } from "./router"; | ||
import { CustomAPIParams, ResultsResponse } from "../types"; | ||
|
||
/** | ||
* Custom API Interface: | ||
* Create custom API endpoints from existing Dune queries. | ||
* https://docs.dune.com/api-reference/custom/overview | ||
*/ | ||
export class CustomAPI extends Router { | ||
/** | ||
* Custom Endpoints allow developers to create and manage API | ||
* endpoints from Dune queries. | ||
* By selecting a query and scheduling it to run at a specified | ||
* frequency, developers can call a custom URL to consume data. | ||
* This flexible alternative to Preset Endpoints provides greater | ||
* customization without the complexities of SQL Endpoints. | ||
* | ||
* @param {CustomAPIParams} args - Parameters for the custom API request. | ||
* @see {@link CustomAPIParams} | ||
* @returns {Promise<ResultsResponse>} - The result of the API call. | ||
* @see {@link ResultsResponse} | ||
*/ | ||
async getResults(args: CustomAPIParams): Promise<ResultsResponse> { | ||
const x = await this._get<ResultsResponse>( | ||
`endpoints/${args.handle}/${args.slug}/results`, | ||
args, | ||
); | ||
|
||
return x; | ||
} | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { DuneClient, QueryAPI, ExecutionAPI } from "./api"; | ||
export { DuneClient, QueryAPI, ExecutionAPI, CustomAPI, TableAPI } from "./api"; | ||
export * from "./types"; | ||
export { Paginator } from "./paginator"; |
This file contains 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
This file contains 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,26 @@ | ||
import { CustomAPI } from "../../src/"; | ||
import log from "loglevel"; | ||
import { BASIC_KEY } from "./util"; | ||
import { expect } from "chai"; | ||
|
||
log.setLevel("silent", true); | ||
|
||
describe("Custom API", () => { | ||
let client: CustomAPI; | ||
const slug = "test-custom-api"; | ||
|
||
before(() => { | ||
client = new CustomAPI(BASIC_KEY); | ||
}); | ||
|
||
// Skip: This endpoint is very "user specific" | ||
it.skip("retrieves data from custom endpoint", async () => { | ||
// Note: for DuneClient class this would be `client.custom.getResults` | ||
const results = await client.getResults({ | ||
handle: "bh2smith", | ||
slug, | ||
limit: 1, | ||
}); | ||
expect(results.result!.rows.length).to.equal(1); | ||
}); | ||
}); |
This file contains 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