Skip to content

Commit a1d991d

Browse files
committed
changed function calls to PUT / DELETE
1 parent 48c8b92 commit a1d991d

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

lib/Nitrapi/Common/Http/Client.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,54 @@ public function dataGet($url, $headers = null, $options = array()) {
6767
return (isset($json['data'])) ? $json['data'] : $json['message'];
6868
}
6969

70+
/**
71+
* @param $url
72+
* @param array $body
73+
* @param array $headers
74+
* @param array $options
75+
* @return mixed
76+
*/
77+
public function dataPut($url, $body = null, $headers = null, $options = array()) {
78+
try {
79+
if (is_array($body)) {
80+
$options['form_params'] = $body;
81+
}
82+
if (is_array($headers)) {
83+
$options['headers'] = $headers;
84+
}
85+
if (is_array($options) && isset($options['query'])) {
86+
$options['query'] = array_merge($options['query'], $this->defaultQuery);
87+
}
88+
89+
$response = $this->request('PUT', $url, $options);
90+
$this->checkErrors($response);
91+
$json = json_decode($response->getBody(), true);
92+
} catch (RequestException $e) {
93+
if ($e->hasResponse()) {
94+
$response = json_decode($e->getResponse()->getBody(), true);
95+
$msg = isset($response['message']) ? $response['message'] : 'Unknown error';
96+
if ($e->getResponse()->getStatusCode() == 503) {
97+
throw new NitrapiMaintenanceException($msg);
98+
}
99+
if ($e->getResponse()->getStatusCode() == 428) {
100+
throw new NitrapiConcurrencyException($msg);
101+
}
102+
throw new NitrapiHttpErrorException($msg);
103+
}
104+
throw new NitrapiHttpErrorException($e->getMessage());
105+
}
106+
107+
if (isset($json['data']) && is_array($json['data'])) {
108+
return $json['data'];
109+
}
110+
111+
if (!empty($json['message'])) {
112+
return $json['message'];
113+
}
114+
115+
return true;
116+
}
117+
70118
/**
71119
* @param $url
72120
* @param array $body

lib/Nitrapi/Services/Gameservers/Packages/Package.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public function install($version) {
5555
}
5656
public function uninstall() {
5757
$url = "/services/".$this->service->getId()."/gameservers/packages/uninstall";
58-
return $this->service->getApi()->dataPost($url, array(
58+
return $this->service->getApi()->dataDelete($url, array(
5959
"package" => $this->name
6060
));
6161
}
6262
public function reinstall() {
6363
$url = "/services/".$this->service->getId()."/gameservers/packages/reinstall";
64-
return $this->service->getApi()->dataPost($url, array(
64+
return $this->service->getApi()->dataPut($url, array(
6565
"package" => $this->name
6666
));
6767
}

0 commit comments

Comments
 (0)