Estimation hardware performance in games.
API description

Signing request

The API is protected with HTTP request signing with HMAC-SHA1 algorithm . This approach is widely used and provides moderate level of API protection. As the result of the signing procedure the API expects Authorization header in each request. Some clear example can be seen in here

Creating Authorization header

  1. You need API key and secret that we provide you along with the API
  2. The signing procedure parameters:
  1. HTTP method, for example ‘POST’ , ‘GET’
  2. URL path , for example in Javascript it can be obtained with the following code:
    const uri = new URL('https://ul-benchmarks.appspot.com/api/estimate');
    const urlPath = uri.pathname;
  3.  API key 
  4. Secret 

The example depends on crypto package "crypto-browserify", so please have it in your application dependency with npm install crypto-browserify -- save
                           const CryptoJS = require('crypto');   

 

    calculateRFC2104HMAC(text, key){

        return CryptoJS.createHmac('sha1', key)

        .update(text)

        .digest('hex');     

    }

 

    getAuthHeader(method, uriStr, apikey, secret){

        if(!uriStr || !apikey || !secret || !method){

          return;

        }

 

        const date = (new Date().getTime() / 1000).toString().split(".")[0]; // unix stamp seconds

        const uri = new URL(uriStr);

        const signatureString = 
           `
(request-target): ${method} ${uri.pathname} date: ${date.toString()}`.toLowerCase();

        const signature = this.calculateRFC2104HMAC(signatureString, secret);

        // NOTE: for debugging

        // console.log(`signature: ${signature}, apikey: ${apikey}, secret: ${secret}`);

        return `Signature keyId="${apikey}",algorithm="hmac-sha1",headers="(request-target) date",nonce="${date.toString()}",signature="${signature}"`; 

    }

 

The following example is API ‘list-gpu’ call:

<?php 

    $apiKey = '<YOUR_API_KEY>';

    $apiSecret = '<YOUR_SECRET>';

    $fullURLString = 'https://ul-benchmarks.appspot.com/api/list-gpu';

    $options = array(

        'key' => $apiSecret,

        'keyId' => $apiKey,

        'algorithm' => 'hmac-sha1');

    $options['headers'] = array('(request-target) date', 'nonce');

    $forNonce = date_timestamp_get(new Datetime("now"));

    $headers['nonce'] = $forNonce;

   

    $sign = array();

    $data = join("\n", $sign);

    $signatureString = "(request-target): get /api/list-gpu date: " . strval($forNonce);

    $signature = hash_hmac('sha1', $signatureString, $options['key']);

   

    $final = 'Signature keyId="' . $options['keyId'] . '",algorithm="hmac-sha1"' . ',headers="(request-target) date"' . ',nonce="' . strval($forNonce) . '",signature="' . $signature . '"';

    /*echo "Sample authorization: " . 'Signature keyId="623dc04f515644d89ea9b3944488cd03",algorithm="hmac-sha1",headers="(request-target) date",nonce="1619103273",signature="9da04b2be4de94de02150d3b60ce488c6a30d42f"' . "</br>";

    echo "Sent signatureString: " . $signatureString . "</br>";

    echo "Sent signature: " . $signature . "</br>";

    echo "Sent authorization: " . $final . "</br>";*/ 

    $headers['authorization'] = $final;

    $http_headers = array();

    foreach ($headers as $k => $v) {

        $http_headers[] = "$k: $v";

    }

    $http_headers[] = "accept: application/json";

    $http_headers[] = "X-Api-Key: $apiKey";

    $ch = curl_init($fullURLString);

    curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $response = curl_exec($ch);

    $err = curl_error($ch);

    if ($err) {

        echo "<p>" . $err . "</p>";    

    }

    echo "<p>" . $response . "</p>";    

    curl_close($ch);

?>

Output looks like the structure below:

[

  {

    "name": "2x AMD Radeon RX 460",

    "type": "desktop"

  },

...

]


The following example is API ‘estimate’ call:

<?php 

    $apiKey = '<YOUR_API_KEY>';

    $apiSecret = '<YOUR_SECRET>';

    $fullURLString = 'https://ul-benchmarks.appspot.com/api/estimate';

    $options = array(

        'key' => $apiSecret,

        'keyId' => $apiKey,

        'algorithm' => 'hmac-sha1');

    $forNonce = date_timestamp_get(new Datetime("now"));

    $headers['nonce'] = $forNonce;

   

    $sign = array();

    $data = join("\n", $sign);

    $signatureString = "(request-target): post /api/estimate date: " . strval($forNonce);

    $signature = hash_hmac('sha1', $signatureString, $options['key']);

   

    $final = 'Signature keyId="' . $options['keyId'] . '",algorithm="hmac-sha1"' . ',headers="(request-target) date"' . ',nonce="' . strval($forNonce) . '",signature="' . $signature . '"';

    /*echo "Sample authorization: " . 'Signature keyId="623dc04f515644d89ea9b3944488cd03",algorithm="hmac-sha1",headers="(request-target) date",nonce="1619103273",signature="9da04b2be4de94de02150d3b60ce488c6a30d42f"' . "</br>";

    echo "Sent signatureString: " . $signatureString . "</br>";

    echo "Sent signature: " . $signature . "</br>";

    echo "Sent authorization: " . $final . "</br>";*/ 

    $headers['authorization'] = $final;

    $http_headers = array();

    foreach ($headers as $k => $v) {

        $http_headers[] = "$k: $v";

    }

    $http_headers[] = "Content-Type: application/json";

    $http_headers[] = "X-Api-Key: $apiKey";

    $request = [

        "cpuName" => "2x Intel Xeon Processor E5-2640 v4",

        "gpuName" => "2x AMD Radeon RX 460",

        "cpuOC" => "1",

        "gpuNumber" => "1",

        "gpuType" => "desktop",

        "memchannels" => 2,

        "memfrequency" => 2400 

    ];

    $postdata = json_encode($request);

    $ch = curl_init($fullURLString);

    curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    curl_setopt($ch, CURLOPT_POST, 1);

    $response = curl_exec($ch);

    $err = curl_error($ch);

    if ($err) {

        echo "<p>" . $err . "</p>";    

    }

    echo "<p>" . $response . "</p>";    

    curl_close($ch);

?>

Output looks like the structure below:

{

  "timeSpyScoreGPU": 3436,

  "timeSpyScoreCPU": 6300,

  "timeSpyOverallScore": 3687,

  "gameTitles": {

    "Cyberpunk 2077": {

      "fullHdFps": "35",

      "quadHdFps": "less than 20"

    },

    "Fortnite": {

      "fullHdFps": "145",

      "quadHdFps": "40"

    },

  }

}

The API reference

  1. API Update Date (Not Protected with API Signing)

  2. List Available CPUs

  3. List Available GPUs

  4. List Available Games

  5. Estimate game FPS