shapeshiftjs
Advanced tools
Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "shapeshiftjs", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "A javascript wrapper for the ShapeShift API", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha test/" | ||
}, | ||
@@ -18,4 +18,5 @@ "keywords": [ | ||
"bluebird": "^3.3.4", | ||
"request-promise": "^2.0.1" | ||
"request-promise": "^2.0.1", | ||
"should": "^8.3.0" | ||
} | ||
} |
145
src/index.js
@@ -0,43 +1,19 @@ | ||
'use strict'; | ||
var ShapeShiftJS = module.exports; | ||
var request = require('request-promise'); | ||
function getBaseUrl () { | ||
var endpoint = 'shapeshift.io' | ||
// https://shapeshift.io/api.html#cors | ||
return module.exports.cors ? 'https://cors.' + endpoint : 'https://' + endpoint | ||
var endpoint = 'shapeshift.io'; | ||
return 'https://' + endpoint; | ||
} | ||
/** | ||
* getCoins() Get an array of currencies supported by ShapeShift | ||
* | ||
* url: shapeshift.io/getcoins | ||
* method: GET | ||
* | ||
* @returns { Array } | ||
*/ | ||
var getCoins = function() { | ||
let options = { | ||
uri: baseUrl() + '/getcoins', | ||
headers: { | ||
'User-Agent': 'ShapeShiftJS' | ||
}, | ||
json: true | ||
} | ||
return request(options) | ||
.then(function (coins) { | ||
return coins; | ||
}) | ||
.catch(function(err) { | ||
return err; | ||
}); | ||
}; | ||
/** | ||
* getRate() Get the current rate offered by shapeshift for a currency pair | ||
* | ||
* url: shapeshift.io/getcoins | ||
* url: shapeshift.io/rate/ [currencyPair] | ||
* method: GET | ||
* | ||
* @param { String } currencyPair btc_ltc | ||
* | ||
* @returns { Object } currencyPairInfo | ||
@@ -48,3 +24,3 @@ * @returns { String } currencyPairInfo.pair btc_ltc | ||
var getRate = function(currencyPair) { | ||
ShapeShiftJS.getRate = function(currencyPair) { | ||
@@ -54,3 +30,3 @@ if (currencyPair.indexOf('_') === -1) { throw new Error('Invalid currency pair string.') } | ||
let options = { | ||
uri: baseUrl() + '/rate/' + currencyPair, | ||
uri: getBaseUrl() + '/rate/' + currencyPair, | ||
headers: { | ||
@@ -78,2 +54,3 @@ 'User-Agent': 'ShapeShiftJS' | ||
* @param { String } currencyPair btc_ltc (OPTIONAL) | ||
* | ||
* @returns { Object } marketInfo | ||
@@ -87,3 +64,3 @@ * @returns { String } marketInfo.pair btc_ltc | ||
var getMarketInfo = function(currencyPair) { | ||
ShapeShiftJS.getMarketInfo = function(currencyPair) { | ||
@@ -93,3 +70,3 @@ if (currencyPair.indexOf('_') === -1) { throw new Error('Invalid currency pair string.') } | ||
let options = { | ||
uri: baseUrl() + '/marketinfo/' + currencyPair, | ||
uri: getBaseUrl() + '/marketinfo/' + currencyPair, | ||
headers: { | ||
@@ -125,6 +102,6 @@ 'User-Agent': 'ShapeShiftJS' | ||
var recentTx = function(max) { | ||
ShapeShiftJS.recentTx = function(max) { | ||
let options = { | ||
uri: baseUrl() + '/marketinfo/' + max, | ||
uri: getBaseUrl() + '/recenttx/' + max, | ||
headers: { | ||
@@ -179,6 +156,6 @@ 'User-Agent': 'ShapeShiftJS' | ||
var getTxStatus = function(address) { | ||
ShapeShiftJS.getTxStatus = function(address) { | ||
let options = { | ||
uri: baseUrl() + '/txStat/' + address, | ||
uri: getBaseUrl() + '/txStat/' + address, | ||
headers: { | ||
@@ -206,2 +183,3 @@ 'User-Agent': 'ShapeShiftJS' | ||
* @param { String } address | ||
* | ||
* @returns { Object } time | ||
@@ -212,6 +190,6 @@ * @returns { String } time.status pending or expired | ||
var getTimeRemaining = function(address) { | ||
ShapeShiftJS.getTimeRemaining = function(address) { | ||
let options = { | ||
uri: baseUrl() + '/timeremaining/' + address, | ||
uri: getBaseUrl() + '/timeremaining/' + address, | ||
headers: { | ||
@@ -245,6 +223,6 @@ 'User-Agent': 'ShapeShiftJS' | ||
var getCoinInfo = function() { | ||
ShapeShiftJS.getCoinInfo = function() { | ||
let options = { | ||
uri: baseUrl() + '/getcoins', | ||
uri: getBaseUrl() + '/getcoins', | ||
headers: { | ||
@@ -266,3 +244,3 @@ 'User-Agent': 'ShapeShiftJS' | ||
/** | ||
* validateAddress() Validate an address given a currency symbol and addres | ||
* validateAddress() Validate an address given a currency symbol and address | ||
* | ||
@@ -274,2 +252,3 @@ * url: shapeshift.io/validateAddress/[address]/[coinSymbol] | ||
* @param { String } coinSymbol | ||
* | ||
* @returns { Object } response | ||
@@ -280,6 +259,6 @@ * @returns { String } response.isValid true | ||
var validateAddress = function(address, symbol) { | ||
ShapeShiftJS.validateAddress = function(address, symbol) { | ||
let options = { | ||
uri: baseUrl() + '/validateAddress/' + address + '/' + symbol, | ||
uri: getBaseUrl() + '/validateAddress/' + address + '/' + symbol, | ||
headers: { | ||
@@ -307,19 +286,32 @@ 'User-Agent': 'ShapeShiftJS' | ||
* | ||
* @param { String } address | ||
* @param { String } coinSymbol | ||
* @param { String } withdrawTo | ||
* @param { String } currencyPair btc_ltc | ||
* @param { String } returnAddress (OPTIONAL) | ||
* @param { String } shapeshiftApiKey (OPTIONAL) | ||
* | ||
* @returns { Object } response | ||
* @returns { String } response.isValid true | ||
* @returns { String } response.error (if isValid is false) | ||
* @returns { String } response.deposit [ deposit address] | ||
* @returns { String } response.withdrawal [ withdrawal address ] | ||
* @returns { String } response.withdrawalType [ output coin symbol ] | ||
* | ||
* If input coin is NXT | ||
* @returns { String } response.public [ NXT RS_Address pubkey] | ||
* | ||
* If input coin is XRP | ||
* @returns { String } response.xrpDestTag [ xrpDestTag ] | ||
* | ||
* If API Key provided | ||
* @returns { String } response.apiPubKey | ||
*/ | ||
var postShift = function(params) { | ||
ShapeShiftJS.postShift = function(params) { | ||
let options = { | ||
method: 'POST', | ||
uri: baseUrl() + '/shift', | ||
uri: getBaseUrl() + '/shift', | ||
body: { | ||
withdrawTo: params.withdrawTo, | ||
currencyPair: params.currencyPair | ||
returnAddress: params.returnAddress || '', | ||
apiKey: config.shapeshiftApiKey || '' | ||
currencyPair: params.currencyPair, | ||
returnAddress: params.returnAddress || null, | ||
apiKey: config.shapeshiftApiKey || null | ||
}, | ||
@@ -341,7 +333,22 @@ headers: { | ||
var postRequestEmail = function(params) { | ||
/** | ||
* postRequestEmail() Request that a receipt for a transaction be sent by email | ||
* | ||
* url: shapeshift.io/mail | ||
* method: POST | ||
* data type: JSON | ||
* | ||
* @param { String } email | ||
* @param { String } txid | ||
* | ||
* @returns { Object } response | ||
* @returns { String } response.status success | ||
* @returns { String } response.message Email receipt sent | ||
*/ | ||
ShapeShiftJS.postRequestEmail = function(params) { | ||
let options = { | ||
method: 'POST', | ||
uri: baseUrl() + '/mail', | ||
uri: getBaseUrl() + '/mail', | ||
body: { | ||
@@ -366,7 +373,27 @@ email: params.email, | ||
var sendAmount = function(params) { | ||
/** | ||
* postSendAmount() Request that a fixed amount be sent to the withdrawal address | ||
* | ||
* url: shapeshift.io/sendamount | ||
* method: POST | ||
* data type: JSON | ||
* | ||
* @param { String } amount | ||
* @param { String } withdrawal | ||
* @param { String } pair | ||
* @param { String } returnAddress (OPTIONAL) | ||
* @param { String } destTag (OPTIONAL) | ||
* @param { String } rsAddress (OPTIONAL) | ||
* @param { String } apiKey (OPTIONAL) | ||
* | ||
* @returns { Object } response | ||
* @returns { String } response.status success | ||
* @returns { String } response.message Email receipt sent | ||
*/ | ||
ShapeShiftJS.postSendAmount = function(params) { | ||
let options = { | ||
method: 'POST', | ||
uri: baseUrl() + '/sendamount', | ||
uri: getBaseUrl() + '/sendamount', | ||
body: { | ||
@@ -373,0 +400,0 @@ amount: params.amount, |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
13592
5
467
2
1
4
3
+ Addedshould@^8.3.0
+ Addedshould@8.4.0(transitive)
+ Addedshould-equal@0.8.0(transitive)
+ Addedshould-format@0.3.2(transitive)
+ Addedshould-type@0.2.0(transitive)