crypto-news-api
Advanced tools
Comparing version 1.0.0 to 1.0.1
"use strict"; | ||
console.log('hello world'); | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var node_fetch_1 = require("node-fetch"); | ||
var debug = require("debug"); | ||
var qs = require("qs"); | ||
var logger = debug('crypto-news-api'); | ||
var API_HOST = 'https://cryptocontrol.io/api/v1'; | ||
var CryptoControlApi = /** @class */ (function () { | ||
function CryptoControlApi(apikey) { | ||
if (!apikey) | ||
throw new Error('No API key found. Register for an API key at https://cryptocontrol.io/apis'); | ||
this.apikey = apikey; | ||
logger('using cryptocontrol.io api v1'); | ||
} | ||
CryptoControlApi.prototype._fetch = function (url, query) { | ||
if (query === void 0) { query = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var queryString; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
queryString = qs.stringify(__assign({}, query, { key: this.apikey })); | ||
return [4 /*yield*/, node_fetch_1.default("" + API_HOST + url + "?" + queryString)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CryptoControlApi.prototype.getTopNews = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this._fetch('/public/news')]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CryptoControlApi.prototype.getLatestNews = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this._fetch('/public/news', { latest: true })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CryptoControlApi.prototype.getTopNewsByCategory = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this._fetch("/public/news/category")]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CryptoControlApi.prototype.getTopNewsByCoin = function (coinSlug) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this._fetch("/public/news/coin/" + coinSlug)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CryptoControlApi.prototype.getLatestNewsByCoin = function (coinSlug) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this._fetch("/public/news/coin/" + coinSlug, { latest: true })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CryptoControlApi.prototype.getTopNewsByCoinCategory = function (coinSlug) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this._fetch("/public/news/coin/" + coinSlug + "/category")]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return CryptoControlApi; | ||
}()); | ||
exports.default = CryptoControlApi; |
94
index.ts
@@ -1,1 +0,93 @@ | ||
console.log('hello world') | ||
import fetch from 'node-fetch' | ||
import * as debug from 'debug' | ||
import * as qs from 'qs' | ||
const logger = debug('crypto-news-api') | ||
const API_HOST = 'https://cryptocontrol.io/api/v1' | ||
export interface IArticle { | ||
_id: string | ||
publishedAt: string | ||
hotness: number | ||
activityHotness: number | ||
primaryCategory: string | ||
words: number | ||
similarArticles: [{ | ||
_id: string | ||
publishedAt: string | ||
title: string | ||
url: string | ||
}] | ||
coins: [{ | ||
_id: string | ||
name: string | ||
slug: string | ||
tradingSymbol: string | ||
}] | ||
description: string | ||
title: string | ||
url: string | ||
thumbnail: string | ||
} | ||
export interface ICategoryResponse { | ||
analysis: IArticle[] | ||
blockchain: IArticle[] | ||
exchanges: IArticle[] | ||
general: IArticle[] | ||
government: IArticle[] | ||
ico: IArticle[] | ||
mining: IArticle[] | ||
} | ||
export default class CryptoControlApi { | ||
apikey: string | ||
constructor(apikey: string) { | ||
if (!apikey) throw new Error('No API key found. Register for an API key at https://cryptocontrol.io/apis') | ||
this.apikey = apikey | ||
logger('using cryptocontrol.io api v1') | ||
} | ||
private async _fetch(url: string, query: any = {}): Promise<any> { | ||
const queryString = qs.stringify({ | ||
...query, | ||
key: this.apikey | ||
}) | ||
return await fetch(`${API_HOST}${url}?${queryString}`) | ||
} | ||
public async getTopNews(): Promise<IArticle> { | ||
return await this._fetch('/public/news') | ||
} | ||
public async getLatestNews(): Promise<IArticle> { | ||
return await this._fetch('/public/news', { latest: true }) | ||
} | ||
public async getTopNewsByCategory(): Promise<ICategoryResponse> { | ||
return await this._fetch(`/public/news/category`) | ||
} | ||
public async getTopNewsByCoin(coinSlug: string): Promise<IArticle> { | ||
return await this._fetch(`/public/news/coin/${coinSlug}`) | ||
} | ||
public async getLatestNewsByCoin(coinSlug: string): Promise<IArticle> { | ||
return await this._fetch(`/public/news/coin/${coinSlug}`, { latest: true }) | ||
} | ||
public async getTopNewsByCoinCategory(coinSlug: string): Promise<ICategoryResponse> { | ||
return await this._fetch(`/public/news/coin/${coinSlug}/category`) | ||
} | ||
} |
{ | ||
"name": "crypto-news-api", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "API to get a crypto newsfeed in your app", | ||
@@ -26,4 +26,15 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@types/bluebird": "^3.5.20", | ||
"@types/debug": "0.0.30", | ||
"@types/es6-promise": "^3.3.0", | ||
"@types/node-fetch": "^1.6.9", | ||
"@types/qs": "^6.5.1", | ||
"typescript": "^2.8.3" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.5.1", | ||
"debug": "^3.1.0", | ||
"node-fetch": "^2.1.2", | ||
"qs": "^6.5.2" | ||
} | ||
} |
@@ -1,5 +0,5 @@ | ||
CryptoControl Node.js API | ||
CryptoControl Crypto News API | ||
========================= | ||
NPM Package that allows users to access the cryptocontrol API via node. | ||
Node.js official client to [CryptoControl.io](https://cryptocontrol.io) API. The CryptoControl Node.js API let's developer access rich formatted articles from cryptonews sources from all around the world. | ||
@@ -10,7 +10,46 @@ ## Installation | ||
``` | ||
```sh | ||
yarn add crypto-news-api | ||
## Usage | ||
First make sure that you've recieved an API by visiting [https://cryptocontrol.io/apis](https://cryptocontrol.io/apis). With the api key you can write the following code. | ||
```javascript | ||
import CryptoControl from 'crypto-news-api' | ||
const Api = new CryptoControl('API_KEY_HERE') | ||
Api.getTopNews() | ||
.then(articles => console.log(articles)) | ||
.catch(error => console.error(error)) | ||
``` | ||
```sh | ||
bower install crypto-news-api --save | ||
## Sample Response from the API | ||
```javascript | ||
[ | ||
{ | ||
"publishedAt": "2018-05-23T06:30:51.000Z", | ||
"hotness": 70698.68569444444, | ||
"activityHotness": 1.6, | ||
"primaryCategory": "General", | ||
"words": 302, | ||
"similarArticles": [ | ||
{ | ||
"publishedAt": "2018-05-23T03:00:05.000Z", | ||
"_id": "5b04de8d18f173000f9a6d72", | ||
"title": "PayPal: We’ll ‘Definitely Support’ Bitcoin If It Becomes ‘Better Currency’", | ||
"url": "https://cryptocontrol.io/r/api/article/5b04de8d18f173000f9a6d72?ref=5ac11440ec0af7be35528459" | ||
} | ||
], | ||
"coins": [ | ||
{ | ||
"_id": "59cb59e81c073f09e76f614b", | ||
"name": "Bitcoin", | ||
"slug": "bitcoin", | ||
"tradingSymbol": "btc" | ||
} | ||
], | ||
"_id": "5b050b2018f173000f9a7036", | ||
"description": "The Chief Financial...", | ||
"url": "https://cryptocontrol.io/r/api/article/5b050b2018f173000f9a7036?ref=5ac11440ec0af7be35528459" | ||
} | ||
] | ||
``` |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": [ | ||
"es2015" | ||
], | ||
"module": "commonjs", | ||
@@ -5,0 +8,0 @@ "declaration": true, |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
12854
260
54
4
6
1
+ Addedbluebird@^3.5.1
+ Addeddebug@^3.1.0
+ Addednode-fetch@^2.1.2
+ Addedqs@^6.5.2
+ Addedbluebird@3.7.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddebug@3.2.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedobject-inspect@1.13.2(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)