Quick Start

APIs that attempt to create Claims using HTTP require API key for access, before you start using them you should register and get your API Key at https://api.userfeeds.io/portal/apis/.

Read-only APIs do not require API key.

Get simple ranking for Ethereum

Those code snippets will return list of news shared to Ethereum context sorted according to our simple algorithm.

In python

import requests

RANKING_URL = "https://api.userfeeds.io/ranking/ethereum/claims/"

response = requests.get(RANKING_URL).json()

print("Simple ranking for Ethereum:\n")

for index, item in enumerate(response['items']):
    print("{0}. {1}".format(index, item["target"]))
    print("Score: {0}".format(item['score']))
    print()


# Simple ranking for Ethereum:
#
# 0. http://example.com/one
# Score: 123.1234324
#
# 1. http://example.com/two
# Score: 32.234542343

In JavaScript (node.js)

const https = require('https');

const options = {
  hostname: 'api.userfeeds.io',
  port: 443,
  path: '/ranking/ethereum/claims/',
  method: 'GET'
};

console.log('Simple ranking for Ethereum:\n')

const req = https.request(options, (res) => {
  let data = "";

  res.setEncoding('utf8');
  res.on('data', (chunk) => {
    data += chunk;
  });
  res.on('end', () => {
    let ranking = JSON.parse(data);
    for (let index in ranking.items) {
      console.log(`${index}. ${ranking.items[index].target}`);
      console.log(`Score: ${ranking.items[index].score}\n`);
    }
  });
});

req.on('error', (e) => {
  console.error(e);
});

req.end();


// Simple ranking for Ethereum:
//
// 0. http://example.com/one
// Score: 123.1234324
//
// 1. http://example.com/two
// Score: 32.234542343

In JavaScript (browser)

<!DOCTYPE html>
<html>
<head>
  <title>Simple ranking for Ethereum:</title>
</head>
<body>
  <script>
    fetch('https://api.userfeeds.io/ranking/ethereum/claims/')
    .then(function(response) {
      return response.json();
    })
    .then(function(ranking) {
      var div = document.getElementById('ranking');

      for (var i = ranking.items.length - 1; i >= 0; i--) {
        var item = ranking.items[i];
        div.innerHTML += i.toString() + '.<a href="' + item.target + '">' + item.target + '</a><br/>';
        div.innerHTML += 'Score: ' + item.score + '<br/><br/>';
      }
    });
  </script>
  <h1>Simple ranking for Ethereum</h1>
  <div id="ranking"></div>
</body>
</html>

Demo:

Get available algorithms for Ethereum

Sometimes you want to give your users more than one view onto the same dataset. You can get algorithms available for Ethereum context using those simple code snippets.

In python

import requests

RANKING_URL = "https://api.userfeeds.io/ranking/ethereum/"

response = requests.get(RANKING_URL).json()

print("Available algorithms for Ethereum:\n")

for index, item in enumerate(response['items']):
    print("ID:", item["identifier"])
    print("Summary:", item['description'])
    print()


# Available algorithms for Ethereum:
#
# ID: simple
# Summary: Simple algorithm
#
# ID: sponsored
# Summary: Sponsored content algorithm

In JavaScript (node.js)

const https = require('https');

const options = {
  hostname: 'api.userfeeds.io',
  port: 443,
  path: '/ranking/ethereum/',
  method: 'GET'
};

console.log('Available algorithms for Ethereum:\n')

const req = https.request(options, (res) => {
  let data = "";

  res.setEncoding('utf8');
  res.on('data', (chunk) => {
    data += chunk;
  });
  res.on('end', () => {
    let ranking = JSON.parse(data);
    for (let item of ranking.items) {
      console.log(`ID: ${item.identifier}`);
      console.log(`Summary: ${item.description}\n`);
    }
  });
});

req.on('error', (e) => {
  console.error(e);
});

req.end();


// Available algorithms for Ethereum:
//
// ID: simple
// Summary: Simple algorithm
//
// ID: sponsored
// Summary: Sponsored content algorithm

In JavaScript (browser)

<!DOCTYPE html>
<html>
<head>
  <title>Available algorithms for Ethereum:</title>
