Skip to content

Commit

Permalink
Merge pull request #12 from nitrado/Packages
Browse files Browse the repository at this point in the history
changed function calls to PUT / DELETE
  • Loading branch information
BirknerAlex authored Apr 6, 2017
2 parents e86efc6 + a1d991d commit 3972fcc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions lib/Nitrapi/Common/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,54 @@ public function dataGet($url, $headers = null, $options = array()) {
return (isset($json['data'])) ? $json['data'] : $json['message'];
}

/**
* @param $url
* @param array $body
* @param array $headers
* @param array $options
* @return mixed
*/
public function dataPut($url, $body = null, $headers = null, $options = array()) {
try {
if (is_array($body)) {
$options['form_params'] = $body;
}
if (is_array($headers)) {
$options['headers'] = $headers;
}
if (is_array($options) && isset($options['query'])) {
$options['query'] = array_merge($options['query'], $this->defaultQuery);
}

$response = $this->request('PUT', $url, $options);
$this->checkErrors($response);
$json = json_decode($response->getBody(), true);
} catch (RequestException $e) {
if ($e->hasResponse()) {
$response = json_decode($e->getResponse()->getBody(), true);
$msg = isset($response['message']) ? $response['message'] : 'Unknown error';
if ($e->getResponse()->getStatusCode() == 503) {
throw new NitrapiMaintenanceException($msg);
}
if ($e->getResponse()->getStatusCode() == 428) {
throw new NitrapiConcurrencyException($msg);
}
throw new NitrapiHttpErrorException($msg);
}
throw new NitrapiHttpErrorException($e->getMessage());
}

if (isset($json['data']) && is_array($json['data'])) {
return $json['data'];
}

if (!empty($json['message'])) {
return $json['message'];
}

return true;
}

/**
* @param $url
* @param array $body
Expand Down
4 changes: 2 additions & 2 deletions lib/Nitrapi/Services/Gameservers/Packages/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public function install($version) {
}
public function uninstall() {
$url = "/services/".$this->service->getId()."/gameservers/packages/uninstall";
return $this->service->getApi()->dataPost($url, array(
return $this->service->getApi()->dataDelete($url, array(
"package" => $this->name
));
}
public function reinstall() {
$url = "/services/".$this->service->getId()."/gameservers/packages/reinstall";
return $this->service->getApi()->dataPost($url, array(
return $this->service->getApi()->dataPut($url, array(
"package" => $this->name
));
}
Expand Down

0 comments on commit 3972fcc

Please sign in to comment.