Skip to content

Commit 9463966

Browse files
committed
class filename fix
1 parent d781843 commit 9463966

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
BuyVM Stallion API (PHP)
22
========================
33

4+
[![Build Status](https://travis-ci.org/splitice/buyvm-stallion-api.svg?branch=master)](https://travis-ci.org/splitice/buyvm-stallion-api)
5+
46
This is a PHP5 wrapper to easily integrate with BuyVM's Stallion control panel API.
57

68
Developed for use at http://www.x4b.net
@@ -49,3 +51,10 @@ $client = new ApiClient('KEY', 'HASH');
4951
$api = new BuyVMApi($client);
5052
$api->rdns('1.1.1.1', 'rdns-ptr');
5153
```
54+
55+
### Get VPS information
56+
```
57+
$client = new ApiClient('KEY', 'HASH');
58+
$api = new BuyVMApi($client);
59+
$memory = $api->get('mem');
60+
```
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
namespace Splitice\BuyVM;
3+
4+
/**
5+
* Stallion 'SolusVM like' API client
6+
* @package Splitice\BuyVM
7+
*/
8+
class BuyVMApiClient implements IBuyVMApiClient
9+
{
10+
const URL = "https://manage.buyvm.net/api/client/command.php";
11+
private $ch;
12+
private $key;
13+
private $hash;
14+
15+
function __construct($key, $hash, $url = self::URL){
16+
$this->key = $key;
17+
$this->hash = $hash;
18+
19+
//Setup curl
20+
$this->ch = curl_init($url);
21+
curl_setopt($this->ch, CURLOPT_POST, true);
22+
curl_setopt($this->ch, CURLOPT_TIMEOUT, 30);
23+
curl_setopt($this->ch, CURLOPT_FRESH_CONNECT, 1);
24+
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
25+
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
26+
curl_setopt($this->ch, CURLOPT_HEADER, 0);
27+
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
28+
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('Expect:'));
29+
}
30+
31+
function __destruct(){
32+
curl_close($this->ch);
33+
}
34+
35+
private function execute($post){
36+
//Set authentication
37+
$post['key'] = $this->key;
38+
$post['hash'] = $this->hash;
39+
40+
//set post data
41+
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
42+
43+
//Execute request
44+
$data = curl_exec($this->ch);
45+
$code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
46+
47+
//Handle response
48+
if($code == 200){
49+
preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $match);
50+
$result = array();
51+
52+
foreach ($match[1] as $x => $y) {
53+
$result[$y] = $match[2][$x];
54+
}
55+
56+
return $result;
57+
}else{
58+
throw new ApiTransportException($code);
59+
}
60+
}
61+
62+
function execute_action($action, $data = array()){
63+
$data['action'] = $action;
64+
return $this->execute($data);
65+
}
66+
67+
function execute_info($fields){
68+
$post = array();
69+
foreach($fields as $f){
70+
$post[$f] = 'true';
71+
}
72+
return $this->execute($post);
73+
}
74+
}

0 commit comments

Comments
 (0)