cardano-api
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -8,16 +8,21 @@ const request = require('request') | ||
// buildMethod returns a function that returns a promise | ||
const buildMethod = endpoint => query => new Promise((resolve, reject) => { | ||
let path = '', params = '', stopper | ||
let path = '', params = '', badKey | ||
if(query) { | ||
// if trying to set a path in the query but path is not available for this | ||
// endpoint, then reject | ||
if(!endpoint.path && query.path) return reject(noPathAllowed) | ||
params = Object.keys(query).reduce((str, key) => { | ||
// if this is not a valid param for the endpoint, set the badKey | ||
if(!endpoint.params.includes(key)) { | ||
stopper = true | ||
badKey = key | ||
} | ||
// if one of the keys matches a path, set the path for the url | ||
if(paths.includes(key)) { | ||
@@ -28,2 +33,3 @@ path = `/${query[key]}` | ||
// tack on the current ket to the params string | ||
str += `${key}=${query[key]}&` | ||
@@ -34,9 +40,12 @@ return str | ||
// if there are params add a '?' to the front and remove the trailing '&' | ||
params = params ? `?${params.replace(/\&$/, '')}` : '' | ||
if(stopper) return reject(`${stopper} is not a valid query to this endpoint`) | ||
if(badKey) return reject(`${badKey} is not a valid query to this endpoint`) | ||
} | ||
// if the endpoint requires a path but it is not provided reject | ||
if(endpoint.path && !path) return reject(noPathProvided) | ||
// build the url | ||
const url = `${api}${endpoint.url}${path}${params}` | ||
@@ -46,3 +55,5 @@ | ||
if(err) reject(err) | ||
if(res.statusCode === 404 || res.statusCode === 400) reject(res.statusMessage) | ||
if(res.statusCode === 404 || res.statusCode === 400) { | ||
reject(`${res.statusCode}: ${res.statusMessage}`) | ||
} | ||
if(body) resolve(JSON.parse(body)) | ||
@@ -49,0 +60,0 @@ }) |
{ | ||
"name": "cardano-api", | ||
"version": "0.0.4", | ||
"description": "Node promise wrapper for the Cardano Explorer API", | ||
"version": "0.0.5", | ||
"description": "Node wrapper for the Cardano Explorer API", | ||
"main": "lib/cardano.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
# cardano-api | ||
Promise wrapper for the [Cardano API](https://cardanodocs.com/technical/explorer/api/). | ||
Wrapper for the [Cardano API](https://cardanodocs.com/technical/explorer/api/). | ||
@@ -81,3 +81,2 @@ ```js | ||
```js | ||
const query = { | ||
@@ -156,2 +155,2 @@ page: 1, // Optional | ||
#### Thank You | ||
##### Thank You |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18986
7
498
154