Revive Utopian Chrome Extension thanks to @wehmoen ! (Wrapping Utopian API Calls)

in #utopian-io7 years ago (edited)

Utopian Moderators & Supervisors is a Chrome Extension that has iterated for 12 versions, however, sadly, since last time Utopian revokes for all API calls the Chrome Extension is virtually dead i.e. all API calls to https://api.utopian.io/api return 500 internal server error.

I submitted a support ticket asking for the utopian API key but got rejected because:

A API key must not be given out to end users and/or other developers.
An API Key is bind to one ore more domains. From which domain/domains will you send the requests. At the moment we can only provide API keys suiteable for ajax requests made from websites in a browser.

Luckily, at the London Cryptocurrency Show I met @wehmoen who is the leading developer (staff) at @utopian-io therefore I managed to persuade him giving me the API key by proposing that I will wrap the API key on my server and change all API calls in the chrome extension to my API server, where I will hide all the API key/secret in my server.

Therefore, with the changes commited here, the Utopian Moderators v0.0.13 is back to life!

You can install the extension at Chrome Webstore. For Opera browsers, the workaround is to first installthis and similarly for Firefox, you can install Chrome Store Foxified before you install Utopian Moderators & Supervisors.

API wrapping in PHP

<?php
/*
  utopian api wrapper at server side
  thanks to @wehmoen for providing me api key
*/
define("ORIGIN", "");
define("API_KEY", "");
define("API_KEY_ID", "");
function CallAPI($url, &$error, $data = null, $headers = null) {
  $curl = curl_init($url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  if ($headers) {
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  }
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
  $response = curl_exec($curl);
  $data = json_decode($response);
  /* Check for 404 (file not found). */
  $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  // Check the HTTP Status code
  switch ($httpCode) {
    case 200:
        $error = 200;
        break;
    case 404:
        $error = 404;
        break;
    case 500:
        $error = 500;
        break;
    case 502:
        $error = 502;
        break;
    case 503:
        $error = 503;
        break;
    default:
        $error = $httpCode;
        break;
  }
  curl_close($curl);
  return ($data);  
}    
$api = $_GET['api'] ?? '';
if (!$api) {
  die();
}

// avoid hacking to get the keys
$host = strtolower(parse_url($api, PHP_URL_HOST));
if ($host != 'api.utopian.io') {
  die();
}

$headers = array("Origin: " . ORIGIN, "x-api-key: " . API_KEY, "x-api-key-id: " . API_KEY_ID);
$err = '';
$data = CallAPI($api, $err, null, $headers);
header("Access-Control-Allow-Origin: *");  
header('Content-Type: application/json');
if ($err === 200) {
  die(json_encode($data));
} else {
  die(json_encode(array("error" => $err, "raw" => $data)));
}

image.png

PS: just confirmed with @wehmoen the https://utopian.plus/unreviewedPosts.json is not working anymore and unfortunately there is currently no suitable API calls for this purpose.

Long live @utopian-io !

Reposted to my blog for better indexing and archiving.


Support me and my work as a witness by

  1. voting me here, or
  2. voting me as a proxy.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

I like this extention.. how can i do for use it

Thanks for the contribution. It has been approved.

Cool! I might need to try something like this, since utopian-cli is currently dead as well.


Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Hey @justyy I am @utopian-io. I have just upvoted you!

Achievements

  • People loved what you did here. GREAT JOB!
  • Seems like you contribute quite often. AMAZING!

Utopian Witness!

Participate on Discord. Lets GROW TOGETHER!

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Hey I just checked out a bunch of tools, toys, and awesome stuff you have made for streamians. That being the case I saw your message and just now voted for you as my witness. Just keep it up guy and I will stay happy. This one you talk about on the post looks great too.

Thank you very much.

No justy thank you for us steemians.

Hello @justyy.
Today I have left my vote, to support you as a witness.
That you continue contributing with your talent and kindness in the Steemit community.
Que estés siempre muy feliz.

Thank you very much.

Coin Marketplace

STEEM 0.20
TRX 0.25
JST 0.038
BTC 97161.42
ETH 3477.12
USDT 1.00
SBD 3.11