API

node v4.9.1
version: 1.0.2
endpointsharetweet
In order to view stats, first click the "clone and edit this notebook" button at the bottom of the page. Then, in the left bar of the page, click the T icon, then click "environment settings". Here you need to add two variables, CITETHAT_KEY and CITETHAT_SECRET (get those from Pete). Then come back here and proceed down farther.
const http = require('http'); const key = process.env.CITETHAT_KEY; const signature = process.env.CITETHAT_SECRET; function statsForHash(hash) { return new Promise((resolve) => { let dataInProgress = ''; const req = http.request({ host: 'api.citeth.at', path: '/stats/' + hash, headers: { 'Content-Type': 'application/json', 'apiKey': key, 'signature': signature } }, (res) => { res.on('data', (chunk) => { dataInProgress += chunk; }); res.on('end', () => { try { resolve(JSON.parse(dataInProgress)); } catch (err) { reject(err); } }); }); req.end(); }); } module.exports = { statsForHash: statsForHash }; 0;
Below, replace the values in hashes with whatever hashes you're curious about (that is, http://citeth.at/<hash>) When you're ready, press shift+return with your cursor in the box below and the counts/results will appear. From there you can toggle view options to see it in bar graphs, pie graphs etc.
const hashes = [ 'z2b2bca', 'z364126' ] await Promise.all(hashes.map((hash) => statsForHash(hash))) .then((results) => { let mappedResults = results.map((result) => Number(result.count)); for (let i = 0; i < results.length; i++) { //console.log(i + ': ' + hashes[i]); } return Promise.resolve(mappedResults); });
exports
Loading…

no comments

    sign in to comment