Skip to content

Commit

Permalink
Merge pull request #67 from blockfrost/feat/nutlink
Browse files Browse the repository at this point in the history
feat: add nutlink endpoints
  • Loading branch information
vladimirvolek authored Jul 5, 2021
2 parents eb12c0e + 900b7ee commit d6c2212
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 11 deletions.
10 changes: 5 additions & 5 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file modified .yarn/install-state.gz
Binary file not shown.
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- nutlink endpoints

## [0.7.1] - 2021-06-30

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test": "jest -c jest.config.js"
},
"dependencies": {
"@blockfrost/openapi": "^0.1.21",
"@blockfrost/openapi": "^0.1.22",
"@yarnpkg/pnpify": "3.0.0-rc.6",
"axios": "^0.21.1",
"axios-retry": "^3.1.9",
Expand Down
180 changes: 180 additions & 0 deletions src/endpoints/nutlink/index.ts
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;
}
}
}
}
56 changes: 56 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ import {
txsMetadata,
txSubmit,
} from './endpoints/txs';
import {
nutlinkAddressTicker,
nutlinkAddressTickers,
nutlinkAddressTickersAll,
nutlinkAddressTickerAll,
nutlinkTickers,
nutlinkTickersAll,
} from './endpoints/nutlink';

import { Options, ValidatedOptions } from './types';
import join from 'url-join';
Expand Down Expand Up @@ -541,6 +549,54 @@ class BlockFrostAPI {
*/
metricsEndpoints = metricsEndpoints;

/**
* nutlinkAddressTicker
*
* @returns xxx
*
*/
nutlinkAddressTicker = nutlinkAddressTicker;

/**
* nutlinkAddressTickers
*
* @returns xxx
*
*/
nutlinkAddressTickers = nutlinkAddressTickers;

/**
* nutlinkAddressTickersAll
*
* @returns xxx
*
*/
nutlinkAddressTickersAll = nutlinkAddressTickersAll;

/**
* nutlinkAddressTickerAll
*
* @returns xxx
*
*/
nutlinkAddressTickerAll = nutlinkAddressTickerAll;

/**
* nutlinkTickers
*
* @returns xxx
*
*/
nutlinkTickers = nutlinkTickers;

/**
* nutlinkTickersAll
*
* @returns xxx
*
*/
nutlinkTickersAll = nutlinkTickersAll;

/**
* pools
*
Expand Down
Loading

0 comments on commit d6c2212

Please sign in to comment.