Skip to content

Commit d4329d5

Browse files
author
Alexander Birkner
committed
Update Tue Nov 17 17:33:53 CET 2015
1 parent 2ac6d36 commit d4329d5

File tree

13 files changed

+520
-19
lines changed

13 files changed

+520
-19
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
Nitrapi-PHP
22
===========
33

4-
[![Latest Stable Version](https://poser.pugx.org/nitrado/nitrapi-php-lib/v/stable.png)](https://packagist.org/packages/nitrado/nitrapi-php-lib)
5-
[![Latest Unstable Version](https://poser.pugx.org/nitrado/nitrapi-php-lib/v/unstable.svg)](https://packagist.org/packages/nitrado/nitrapi-php-lib)
6-
[![Total Downloads](https://poser.pugx.org/nitrado/nitrapi-php-lib/downloads.png)](https://packagist.org/packages/nitrado/nitrapi-php-lib)
7-
84
PHP based SDK for the Nitrapi RESTful API.
95

106

@@ -43,4 +39,4 @@ try {
4339
} catch(\Exception $e) {
4440
var_dump("API Error: " . $e->getMessage());
4541
}
46-
```
42+
```

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"php" : ">=5.4",
2525
"guzzlehttp/guzzle": "~5.0"
2626
}
27-
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Nitrapi\Common\Exceptions;
4+
5+
class NitrapiConcurrencyException extends NitrapiException
6+
{
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Nitrapi\Common\Exceptions;
4+
5+
class NitrapiMaintenanceException extends NitrapiException
6+
{
7+
}

lib/Nitrapi/Common/Http/Client.php

+20
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
use GuzzleHttp\Client as GuzzleClient;
66
use GuzzleHttp\Exception\RequestException;
77
use GuzzleHttp\Message\Response;
8+
use Nitrapi\Common\Exceptions\NitrapiConcurrencyException;
89
use Nitrapi\Common\Exceptions\NitrapiException;
910
use Nitrapi\Common\Exceptions\NitrapiHttpErrorException;
11+
use Nitrapi\Common\Exceptions\NitrapiMaintenanceException;
1012

1113
class Client extends GuzzleClient
1214
{
@@ -45,6 +47,12 @@ public function dataGet($url, $headers = null, $options = array()) {
4547
if ($e->hasResponse()) {
4648
$response = $e->getResponse()->json();
4749
$msg = isset($response['message']) ? $response['message'] : 'Unknown error';
50+
if ($e->getResponse()->getStatusCode() == 503) {
51+
throw new NitrapiMaintenanceException();
52+
}
53+
if ($e->getResponse()->getStatusCode() == 428) {
54+
throw new NitrapiConcurrencyException();
55+
}
4856
throw new NitrapiHttpErrorException($msg);
4957
}
5058
throw new NitrapiHttpErrorException($e->getMessage());
@@ -77,6 +85,12 @@ public function dataPost($url, $body = null, $headers = null, $options = array()
7785
if ($e->hasResponse()) {
7886
$response = $e->getResponse()->json();
7987
$msg = isset($response['message']) ? $response['message'] : 'Unknown error';
88+
if ($e->getResponse()->getStatusCode() == 503) {
89+
throw new NitrapiMaintenanceException();
90+
}
91+
if ($e->getResponse()->getStatusCode() == 428) {
92+
throw new NitrapiConcurrencyException();
93+
}
8094
throw new NitrapiHttpErrorException($msg);
8195
}
8296
throw new NitrapiHttpErrorException($e->getMessage());
@@ -116,6 +130,12 @@ public function dataDelete($url, $body = null, $headers = null, $options = array
116130
if ($e->hasResponse()) {
117131
$response = $e->getResponse()->json();
118132
$msg = isset($response['message']) ? $response['message'] : 'Unknown error';
133+
if ($e->getResponse()->getStatusCode() == 503) {
134+
throw new NitrapiMaintenanceException();
135+
}
136+
if ($e->getResponse()->getStatusCode() == 428) {
137+
throw new NitrapiConcurrencyException();
138+
}
119139
throw new NitrapiHttpErrorException($msg);
120140
}
121141
throw new NitrapiHttpErrorException($e->getMessage());

lib/Nitrapi/Customer/Customer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(Nitrapi $api, $token) {
2323
*/
2424
public function getUserId() {
2525

26-
return $this->get('id');
26+
return $this->get('user_id');
2727

2828
}
2929

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Nitrapi\Services\Gameservers\ApplicationServer;
4+
5+
use Nitrapi\Common\Exceptions\NitrapiErrorException;
6+
use Nitrapi\Services\Gameservers\Gameserver;
7+
8+
class ApplicationServer
9+
{
10+
/**
11+
* @var Gameserver $service
12+
*/
13+
protected $service;
14+
15+
public function __construct(Gameserver &$service) {
16+
$this->service = $service;
17+
}
18+
19+
/**
20+
* Sends a ping to the application server
21+
*
22+
* @return bool
23+
*/
24+
public function ping() {
25+
try {
26+
$url = "/services/".$this->service->getId()."/gameservers/app_server";
27+
$this->service->getApi()->dataGet($url);
28+
return true;
29+
} catch (\Exception $e) {}
30+
31+
return false;
32+
}
33+
34+
/**
35+
* Sends a command to the app server
36+
*
37+
* @param $command string
38+
* @return bool
39+
*/
40+
public function sendCommand($command) {
41+
$url = "/services/".$this->service->getId()."/gameservers/app_server/command";
42+
$this->service->getApi()->dataPost($url, array(
43+
"command" => $command
44+
));
45+
return true;
46+
}
47+
}

lib/Nitrapi/Services/Gameservers/FileServer/FileServer.php

+13
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ public function deleteFile($file) {
215215
return true;
216216
}
217217

218+
/**
219+
* Gets the file size of the given path
220+
*
221+
* @param $path
222+
* @return int
223+
*/
224+
public function pathSize($path) {
225+
$url = "/services/".$this->service->getId()."/gameservers/file_server/size?path=" . $path;
226+
$result = $this->service->getApi()->dataGet($url);
227+
228+
return (int)$result['size'];
229+
}
230+
218231
/**
219232
* Deletes a directory with content from server
220233
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Nitrapi\Services\Gameservers\Games;
4+
5+
use Nitrapi\Services\Gameservers\Gameserver;
6+
7+
abstract class Game
8+
{
9+
/**
10+
* @var Gameserver
11+
*/
12+
protected $service;
13+
14+
/**
15+
* @var string
16+
*/
17+
protected $game;
18+
19+
public function __construct(Gameserver &$service) {
20+
$this->service = $service;
21+
}
22+
23+
public function getGame() {
24+
return $this->game;
25+
}
26+
27+
/**
28+
* @return mixed
29+
* @throws \Nitrapi\Common\Exceptions\NitrapiHttpErrorException
30+
*/
31+
public function getInfo() {
32+
$url = "services/" . $this->service->getId() . "/gameservers/games/" . $this->getGame();
33+
return $this->service->getApi()->dataGet($url);
34+
}
35+
}

0 commit comments

Comments
 (0)