-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from blockfrost/feat/nutlink
feat: add nutlink endpoints
- Loading branch information
Showing
10 changed files
with
433 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,180 @@ | ||
import axios from 'axios'; | ||
import { getHeaders, handleError } from '../../utils'; | ||
import { components } from '../../types/OpenApi'; | ||
import { BlockFrostAPI } from '../../index'; | ||
import { | ||
DEFAULT_PAGINATION_PAGE_COUNT, | ||
DEFAULT_PAGINATION_PAGE_ITEMS_COUNT, | ||
DEFAULT_ORDER, | ||
} from '../../config'; | ||
|
||
export async function nutlink( | ||
this: BlockFrostAPI, | ||
address: string, | ||
): Promise<components['schemas']['nutlink_address']> { | ||
return new Promise((resolve, reject) => { | ||
axios | ||
.get(`${this.apiUrl}/nutlink/${address}`, { | ||
headers: getHeaders(this), | ||
}) | ||
.then(resp => { | ||
resolve(resp.data); | ||
}) | ||
.catch(err => reject(handleError(err))); | ||
}); | ||
} | ||
|
||
export async function nutlinkAddressTickers( | ||
this: BlockFrostAPI, | ||
address: string, | ||
page = DEFAULT_PAGINATION_PAGE_COUNT, | ||
count = DEFAULT_PAGINATION_PAGE_ITEMS_COUNT, | ||
order = DEFAULT_ORDER, | ||
): Promise<components['schemas']['nutlink_address_tickers']> { | ||
return new Promise((resolve, reject) => { | ||
axios | ||
.get(`${this.apiUrl}/nutlink/${address}/tickers`, { | ||
headers: getHeaders(this), | ||
params: { page, count, order }, | ||
}) | ||
.then(resp => { | ||
resolve(resp.data); | ||
}) | ||
.catch(err => reject(handleError(err))); | ||
}); | ||
} | ||
|
||
export async function nutlinkAddressTickersAll( | ||
this: BlockFrostAPI, | ||
address: string, | ||
order = DEFAULT_ORDER, | ||
batchSize = 10, | ||
): Promise<components['schemas']['nutlink_address_tickers']> { | ||
let page = 1; | ||
const count = DEFAULT_PAGINATION_PAGE_ITEMS_COUNT; | ||
const res: components['schemas']['nutlink_address_tickers'] = []; | ||
|
||
const getPromiseBundle = () => { | ||
const promises = [...Array(batchSize).keys()].map(i => | ||
this.nutlinkAddressTickers(address, page + i, count, order), | ||
); | ||
page += batchSize; | ||
return promises; | ||
}; | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const promiseBundle = getPromiseBundle(); | ||
const pages = await Promise.all(promiseBundle); | ||
for (const page of pages) { | ||
res.push(...page); | ||
if (page.length < DEFAULT_PAGINATION_PAGE_ITEMS_COUNT) { | ||
return res; | ||
} | ||
} | ||
} | ||
} | ||
|
||
export async function nutlinkAddressTicker( | ||
this: BlockFrostAPI, | ||
address: string, | ||
ticker: string, | ||
page = DEFAULT_PAGINATION_PAGE_COUNT, | ||
count = DEFAULT_PAGINATION_PAGE_ITEMS_COUNT, | ||
order = DEFAULT_ORDER, | ||
): Promise<components['schemas']['nutlink_address_ticker']> { | ||
return new Promise((resolve, reject) => { | ||
axios | ||
.get(`${this.apiUrl}/nutlink/${address}/tickers/${ticker}`, { | ||
headers: getHeaders(this), | ||
params: { page, count, order }, | ||
}) | ||
.then(resp => { | ||
resolve(resp.data); | ||
}) | ||
.catch(err => reject(handleError(err))); | ||
}); | ||
} | ||
|
||
export async function nutlinkAddressTickerAll( | ||
this: BlockFrostAPI, | ||
address: string, | ||
ticker: string, | ||
order = DEFAULT_ORDER, | ||
batchSize = 10, | ||
): Promise<components['schemas']['nutlink_address_ticker']> { | ||
let page = 1; | ||
const count = DEFAULT_PAGINATION_PAGE_ITEMS_COUNT; | ||
const res: components['schemas']['nutlink_address_ticker'] = []; | ||
|
||
const getPromiseBundle = () => { | ||
const promises = [...Array(batchSize).keys()].map(i => | ||
this.nutlinkAddressTicker(address, ticker, page + i, count, order), | ||
); | ||
page += batchSize; | ||
return promises; | ||
}; | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const promiseBundle = getPromiseBundle(); | ||
const pages = await Promise.all(promiseBundle); | ||
for (const page of pages) { | ||
res.push(...page); | ||
if (page.length < DEFAULT_PAGINATION_PAGE_ITEMS_COUNT) { | ||
return res; | ||
} | ||
} | ||
} | ||
} | ||
|
||
export async function nutlinkTickers( | ||
this: BlockFrostAPI, | ||
ticker: string, | ||
page = DEFAULT_PAGINATION_PAGE_COUNT, | ||
count = DEFAULT_PAGINATION_PAGE_ITEMS_COUNT, | ||
order = DEFAULT_ORDER, | ||
): Promise<components['schemas']['nutlink_tickers_ticker']> { | ||
return new Promise((resolve, reject) => { | ||
axios | ||
.get(`${this.apiUrl}/nutlink/tickers/${ticker}`, { | ||
headers: getHeaders(this), | ||
params: { page, count, order }, | ||
}) | ||
.then(resp => { | ||
resolve(resp.data); | ||
}) | ||
.catch(err => reject(handleError(err))); | ||
}); | ||
} | ||
|
||
export async function nutlinkTickersAll( | ||
this: BlockFrostAPI, | ||
ticker: string, | ||
order = DEFAULT_ORDER, | ||
batchSize = 10, | ||
): Promise<components['schemas']['nutlink_tickers_ticker']> { | ||
let page = 1; | ||
const count = DEFAULT_PAGINATION_PAGE_ITEMS_COUNT; | ||
const res: components['schemas']['nutlink_tickers_ticker'] = []; | ||
|
||
const getPromiseBundle = () => { | ||
const promises = [...Array(batchSize).keys()].map(i => | ||
this.nutlinkTickers(ticker, page + i, count, order), | ||
); | ||
page += batchSize; | ||
return promises; | ||
}; | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const promiseBundle = getPromiseBundle(); | ||
const pages = await Promise.all(promiseBundle); | ||
for (const page of pages) { | ||
res.push(...page); | ||
if (page.length < DEFAULT_PAGINATION_PAGE_ITEMS_COUNT) { | ||
return res; | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.