pulsar_sdk_js
Version:
A convenient way for you to interact with Pulsar's Third Party APIs, using typified classes.
55 lines (54 loc) • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const class_transformer_1 = require("class-transformer");
const base_1 = require("./base");
const schema_1 = require("../data/dataclasses/schema");
class NFTRestClient extends base_1.RestClient {
async list_collection_nfts(collection_id, options = {}) {
const { search_string = undefined, rarity_score = undefined, rank_minimum = undefined, rank_maximum = undefined, traits = undefined, sort_by = undefined, offset = 0, limit = 10, } = options;
const traits_dict = {
traits: traits === undefined ? {} : traits.traits,
};
const response = await this._request(`/nfts/collections/${collection_id}/nfts`, 'POST', traits_dict, {
search_string,
rarity_score,
rank_minimum,
rank_maximum,
sort_by,
offset,
limit,
});
return (0, class_transformer_1.plainToInstance)(schema_1.PaginatedNFTItem, response);
}
async fetch_collection(collection_id) {
const response = await this._request(`/nfts/collections/${collection_id}`, 'GET');
return (0, class_transformer_1.plainToInstance)(schema_1.NFTCollection, response);
}
async fetch_collection_by_address(chain, collection_address) {
const response = await this._request(`/nfts/collections/${chain}/${collection_address}`, 'GET');
return (0, class_transformer_1.plainToInstance)(schema_1.NFTCollection, response);
}
async fetch_nft_by_address(chain, collection_address, token_id) {
const response = await this._request(`/nfts/collections/${chain}/${collection_address}/nfts`, 'GET', {}, {
token_id,
});
return (0, class_transformer_1.plainToInstance)(schema_1.NFTItem, response);
}
async fetch_nft(collection_id, token_id) {
const response = await this._request(`/nfts/collections/${collection_id}/nfts/${token_id}`, 'GET');
return (0, class_transformer_1.plainToInstance)(schema_1.NFTItem, response);
}
async list_nfts(options = {}) {
const { chains = undefined, offset = 0, limit = 10, is_fully_index = true, name = undefined, sort_by = undefined, } = options;
const response = await this._request('/nfts', 'GET', {}, {
chains,
offset,
limit,
is_fully_index,
name,
sort_by,
});
return (0, class_transformer_1.plainToInstance)(schema_1.PaginatedNFTCollection, response);
}
}
exports.default = NFTRestClient;