diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..123ae94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git +node_modules diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5ce0575 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - 'stable' + - '0.12' + - '0.10' +sudo: false +cache: + directories: + - node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3397844 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# cryptocompare change log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## Unreleased +* engage diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..169c5d1 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +# [MIT License](https://spdx.org/licenses/MIT) + +Copyright (c) 2016 JP Richardson + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0948d4f --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +cryptocompare +============= + +[![npm][npm-image]][npm-url] +[![travis][travis-image]][travis-url] +[![standard][standard-image]][standard-url] + +[npm-image]: https://img.shields.io/npm/v/cryptocompare.svg?style=flat-square +[npm-url]: https://www.npmjs.com/package/cryptocompare +[travis-image]: https://img.shields.io/travis/jprichardson/cryptocompare.svg?style=flat-square +[travis-url]: https://travis-ci.org/jprichardson/cryptocompare +[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square +[standard-url]: http://npm.im/standard + +CryptoCompare JavaScript API + +Install +------- + + npm install cryptocompare + + +Usage +----- + +### Methods + +#### coinList + +Reference: https://www.cryptocompare.com/api/#-api-data-coinlist- + +| ---: | :--- | +| Signature | `coinList()` | +| Parameters | (none) | +| Returns | A Promise function. | + +```js +var cryptocompare = require('cryptocompare') +``` + + +## License + +[MIT](LICENSE.md) diff --git a/index.js b/index.js new file mode 100644 index 0000000..1214afc --- /dev/null +++ b/index.js @@ -0,0 +1,22 @@ +/* global fetch */ + +var baseUrl = 'https://www.cryptocompare.com/api/data/' + +function fetchJSON (url) { + return fetch(url) + .then(res => res.json()) + .then(body => { + // 'response' is a CryptoCompare field + if (body.Response !== 'Success') throw new Error(body.Message) + return body.Data + }) +} + +function coinList () { + var url = baseUrl + 'coinlist/' + return fetchJSON(url) +} + +module.exports = { + coinList +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..f8309a2 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "cryptocompare", + "description": "CryptoCompare JavaScript API", + "version": "0.0.0", + "author": "JP Richardson ", + "bugs": { + "url": "https://github.com/exodusmovement/cryptocompare/issues" + }, + "devDependencies": { + "node-fetch": "^1.5.3", + "standard": "*", + "tap-spec": "^4.0.2", + "tape": "^4.0.0" + }, + "homepage": "https://github.com/exodusmovement/cryptocompare", + "keywords": [ + "api", + "bitcoin", + "cryptocurrency", + "ethereum", + "price" + ], + "license": "MIT", + "main": "index.js", + "repository": { + "type": "git", + "url": "https://github.com/exodusmovement/cryptocompare.git" + }, + "scripts": { + "test": "standard && tape test/*.js | tap-spec" + } +} diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..45a382a --- /dev/null +++ b/test/index.js @@ -0,0 +1,12 @@ +var test = require('tape') + +// set to global +global.fetch = require('node-fetch') +var cc = require('../') + +test('coinList()', function (t) { + t.plan(1) + cc.coinList().then(coinList => { + t.strictEqual(coinList.BTC.CoinName, 'Bitcoin') + }).catch(t.end) +})