forked from Sfippa/api-client-v1-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var API = require('../api')
var q = require('q')
var UrlPattern = require('url-pattern')
var endpoints = {
charts: new UrlPattern('/charts/:type?format=json(&api_code=:apiCode)(×pan=:timespan)(&rollingAverage=:rollingAverage)'),
pools: new UrlPattern('/pools?format=json(×pan=:timespan\\days)(&api_code=:apiCode)'),
stats: new UrlPattern('/stats?format=json(&api_code=:apiCode)')
}
var api = new API('https://blockchain.info', endpoints)
module.exports = {
get: get,
getChartData: getChartData,
getPoolData: getPoolData
}
function get (options) {
options = options || {}
return api
.request('stats', { apiCode: options.apiCode })
.then(function (data) {
data = options.stat ? data[options.stat] : data
return data || q.reject('Received unknown stat option')
})
}
function getChartData (chartType, options) {
options = options || {}
return api
.request('charts', { type: chartType, apiCode: options.apiCode, timespan: options.timespan, rollingAverage: options.rollingAverage })
.then(function (data) { return data.values })
}
function getPoolData (options) {
options = options || {}
return api
.request('pools', { apiCode: options.apiCode, timespan: options.timespan })
}