Skip to content

Commit f83ef9b

Browse files
author
CryptAPI
committed
added info endpoint
1 parent 78be204 commit f83ef9b

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

cryptapi/cryptapi.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Exception;
55

66
class CryptAPI {
7-
private $base_url = "https://cryptapi.io/api";
7+
private static $base_url = "https://cryptapi.io/api";
88
private $valid_coins = ['btc', 'bch', 'eth', 'ltc', 'xmr', 'iota'];
99
private $own_address = null;
1010
private $callback_url = null;
@@ -52,7 +52,7 @@ public function get_address() {
5252
'pending' => $this->pending,
5353
];
5454

55-
$response = $this->_request('create', $ca_params);
55+
$response = CryptAPI::_request($this->coin, 'create', $ca_params);
5656

5757
if ($response->status == 'success') {
5858
return $response->address_in;
@@ -69,7 +69,17 @@ public function check_logs() {
6969
'callback' => $this->callback_url,
7070
];
7171

72-
$response = $this->_request('logs', $params);
72+
$response = CryptAPI::_request($this->coin, 'logs', $params);
73+
74+
if ($response->status == 'success') {
75+
return $response;
76+
}
77+
78+
return null;
79+
}
80+
81+
public static function get_info($coin) {
82+
$response = CryptAPI::_request($coin, 'info');
7383

7484
if ($response->status == 'success') {
7585
return $response;
@@ -90,7 +100,7 @@ public static function process_callback($_get, $convert=false) {
90100
'coin' => $_get['coin'],
91101
'pending' => isset($_get['pending']) ? $_get['pending'] : false,
92102
];
93-
103+
94104
foreach ($_get as $k => $v) {
95105
if (isset($params[$k])) continue;
96106
$params[$k] = $_get[$k];
@@ -103,10 +113,15 @@ public static function convert($val, $coin) {
103113
return $val / Cryptapi::$COIN_MULTIPLIERS[$coin];
104114
}
105115

106-
private function _request($endpoint, $params) {
116+
private static function _request($coin, $endpoint, $params=[]) {
117+
118+
$base_url = Cryptapi::$base_url;
119+
120+
if (!empty($params)) $data = http_build_query($params);
121+
122+
$url = "{$base_url}/{$coin}/{$endpoint}/";
107123

108-
$data = http_build_query($params);
109-
$url = "{$this->base_url}/{$this->coin}/{$endpoint}/?{$data}";
124+
if (!empty($data)) $url .= "?{$data}";
110125

111126
$ch = curl_init();
112127
curl_setopt($ch, CURLOPT_URL, $url);

0 commit comments

Comments
 (0)