Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from SamuelMwangiW/readme
Browse files Browse the repository at this point in the history
Update Docs
  • Loading branch information
SamuelMwangiW authored Sep 23, 2022
2 parents a1f1e62 + 69f4d9e commit ffddf00
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 7 deletions.
85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/samuelmwangiw/linode.svg?style=flat-square)](https://packagist.org/packages/samuelmwangiw/linode)
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/samuelmwangiw/linode/run-tests?label=tests)](https://github.com/samuelmwangiw/linode/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/samuelmwangiw/linode/Check%20&%20fix%20styling?label=code%20style)](https://github.com/samuelmwangiw/linode/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[![PHPStan](https://github.com/SamuelMwangiW/linode/actions/workflows/phpstan.yml/badge.svg)](https://github.com/SamuelMwangiW/linode/actions/workflows/phpstan.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/samuelmwangiw/linode.svg?style=flat-square)](https://packagist.org/packages/samuelmwangiw/linode)

---
A Simple Linode client built for Laravel with @JustSteveKing laravel-transporter package
A Simple Linode client built for Laravel.

---

Expand Down Expand Up @@ -33,13 +34,95 @@ This is the contents of the published config file:

```php
return [
'endpoint' => env('LINODE_API_ENDPOINT', 'https://api.linode.com/v4/'),
'token' => env('LINODE_PERSONAL_ACCESS_TOKEN'),
];
```

## Usage

@todo.

```php
use SamuelMwangiW\Linode\Linode;

// Get your account details
Linode::account();

// List created Firewalls
Linode::firewall()->list();

// Get a Firewall rule
Linode::firewall()->show(123456);

// Delete a Firewall and its rules
Linode::firewall()->destroy(123456);

// Get all rules attached to a Firewall
Linode::firewall()->rules()->show(123456);

// Get available images
Linode::images()->list();

$image = [
'disk_id' => 67890123,
'label' => 'backup_disk',
'description' => 'Created in tests, delete',
];

// Create image from disk
Linode::images()->create($disk);

// show an image
Linode::images()->show(12345678);

// Delete a user created image
Linode::images()->destroy(12345678);

// List of available instances
Linode::instance()->list();

// Get an instance details
Linode::instance()->show(654321);

// Get list of disks attached to an instance
Linode::instance()->disks(654321);

$instance = [
'authorized_keys' => ['ssh-rsa yourverysecuresshpublickeywhoseprivatekeywillneverbeleakedontheinternetandfileperssionsarepermanentlysetto0600='],
'authorized_users' => ['unicorn'],
'region' => 'eu-west',
'image' => 'linode/ubuntu22.04',
'private_ip' => true,
'label' => 'unicorn-worker-42',
'root_pass' => fake()->password(),
'type' => 'g6-nanode-1',
'watchdog_enabled' => true,
'tags' => ['workers', 'to-the-moon'],
];

// Create a linode instance
Linode::instance()->create($instance);

// Update an instance details
Linode::instance()
->update(654321, ['label'=> 'mars-rover','tags'=>['mars-colony']]);

// Clone a Linode instance
Linode::instance()
->clone(654321,['label'=>'mars-rover-02','tags'=>['test']]);

// Nuke 💣 an instance
Linode::instance()->destroy(654321);

// Shutdown an instance
Linode::instance()->shutdown(654321);

// List available Linode plans
Linode::billing()->plans();

// List of available regions
Linode::region()->list();
```

## Testing
Expand Down
7 changes: 7 additions & 0 deletions src/Domain/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

class Account
{
/**
* @return AccountDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public static function details(): AccountDTO
{
$response = GetRequest::make()
Expand Down
11 changes: 10 additions & 1 deletion src/Domain/Billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

namespace SamuelMwangiW\Linode\Domain;

use Illuminate\Support\Collection;
use SamuelMwangiW\Linode\DTO\PlanDTO;
use SamuelMwangiW\Linode\Factory\PlanFactory;
use SamuelMwangiW\Linode\Saloon\Requests\Billing\PlansListRequest;

class Billing
{
public function plans()
/**
* @return Collection<PlanDTO>
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function plans(): Collection
{
return PlansListRequest::make()
->send()
Expand Down
34 changes: 34 additions & 0 deletions src/Domain/Firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@

class Firewall
{
/**
* @return FirewallRule
*/
public function rules(): FirewallRule
{
return new FirewallRule();
}

/**
* @return Collection<FirewallDTO>
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function list(): Collection
{
return ListRequest::make()
Expand All @@ -29,6 +39,14 @@ public function list(): Collection
->map(fn (array $firewall) => FirewallFactory::make($firewall));
}

/**
* @param $firewallId
* @return FirewallDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function show($firewallId): FirewallDTO
{
return FirewallFactory::make(
Expand All @@ -39,6 +57,14 @@ public function show($firewallId): FirewallDTO
);
}

/**
* @param $data
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function create($data)
{
CreateRequest::make($data)
Expand All @@ -47,6 +73,14 @@ public function create($data)
->collect()->dd();
}

/**
* @param $firewallId
* @return SaloonResponse
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function destroy($firewallId): SaloonResponse
{
return DeleteRequest::make($firewallId)
Expand Down
8 changes: 8 additions & 0 deletions src/Domain/FirewallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

class FirewallRule
{
/**
* @param $firewallId
* @return FirewallRulesDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function show($firewallId): FirewallRulesDTO
{
return FirewallRulesFactory::make(
Expand Down
29 changes: 26 additions & 3 deletions src/Domain/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
namespace SamuelMwangiW\Linode\Domain;

use Illuminate\Support\Collection;
use SamuelMwangiW\Linode\Contracts\DTOContract;
use SamuelMwangiW\Linode\DTO\ImageDTO;
use SamuelMwangiW\Linode\Factory\ImageFactory;
use SamuelMwangiW\Linode\Saloon\Requests\Images\CreateRequest;
use SamuelMwangiW\Linode\Saloon\Requests\Images\ListRequest;
use SamuelMwangiW\Linode\Saloon\Requests\Images\ShowRequest;

class Image
{
/**
* @return Collection<ImageDTO>
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function list(): Collection
{
return ListRequest::make()
Expand All @@ -22,7 +29,15 @@ public function list(): Collection
->map(fn (array $image) => ImageFactory::make($image));
}

public function create(array $data): DTOContract
/**
* @param array $data
* @return ImageDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function create(array $data): ImageDTO
{
$image = CreateRequest::make($data)
->send()
Expand All @@ -32,7 +47,15 @@ public function create(array $data): DTOContract
return ImageFactory::make($image);
}

public function show(string $id): DTOContract
/**
* @param string $id
* @return ImageDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
*/
public function show(string $id): ImageDTO
{
$image = ShowRequest::make($id)
->send()
Expand Down
Loading

0 comments on commit ffddf00

Please sign in to comment.