Skip to content

Instantly share code, notes, and snippets.

@JanrikV
Created August 11, 2020 22:56
Show Gist options
  • Save JanrikV/816d4456a93fa7ffe371fa66099d8175 to your computer and use it in GitHub Desktop.
Save JanrikV/816d4456a93fa7ffe371fa66099d8175 to your computer and use it in GitHub Desktop.
Minero API - Based on coinhive-api class
<?php
/**
* Based on the original coinhive-api class
* https://gist.github.com/coinhive-com/dc37d300b2f4f909006a07139c9d2c71
*
*/
class MineroAPI {
const API_URL = 'https://api.minero.cc';
private $secret = null;
public function __construct($secret) {
if (strlen($secret) !== 32) {
throw new Exception('Minero.cc - Invalid Secret');
}
$this->secret = $secret;
}
function get($path, $data = []) {
$data['secret'] = $this->secret;
$url = self::API_URL.$path.'?'.http_build_query($data);
$response = file_get_contents($url);
return json_decode($response);
}
function post($path, $data = []) {
$data['secret'] = $this->secret;
$context = stream_context_create([
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
]
]);
$url = SELF::API_URL.$path;
$response = file_get_contents($url, false, $context);
return json_decode($response);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment