Skip to content

Commit

Permalink
Throw an exception if the OhDear credentials have not been provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Siewertsen committed Apr 26, 2020
1 parent ea6d1df commit 70d47d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Exceptions/OhDearCredentialsNotProvidedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Jonassiewertsen\OhDear\Exceptions;

use Exception;

class OhDearCredentialsNotProvidedException extends Exception
{

}
11 changes: 11 additions & 0 deletions src/OhDear.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Jonassiewertsen\OhDear;

use Illuminate\Support\Carbon;
use Jonassiewertsen\OhDear\Exceptions\OhDearCredentialsNotProvidedException;
use OhDear\PhpSdk\OhDear as OhDearSDK;

class OhDear {
Expand All @@ -20,7 +21,17 @@ class OhDear {
*/
public $site;

/**
* Instanciate OhDear
* @throws OhDearCredentialsNotProvidedException
*/
public function __construct() {
// Throw an exception, in case the API key or site id have not been provided
// In case you do wonder: They should be in your .env file
if (config('oh-dear.api_key') === null || config('oh-dear.site_id') === null) {
throw new OhDearCredentialsNotProvidedException;
}

try {
$this->ohDear = new OhDearSDK(config('oh-dear.api_key'));
$this->site = $this->ohDear->site(config('oh-dear.site_id'));
Expand Down

0 comments on commit 70d47d8

Please sign in to comment.