</head>
<body>
  <script>
    fetch('https://api.userfeeds.io/ranking/ethereum/')
    .then(function(response) {
      return response.json();
    })
    .then(function(ranking) {
      var div = document.getElementById('ranking');

      for (var i = ranking.items.length - 1; i >= 0; i--) {
        var item = ranking.items[i];
        div.innerHTML += 'ID: ' + item.identifier + '<br/>';
        div.innerHTML += 'Summary: ' + item.description + '<br/><br/>';
      }
    });
  </script>
  <h1>Available algorithms for Ethereum</h1>
  <div id="ranking"></div>
</body>
</html>

Demo:

Allow your users to sponsor content on your webpage

In JavaScript (browser)

<!DOCTYPE html>
<html>
<head>
  <title>Sponsred ranking for Ethereum:</title>
  <style type="text/css">
    ul#choices li {
      list-style: none;
      display: inline-block;
    }

    ul#choices li img {
      width: 200px;
      height: auto;
    }

    div#ranking img {
      width: 180px;
      height: auto;
      margin-right: 20px;
    }

    ul.winners li {
      display: inline-block;
    }
  </style>
</head>
<body>
  <h1>Winners:</h1>
  <div id="ranking"></div>

  Ranking address:<input type="text" id="address" value="rinkeby:0xfe5da6ae3f65e7d5ce29121a9f5872ffd83b45e6"/>
  <button onclick="init();">Refresh</button>


  <h1>Which is the best animal?:</h1>
  <ul id="choices">
    <li>
      <img id="cat" src="img/cat.png">
      <br/>
      <button onclick="promote(this, 0.01);">Promote by 0.01 Ether</button><br/>
      <button onclick="promote(this, 0.1);">Promote by 0.1 Ether</button><br/>
      <button onclick="promote(this, 1);">Promote by 1 Ether</button>
    </li>
    <li>
      <img id="dog" src="img/dog.png">
      <br/>
      <button onclick="promote(this, 0.01);">Promote by 0.01 Ether</button><br/>
      <button onclick="promote(this, 0.1);">Promote by 0.1 Ether</button><br/>
      <button onclick="promote(this, 1);">Promote by 1 Ether</button>
    </li>
    <li>
      <img id="horse" src="img/horse.png">
      <br/>
      <button onclick="promote(this, 0.01);">Promote by 0.01 Ether</button><br/>
      <button onclick="promote(this, 0.1);">Promote by 0.1 Ether</button><br/>
      <button onclick="promote(this, 1);">Promote by 1 Ether</button>
    </li>
    <li>
      <img id="bird" src="img/bird.png">
      <br/>
      <button onclick="promote(this, 0.01);">Promote by 0.01 Ether</button><br/>
      <button onclick="promote(this, 0.1);">Promote by 0.1 Ether</button><br/>
      <button onclick="promote(this, 1);">Promote by 1 Ether</button>
    </li>
  </ul>

  <script>
    var rankingAddress = null;
    var content = {};

    function init() {
      rankingAddress = document.getElementById('address').value;

      var choices = document.getElementById('choices').getElementsByTagName("li");

      for (var i = choices.length - 1; i >= 0; i--) {
        var img = choices[i].getElementsByTagName('img')[0];
        content[img.id] = img.src;
      }

      displayRanking();
    }

    function displayRanking() {
      fetch(`https://api.userfeeds.io/ranking/${rankingAddress}/sponsored/`)
      .then(response => response.json())
      .then(ranking => {
        let div = document.getElementById('ranking');

        let html = '<ul class="winners">';
        for (let i = 0; i <= 3; i++) {
          let item = ranking.items[i];
          if (item) {
            let src = content[toAscii(item.target)];
            let score = item.score;
            if (src) {
              html += `<li><img src="${src}"><br/>Score: ${score}</li>`;
            }
          }
        }
        html += '</ul>';

        div.innerHTML = html;
      });
    }

    function promote(button, value) {
      var img = button.parentElement.getElementsByTagName('img')[0];

      // Send identifier as transaction data
      var data = web3.fromAscii(img.id);

      web3.eth.sendTransaction({to: rankingAddress.split(':')[1], data: data, value: web3.toWei(value, 'ether')}, function(err, address) {
        if (!err)
          alert("Thank You!");
      });
    }

    function toAscii (hex) {
        var str = '',
            i = 0,
            l = hex.length;
        if (hex.substring(0, 2) === '0x') {
            i = 2;
        }
        for (; i < l; i+=2) {
            var code = parseInt(hex.substr(i, 2), 16);
            if (code === 0) continue; // this is added
            str += String.fromCharCode(code);
        }
        return str;
    };

    init();
  </script>
</body>
</html>

Demo: