Skip to content

Commit

Permalink
Merge pull request #1 from Comp-MC/main
Browse files Browse the repository at this point in the history
merge changes from 17 updates to comp-mc
  • Loading branch information
dutchie027 committed Apr 30, 2021
2 parents 48bc051 + 64facf1 commit d8762fb
Show file tree
Hide file tree
Showing 28 changed files with 350 additions and 658 deletions.
11 changes: 11 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# vultr-php

[![Latest Stable Version](https://poser.pugx.org/dutchie027/vultr/v)](//packagist.org/packages/dutchie027/vultr)
[![Total Downloads](https://poser.pugx.org/dutchie027/vultr/downloads)](//packagist.org/packages/dutchie027/vultr)
[![License](https://poser.pugx.org/dutchie027/vultr/license)](//packagist.org/packages/dutchie027/vultr)
[![CodeFactor](https://www.codefactor.io/repository/github/dutchie027/vultr-php/badge)](https://www.codefactor.io/repository/github/dutchie027/vultr-php)

PHP Library Intended to Interact with [Vultr's v2 API](https://www.vultr.com/api/v2)
There are a few other PHP libraries out that do similar things, but I wasn't happy that they were very monolithic and also they used cURL and not Guzzle. Further, there was no logging in any of the libraries, so I wrote this one.

## Installation
```php
composer require dutchie027/vultr
composer require comp-mc/vultr
```

## Usage
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "dutchie027/vultr",
"description": "Vultr PHP API Wrapper",
"name": "comp-mc/vultr",
"description": "Vultr PHP API Wrapper by dutchie027. Forked.",
"keywords": ["php", "automation", "Vultr", "paas", "headless", "server administration"],
"type": "library",
"require": {
"monolog/monolog": "^2.2",
"guzzlehttp/guzzle": "^7.2",
"aws/aws-sdk-php": "^3.171"
"aws/aws-sdk-php": "^3.171",
"ext-json": "*"
},
"autoload": {
"psr-4": {
Expand Down
32 changes: 17 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 25 additions & 23 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace dutchie027\Vultr;

use dutchie027\Vultr\Exceptions\VultrAPIRequestException;
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\RequestException;
Expand Down Expand Up @@ -336,7 +337,7 @@ private function getAPIToken()
* @return object
*
*/
public function account()
public function account(): Account
{
$account = new Account($this);
return $account;
Expand All @@ -350,7 +351,7 @@ public function account()
* @return object
*
*/
public function applications()
public function applications(): Applications
{
$ap = new Applications($this);
return $ap;
Expand All @@ -364,7 +365,7 @@ public function applications()
* @return object
*
*/
public function backups()
public function backups(): Backups
{
$bu = new Backups($this);
return $bu;
Expand All @@ -378,7 +379,7 @@ public function backups()
* @return object
*
*/
public function bareMetal()
public function bareMetal(): BareMetal
{
$bm = new BareMetal($this);
return $bm;
Expand All @@ -392,7 +393,7 @@ public function bareMetal()
* @return object
*
*/
public function blockStorage()
public function blockStorage(): BlockStorage
{
$bs = new BlockStorage($this);
return $bs;
Expand All @@ -406,7 +407,7 @@ public function blockStorage()
* @return object
*
*/
public function dns()
public function dns(): DNS
{
$dns = new DNS($this);
return $dns;
Expand All @@ -420,7 +421,7 @@ public function dns()
* @return object
*
*/
public function firewalls()
public function firewalls(): Firewalls
{
$fw = new Firewalls($this);
return $fw;
Expand All @@ -434,7 +435,7 @@ public function firewalls()
* @return object
*
*/
public function instances()
public function instances(): Instances
{
$instances = new Instances($this);
return $instances;
Expand All @@ -448,7 +449,7 @@ public function instances()
* @return object
*
*/
public function iso()
public function iso(): ISO
{
$iso = new ISO($this);
return $iso;
Expand All @@ -462,7 +463,7 @@ public function iso()
* @return object
*
*/
public function loadBalancers()
public function loadBalancers(): LoadBalancers
{
$lb = new LoadBalancers($this);
return $lb;
Expand All @@ -476,7 +477,7 @@ public function loadBalancers()
* @return object
*
*/
public function objectStorage()
public function objectStorage(): ObjectStorage
{
$os = new ObjectStorage($this);
return $os;
Expand All @@ -490,7 +491,7 @@ public function objectStorage()
* @return object
*
*/
public function operatingSystems()
public function operatingSystems(): OperatingSystems
{
$os = new OperatingSystems($this);
return $os;
Expand All @@ -504,7 +505,7 @@ public function operatingSystems()
* @return object
*
*/
public function plans()
public function plans(): Plans
{
$plans = new Plans($this);
return $plans;
Expand All @@ -518,7 +519,7 @@ public function plans()
* @return object
*
*/
public function privateNetworks()
public function privateNetworks(): PrivateNetworks
{
$pn = new PrivateNetworks($this);
return $pn;
Expand All @@ -532,7 +533,7 @@ public function privateNetworks()
* @return object
*
*/
public function regions()
public function regions(): Regions
{
$regions = new Regions($this);
return $regions;
Expand All @@ -546,7 +547,7 @@ public function regions()
* @return object
*
*/
public function reservedIPs()
public function reservedIPs(): ReservedIPs
{
$rip = new ReservedIPs($this);
return $rip;
Expand All @@ -560,7 +561,7 @@ public function reservedIPs()
* @return object
*
*/
public function snapshots()
public function snapshots(): Snapshots
{
$snap = new Snapshots($this);
return $snap;
Expand All @@ -574,7 +575,7 @@ public function snapshots()
* @return object
*
*/
public function sshKeys()
public function sshKeys(): SSHKeys
{
$ssh = new SSHKeys($this);
return $ssh;
Expand All @@ -588,7 +589,7 @@ public function sshKeys()
* @return object
*
*/
public function startupScripts()
public function startupScripts(): StartupScripts
{
$ss = new StartupScripts($this);
return $ss;
Expand All @@ -602,7 +603,7 @@ public function startupScripts()
* @return object
*
*/
public function users()
public function users(): Users
{
$users = new Users($this);
return $users;
Expand Down Expand Up @@ -682,8 +683,8 @@ public function pGenRandomString($length = 6)
* @param $url string endpoint
* @param $body string - usually passed as JSON
*
* @return string Body Object
* @throws string error message
* @return Psr7\Stream Object
* @throws VultrAPIRequestException Exception with details regarding the failed request
*
*/
public function makeAPICall($type, $url, $body = null)
Expand All @@ -697,8 +698,9 @@ public function makeAPICall($type, $url, $body = null)
if ($e->hasResponse()) {
$response = $e->getResponse();
$ja = json_decode($response->getBody()->getContents(), true);
print $ja['error'];
throw new VultrAPIRequestException('An error occurred while performing the request to ' . $url . ' -> ' . (isset($ja['error']) ? $ja['error'] : json_encode($ja)));
}
throw new VultrAPIRequestException(('An unknown error ocurred while performing the request to ' . $url));
}
}
}
1 change: 0 additions & 1 deletion src/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function __construct(API $api)
* getAccountInfo
* Gets account info
*
*
* @return string
*
*/
Expand Down
30 changes: 0 additions & 30 deletions src/Applications.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,36 +107,6 @@ public function loadApplications()
$this->app_count = $apps['meta']['total'];
}

/**
* printNames
* Prints Names and IDs to stdout
*
*
* @return void
*
*/
public function printNames()
{
foreach ($this->ids as $id) {
print $this->deploy_names[$id] . " ($id)" . PHP_EOL;
}
}

/**
* listIds
* Prints Instance IDs to stdout
*
*
* @return void
*
*/
public function listIds()
{
foreach ($this->ids as $id) {
print $id . PHP_EOL;
}
}

/**
* getNumberOfApplications
* Returns total number of applications
Expand Down
Loading

0 comments on commit d8762fb

Please sign in to comment.