diff --git a/README.md b/README.md index 5177a04..4ea311c 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,6 @@ if ($response->wasSuccessful()) ); } } - ``` ### Getting your balance @@ -120,3 +119,101 @@ $spryng = new Spryng($apiKey); $balance = $spryng->balance->get()->toObject(); echo "You have " . $balance->getAmount() . " credits remaining\n"; ``` + +## Setting up your Spryng account in laravel + +Add the environment variables to your `config/services.php`: + +```php +// config/services.php +... +'spryng' => [ + 'access_key' => env('SPRYNG_ACCESS_KEY', ''), + 'originator' => env('SPRYNG_ORIGINATOR', ''), + 'recipients' => env('SPRYNG_RECIPIENTS', []), + ], +... +``` + +Add your Spryng Access Key, Default originator (name or number of sender), and default recipients to your `.env`: + +```php +// .env +... +SPRYNG_ACCESS_KEY= +SPRYNG_ORIGINATOR= +SPRYNG_RECIPIENTS= +], +... +``` + +You can create a 'SpryngChannel.php' in 'App/Channels' + +```php +use Illuminate\Notifications\Notification; +use Spryng\SpryngRestApi\Exceptions\ValidationException; +use Spryng\SpryngRestApi\SpryngClient; + +class SpryngChannel +{ + private SpryngClient $client; + + public function __construct(SpryngClient $client) + { + $this->client = $client; + } + + public function send($notifiable, Notification $notification) + { + $config = config('services.spryng'); + + $spryngMessage = $notification->toSpryng($notifiable); + + if (is_string($spryngMessage)) { + $spryngMessageObj = new \Spryng\SpryngRestApi\Objects\Message(); + $spryngMessageObj->setBody($spryngMessage); + $spryngMessage = $spryngMessageObj; + } + + $spryngMessage->setOriginator($config['originator']); + + $data = []; + + if ($to = $notifiable->routeNotificationFor('spryng')) { + $spryngMessage->setRecipients([$to]); + } + + try { + $data = $this->client->send($spryngMessage); + } catch (ValidationException $e) { + logger()->error($e->getMessage()); + } + + return $data; + } +} +``` + +Now you can use the channel in your `via()` method inside the notification: + +``` php +use App\Channels\SpryngChannel; +use Spryng\SpryngRestApi\Objects\Message; +use Illuminate\Notifications\Notification; + +class VpsServerOrdered extends Notification +{ + public function via($notifiable) + { + return [SpryngChannel::class]; + } + + public function toSpryng($notifiable): Message + { + $message = new Message(); + $message->setBody('This is message'); + + return $message; + } +} +``` \ No newline at end of file diff --git a/composer.json b/composer.json index 29a80aa..3663800 100644 --- a/composer.json +++ b/composer.json @@ -23,5 +23,12 @@ "psr-4": { "Spryng\\SpryngRestApi\\": "src/Spryng/SpryngRestApi" } + }, + "extra": { + "laravel": { + "providers": [ + "Spryng\\SpryngRestApi\\SpryngServiceProvider" + ] + } } } diff --git a/src/Spryng/SpryngRestApi/ApiResource.php b/src/Spryng/SpryngRestApi/ApiResource.php index 0127598..e8a0a16 100644 --- a/src/Spryng/SpryngRestApi/ApiResource.php +++ b/src/Spryng/SpryngRestApi/ApiResource.php @@ -10,8 +10,7 @@ class ApiResource public function __construct($raw = null) { - if ($raw !== null) - { + if ($raw !== null) { $this->setRaw($raw); } } @@ -25,7 +24,7 @@ public function getRaw() } /** - * @param mixed $raw + * @param mixed $raw */ public function setRaw($raw) { @@ -33,8 +32,8 @@ public function setRaw($raw) } /** - * @param $raw string|array - * @param $class string + * @param $raw string|array + * @param $class string * @return ApiResource|array */ public static function deserializeFromRaw($raw, $class) @@ -43,8 +42,7 @@ public static function deserializeFromRaw($raw, $class) $json = json_decode($raw, true); // If the data parameter is set, it means that this is a collection of message objects - if (isset($json['data'])) - { + if (isset($json['data'])) { $collection = new MessageCollection(); $collection->setTotal($json['total']); $collection->setPerPage($json['per_page']); @@ -55,9 +53,8 @@ public static function deserializeFromRaw($raw, $class) $collection->setFrom($json['from']); $collection->setTo($json['to']); - $messages = array(); - foreach ($json['data'] as $rawMessage) - { + $messages = []; + foreach ($json['data'] as $rawMessage) { // Call the function recursively to deserialize every message. Serialize back to Json to avoid array/object // conversion issues $messages[] = self::deserializeFromRaw(json_encode($rawMessage), $class); @@ -69,8 +66,7 @@ public static function deserializeFromRaw($raw, $class) // If we've come here, we're deserializing a single message or balance response $obj = new $class; - foreach ($json as $key => $val) - { + foreach ($json as $key => $val) { // Remove underscores from the key that may be present in the response $key = str_replace('_', '', $key); @@ -78,8 +74,7 @@ public static function deserializeFromRaw($raw, $class) $name = 'set'.ucfirst($key); // If there is such a set method, call it - if (method_exists($class, $name)) - { + if (method_exists($class, $name)) { $obj->$name($val); } } diff --git a/src/Spryng/SpryngRestApi/BaseClient.php b/src/Spryng/SpryngRestApi/BaseClient.php index 4e483f5..6266235 100644 --- a/src/Spryng/SpryngRestApi/BaseClient.php +++ b/src/Spryng/SpryngRestApi/BaseClient.php @@ -20,10 +20,10 @@ public function getApi() } /** - * @param mixed $api + * @param mixed $api */ public function setApi($api) { $this->api = $api; } -} \ No newline at end of file +} diff --git a/src/Spryng/SpryngRestApi/Exceptions/InvalidConfiguration.php b/src/Spryng/SpryngRestApi/Exceptions/InvalidConfiguration.php new file mode 100644 index 0000000..55d7bdb --- /dev/null +++ b/src/Spryng/SpryngRestApi/Exceptions/InvalidConfiguration.php @@ -0,0 +1,16 @@ +ch = curl_init(); - if ($req !== null) - { + if ($req !== null) { $this->setActiveRequest($req); } } - public function send(Request $req = null) + public function send(?Request $req = null) { if ($req === null) { if ($this->activeRequest === null) { @@ -48,8 +50,7 @@ public function send(Request $req = null) // Don't print the result curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); - switch ($this->activeRequest->getHttpMethod()) - { + switch ($this->activeRequest->getHttpMethod()) { case self::METHOD_GET: case self::METHOD_DELETE: $this->lastResponse = $this->executeNoData(); @@ -75,6 +76,7 @@ private function executeNoData() $this->applyHeaders(); $rawResponse = curl_exec($this->ch); + return Response::constructFromCurlResponse($this->ch, $rawResponse); } @@ -90,13 +92,13 @@ private function executeWithData() $this->applyHeaders(); $rawResponse = curl_exec($this->ch); + return Response::constructFromCurlResponse($this->ch, $rawResponse); } /** * Sets the current request to be activated to $req * - * @param Request $req * @return HttpClientInterface */ public function setActiveRequest(Request $req) @@ -125,20 +127,19 @@ public function getLastResponse() private function applyHeaders() { // Convert associative array of headers with key and value to single string headers - $headers = array(); + $headers = []; foreach ($this->activeRequest->getHeaders() as $key => $value) { // Apply the user agent header using the CURLOPT_USERAGENT option - if (strtolower($key) === 'user-agent') - { + if (strtolower($key) === 'user-agent') { curl_setopt($this->ch, CURLOPT_USERAGENT, $value); + continue; } $headers[] = sprintf('%s: %s', $key, $value); } // Set converted headers on the curl instance - if (count($headers) > 0) - { + if (count($headers) > 0) { curl_setopt($this->ch, CURLOPT_HEADER, true); curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers); } @@ -159,8 +160,7 @@ private function setUrl() $url = sprintf('%s%s', $this->activeRequest->getBaseUrl(), $this->activeRequest->getMethod()); // If any query string parameters are set, format them and add to the URL. - if (count($this->activeRequest->getQueryStringParameters()) > 0) - { + if (count($this->activeRequest->getQueryStringParameters()) > 0) { $url .= sprintf('?%s', http_build_query($this->activeRequest->getQueryStringParameters())); } @@ -186,4 +186,4 @@ public function getActiveRequest() { return $this->activeRequest; } -} \ No newline at end of file +} diff --git a/src/Spryng/SpryngRestApi/Http/HttpClientInterface.php b/src/Spryng/SpryngRestApi/Http/HttpClientInterface.php index 6944672..0ffa6cc 100644 --- a/src/Spryng/SpryngRestApi/Http/HttpClientInterface.php +++ b/src/Spryng/SpryngRestApi/Http/HttpClientInterface.php @@ -6,22 +6,19 @@ interface HttpClientInterface { /** * HttpClientInterface constructor. - * @param Request|null $req */ - public function __construct(Request $req = null); + public function __construct(?Request $req = null); /** * Executes the currently active request or $req if it is set. * - * @param Request $req * @return Response */ - public function send(Request $req = null); + public function send(?Request $req = null); /** * Sets the current request to be activated to $req * - * @param Request $req * @return HttpClientInterface */ public function setActiveRequest(Request $req); @@ -32,4 +29,4 @@ public function setActiveRequest(Request $req); * @return Response */ public function getLastResponse(); -} \ No newline at end of file +} diff --git a/src/Spryng/SpryngRestApi/Http/Request.php b/src/Spryng/SpryngRestApi/Http/Request.php index 4553648..841ae90 100644 --- a/src/Spryng/SpryngRestApi/Http/Request.php +++ b/src/Spryng/SpryngRestApi/Http/Request.php @@ -2,39 +2,38 @@ namespace Spryng\SpryngRestApi\Http; -use Spryng\SpryngRestApi\Spryng; - class Request { protected $baseUrl; + protected $httpMethod; + protected $method; - protected $headers = array(); - protected $queryStringParameters = array(); - protected $parameters = array(); + + protected $headers = []; + + protected $queryStringParameters = []; + + protected $parameters = []; + protected $client; /** * Request constructor. - * @param $baseUrl - * @param $httpMethod - * @param $method - * @param array $headers - * @param array $queryStringParameters */ - public function __construct($baseUrl, $httpMethod, $method, array $headers = array(), array $queryStringParameters = array()) + public function __construct($baseUrl, $httpMethod, $method, array $headers = [], array $queryStringParameters = []) { - $this->baseUrl = $baseUrl; - $this->httpMethod = $httpMethod; - $this->method = $method; - $this->headers = $headers; - $this->queryStringParameters = $queryStringParameters; - $this->client = new HttpClient($this); + $this->baseUrl = $baseUrl; + $this->httpMethod = $httpMethod; + $this->method = $method; + $this->headers = $headers; + $this->queryStringParameters = $queryStringParameters; + $this->client = new HttpClient($this); } public function withBearerToken($token) { - $this->addheader("Authorization", sprintf("Bearer %s", $token)); + $this->addheader('Authorization', sprintf('Bearer %s', $token)); return $this; } @@ -46,8 +45,7 @@ public function send() public function addParameter($k, $v) { - if (!empty($v)) - { + if (! empty($v)) { $this->parameters[$k] = $v; } @@ -56,8 +54,7 @@ public function addParameter($k, $v) public function addQueryStringParameter($k, $v) { - if (!empty($v)) - { + if (! empty($v)) { $this->queryStringParameters[$k] = $v; } @@ -67,8 +64,8 @@ public function addQueryStringParameter($k, $v) /** * Adds a header to the current header array to be included in the request * - * @param string $name - * @param string|int $value + * @param string $name + * @param string|int $value * @return Request */ public function addheader($name, $value) @@ -135,4 +132,4 @@ public function getParameters() { return $this->parameters; } -} \ No newline at end of file +} diff --git a/src/Spryng/SpryngRestApi/Http/Response.php b/src/Spryng/SpryngRestApi/Http/Response.php index 23f0e7d..934e2e4 100644 --- a/src/Spryng/SpryngRestApi/Http/Response.php +++ b/src/Spryng/SpryngRestApi/Http/Response.php @@ -35,8 +35,6 @@ class Response /** * Constructs a Response instance straight from the raw response of a curl instance, and the instance itself. * - * @param $ch - * @param $rawResponse * @return Response */ public static function constructFromCurlResponse($ch, $rawResponse) @@ -57,7 +55,7 @@ public static function constructFromCurlResponse($ch, $rawResponse) */ public function wasSuccessful() { - return ($this->getResponseCode() >= 200 && $this->getResponseCode() < 300); + return $this->getResponseCode() >= 200 && $this->getResponseCode() < 300; } /** @@ -67,11 +65,11 @@ public function wasSuccessful() */ public function serverError() { - return ($this->getResponseCode() >= 500 && $this->getResponseCode() <= 599); + return $this->getResponseCode() >= 500 && $this->getResponseCode() <= 599; } /** - * @param mixed $curlInstance + * @param mixed $curlInstance */ public function setCurlInstance($curlInstance) { @@ -87,7 +85,7 @@ public function getRawResponse() } /** - * @param mixed $rawResponse + * @param mixed $rawResponse */ public function setRawResponse($rawResponse) { @@ -103,7 +101,7 @@ public function getRawBody() } /** - * @param mixed $rawBody + * @param mixed $rawBody */ public function setRawBody($rawBody) { @@ -121,7 +119,7 @@ public function getResponseCode() } /** - * @param mixed $responseCode + * @param mixed $responseCode */ public function setResponseCode($responseCode) { @@ -137,8 +135,7 @@ public function toObject() { // Wanted to keep this as simple as possible as there are only 2 objects in the API. Just check if the original // url contains 'messages' to know which object to serialize to - if (false !== strpos(curl_getinfo($this->curlInstance, CURLINFO_EFFECTIVE_URL), 'messages')) - { + if (strpos(curl_getinfo($this->curlInstance, CURLINFO_EFFECTIVE_URL), 'messages') !== false) { return ApiResource::deserializeFromRaw($this->getRawBody(), Message::class); } diff --git a/src/Spryng/SpryngRestApi/Objects/Balance.php b/src/Spryng/SpryngRestApi/Objects/Balance.php index b1a445f..d97f378 100644 --- a/src/Spryng/SpryngRestApi/Objects/Balance.php +++ b/src/Spryng/SpryngRestApi/Objects/Balance.php @@ -17,10 +17,10 @@ public function getAmount() } /** - * @param mixed $amount + * @param mixed $amount */ public function setAmount($amount) { $this->amount = $amount; } -} \ No newline at end of file +} diff --git a/src/Spryng/SpryngRestApi/Objects/Message.php b/src/Spryng/SpryngRestApi/Objects/Message.php index 1627d59..1df11a9 100644 --- a/src/Spryng/SpryngRestApi/Objects/Message.php +++ b/src/Spryng/SpryngRestApi/Objects/Message.php @@ -5,19 +5,30 @@ use Spryng\SpryngRestApi\ApiResource; class Message extends ApiResource -{ +{ public $id; + public $encoding = 'plain'; + public $body; + public $reference; + public $credits; + public $scheduledAt; + public $createdAt; + public $updatedAt; - public $links = array(); + + public $links = []; + public $route = 'business'; + public $originator; - public $recipients = array(); + + public $recipients = []; /** * @return mixed @@ -28,7 +39,7 @@ public function getId() } /** - * @param mixed $id + * @param mixed $id */ public function setId($id) { @@ -44,7 +55,7 @@ public function getEncoding() } /** - * @param string $encoding + * @param string $encoding */ public function setEncoding($encoding) { @@ -60,7 +71,7 @@ public function getBody() } /** - * @param mixed $body + * @param mixed $body */ public function setBody($body) { @@ -76,7 +87,7 @@ public function getReference() } /** - * @param mixed $reference + * @param mixed $reference */ public function setReference($reference) { @@ -92,7 +103,7 @@ public function getCredits() } /** - * @param mixed $credits + * @param mixed $credits */ public function setCredits($credits) { @@ -108,7 +119,7 @@ public function getScheduledAt() } /** - * @param mixed $scheduledAt + * @param mixed $scheduledAt */ public function setScheduledAt($scheduledAt) { @@ -124,7 +135,7 @@ public function getCreatedAt() } /** - * @param mixed $createdAt + * @param mixed $createdAt */ public function setCreatedAt($createdAt) { @@ -140,7 +151,7 @@ public function getUpdatedAt() } /** - * @param mixed $updatedAt + * @param mixed $updatedAt */ public function setUpdatedAt($updatedAt) { @@ -156,7 +167,7 @@ public function getLinks() } /** - * @param array $links + * @param array $links */ public function setLinks($links) { @@ -172,7 +183,7 @@ public function getRoute() } /** - * @param string $route + * @param string $route */ public function setRoute($route) { @@ -188,7 +199,7 @@ public function getOriginator() } /** - * @param mixed $originator + * @param mixed $originator */ public function setOriginator($originator) { @@ -204,10 +215,10 @@ public function getRecipients() } /** - * @param array $recipients + * @param array $recipients */ public function setRecipients($recipients) { $this->recipients = $recipients; } -} \ No newline at end of file +} diff --git a/src/Spryng/SpryngRestApi/Objects/MessageCollection.php b/src/Spryng/SpryngRestApi/Objects/MessageCollection.php index 221eb2b..8c0978f 100644 --- a/src/Spryng/SpryngRestApi/Objects/MessageCollection.php +++ b/src/Spryng/SpryngRestApi/Objects/MessageCollection.php @@ -78,7 +78,7 @@ public function getTotal() } /** - * @param int $total + * @param int $total */ public function setTotal($total) { @@ -94,7 +94,7 @@ public function getPerPage() } /** - * @param int $perPage + * @param int $perPage */ public function setPerPage($perPage) { @@ -110,7 +110,7 @@ public function getCurrentPage() } /** - * @param int $currentPage + * @param int $currentPage */ public function setCurrentPage($currentPage) { @@ -126,7 +126,7 @@ public function getLastPage() } /** - * @param int $lastPage + * @param int $lastPage */ public function setLastPage($lastPage) { @@ -142,7 +142,7 @@ public function getNextPageUrl() } /** - * @param string $nextPageUrl + * @param string $nextPageUrl */ public function setNextPageUrl($nextPageUrl) { @@ -158,7 +158,7 @@ public function getPrevPageUrl() } /** - * @param string $prevPageUrl + * @param string $prevPageUrl */ public function setPrevPageUrl($prevPageUrl) { @@ -174,7 +174,7 @@ public function getFrom() } /** - * @param int $from + * @param int $from */ public function setFrom($from) { @@ -190,7 +190,7 @@ public function getTo() } /** - * @param int $to + * @param int $to */ public function setTo($to) { @@ -206,10 +206,10 @@ public function getData() } /** - * @param array $data + * @param array $data */ public function setData($data) { $this->data = $data; } -} \ No newline at end of file +} diff --git a/src/Spryng/SpryngRestApi/Resources/MessageClient.php b/src/Spryng/SpryngRestApi/Resources/MessageClient.php index cfe6fef..2ee8bbb 100644 --- a/src/Spryng/SpryngRestApi/Resources/MessageClient.php +++ b/src/Spryng/SpryngRestApi/Resources/MessageClient.php @@ -2,9 +2,8 @@ namespace Spryng\SpryngRestApi\Resources; -use Spryng\SpryngRestApi\ApiResource; -use Spryng\SpryngRestApi\Exceptions\ValidationException; use Spryng\SpryngRestApi\BaseClient; +use Spryng\SpryngRestApi\Exceptions\ValidationException; use Spryng\SpryngRestApi\Http\HttpClient; use Spryng\SpryngRestApi\Http\Request; use Spryng\SpryngRestApi\Http\Response; @@ -15,7 +14,7 @@ class MessageClient extends BaseClient { /** * An array of the existing filters for the list endpoint - * + * * @var string[] */ private static $listFilters = [ @@ -26,7 +25,7 @@ class MessageClient extends BaseClient 'created_until', 'scheduled_from', 'scheduled_until', - 'status' + 'status', ]; public function create(Message $message) @@ -54,9 +53,9 @@ public function create(Message $message) /** * List existing message instances. Use $filters to filter the results * - * @param string[] $filters Filters to limit the results - * + * @param string[] $filters Filters to limit the results * @return Response|null + * * @throws ValidationException */ public function list($filters = []) @@ -71,7 +70,7 @@ public function list($filters = []) // Add the filters as query string parameters foreach ($filters as $filter => $value) { // check if this filter actually exists - if (!in_array($filter, self::$listFilters)) { + if (! in_array($filter, self::$listFilters)) { throw new ValidationException(sprintf('%s is not a valid filter', $filter)); } @@ -80,20 +79,19 @@ public function list($filters = []) return $req->send(); } - + /** * Cancel a message scheduled in the future. * - * @param string|Message $id The ID of the message to be canceled - * + * @param string|Message $id The ID of the message to be canceled * @return Response */ public function cancel($id) { - if ($id instanceof Message) // also allow message instances - { + if ($id instanceof Message) { // also allow message instances $id = $id->getId(); } + return (new Request( $this->api->getBaseUrl(), HttpClient::METHOD_POST, @@ -114,8 +112,7 @@ public function send(Message $message) /** * Show the message with $id * - * @param $id The ID of the message to retrieve - * + * @param $id The ID of the message to retrieve * @return Spryng\SpryngRestApi\Http\Response */ public function show($id) @@ -132,7 +129,7 @@ public function show($id) /** * @deprecated 1.10 Use list() */ - public function showAll($page = 1, $limit = 15, $filters = array()) + public function showAll($page = 1, $limit = 15, $filters = []) { return $this->list($filters); } diff --git a/src/Spryng/SpryngRestApi/Spryng.php b/src/Spryng/SpryngRestApi/Spryng.php index d3556b8..6218618 100644 --- a/src/Spryng/SpryngRestApi/Spryng.php +++ b/src/Spryng/SpryngRestApi/Spryng.php @@ -8,28 +8,21 @@ class Spryng { - const VERSION = '1.0.0'; + public const VERSION = '1.0.0'; - protected $baseUrl = 'https://rest.spryngsms.com/v1'; + private string $baseUrl = 'https://rest.spryngsms.com/v1'; - /** - * @var MessageClient - */ - public $message; + public MessageClient $message; - /** - * @var BalanceClient - */ - public $balance; + public BalanceClient $balance; - public static $http; + public static HttpClient $http; - protected $apiKey; + protected string $apiKey = ''; - public function __construct($apiKey = null) + public function __construct(?string $apiKey = '') { - if ($apiKey !== null) - { + if ($apiKey !== null) { $this->setApiKey($apiKey); } @@ -48,27 +41,22 @@ public function getApiKey() } /** - * @param mixed $apiKey + * @param mixed $apiKey */ - public function setApiKey($apiKey) + public function setApiKey($apiKey): void { $this->apiKey = $apiKey; } - /** - * @return string - */ - public function getBaseUrl() + public function getBaseUrl(): string { return $this->baseUrl; } /** * Get the current version of the library - * - * @return string */ - public function getVersion() + public function getVersion(): string { return self::VERSION; } diff --git a/src/Spryng/SpryngRestApi/SpryngClient.php b/src/Spryng/SpryngRestApi/SpryngClient.php new file mode 100644 index 0000000..abd315a --- /dev/null +++ b/src/Spryng/SpryngRestApi/SpryngClient.php @@ -0,0 +1,39 @@ +api->getApiKey()) + ->post($this->api->getBaseUrl().'/messages', [ + 'encoding' => $message->getEncoding(), + 'body' => $message->getBody(), + 'route' => $message->getRoute(), + 'originator' => $message->getOriginator(), + 'recipients' => $message->getRecipients(), + 'reference' => $message->getReference(), + 'scheduled_at' => $message->getScheduledAt(), + ]); + + if ($response->successful()) { + return $response->json(); + } else { + throw new ValidationException($response->body(), $response->status()); + } + } catch (ValidationException $e) { + // Handle exception + throw new ValidationException($e->getMessage()); + } + + } +} diff --git a/src/Spryng/SpryngRestApi/SpryngServiceProvider.php b/src/Spryng/SpryngRestApi/SpryngServiceProvider.php new file mode 100644 index 0000000..2dcf75d --- /dev/null +++ b/src/Spryng/SpryngRestApi/SpryngServiceProvider.php @@ -0,0 +1,27 @@ +app->when(Spryng::class) + ->give(function () { + $config = config('services.spryng'); + + if (is_null($config)) { + throw InvalidConfiguration::configurationNotSet(); + } + + return new MessageClient(new Spryng(), $config['access_key']); + }); + } +} diff --git a/src/Spryng/SpryngRestApi/Utils.php b/src/Spryng/SpryngRestApi/Utils.php index 6d6cd7d..2a9d81d 100644 --- a/src/Spryng/SpryngRestApi/Utils.php +++ b/src/Spryng/SpryngRestApi/Utils.php @@ -5,22 +5,21 @@ use Spryng\SpryngRestApi\Exceptions\ValidationException; class Utils -{ +{ /** * Checks if $expected equals $actual. If not, throws an exception * - * @param mixed $expected The expected value - * @param mixed $actual The actual value - * + * @param mixed $expected The expected value + * @param mixed $actual The actual value * @return void */ public static function assert($expected, $actual = null) { - if ($actual === null && !$expected) { + if ($actual === null && ! $expected) { throw new ValidationException('\'%s\' cannot be null', $expected); } - if (!$expected || $actual !== null && $expected !== $actual) { + if (! $expected || $actual !== null && $expected !== $actual) { throw new ValidationException(sprintf('Assertion failed. Got \'%s\' but expected \'%s\'.', $actual, $expected)); } } -} \ No newline at end of file +} diff --git a/test/BalanceTest.php b/test/BalanceTest.php index 9be88a3..85f7bd5 100644 --- a/test/BalanceTest.php +++ b/test/BalanceTest.php @@ -6,12 +6,14 @@ use Spryng\SpryngRestApi\Spryng; date_default_timezone_set('Europe/Amsterdam'); -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; class BalanceTest extends TestCase { protected $API_KEY; + protected $RECIPIENT = ['']; + protected $messageId = ''; /** @@ -22,7 +24,7 @@ class BalanceTest extends TestCase public function setUp() { parent::setUp(); - $this->API_KEY = file_get_contents(__DIR__ . '/../.apikey'); + $this->API_KEY = file_get_contents(__DIR__.'/../.apikey'); $this->instance = new Spryng($this->API_KEY); } diff --git a/test/HttpClientTest.php b/test/HttpClientTest.php index b8d09f4..12fb227 100644 --- a/test/HttpClientTest.php +++ b/test/HttpClientTest.php @@ -7,7 +7,7 @@ use Spryng\SpryngRestApi\Http\Request; date_default_timezone_set('Europe/Amsterdam'); -require_once __DIR__ .'/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; class HttpClientTest extends TestCase { @@ -39,4 +39,4 @@ public function testSetUrl() $this->assertEquals('https://example.com/create?key1=value1&key2=value2', $info['url']); } -} \ No newline at end of file +} diff --git a/test/MessageTest.php b/test/MessageTest.php index b26a35f..2090905 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -8,12 +8,14 @@ use Spryng\SpryngRestApi\Spryng; date_default_timezone_set('Europe/Amsterdam'); -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; class MessageTest extends TestCase { protected $API_KEY; + protected $RECIPIENT = ['']; + protected $messageId = '90797ce7-a20d-434a-9c00-553e31d9ce03'; /** @@ -24,7 +26,7 @@ class MessageTest extends TestCase public function setUp() { parent::setUp(); - $this->API_KEY = file_get_contents(__DIR__ . '/../.apikey'); + $this->API_KEY = file_get_contents(__DIR__.'/../.apikey'); $this->instance = new Spryng($this->API_KEY); } @@ -89,10 +91,8 @@ public function testShowAll() $this->assertTrue($response->wasSuccessful()); $obj = $response->toObject(); // Check if the response is correctly parsed to objects for all the messages - if (count($obj->getData()) > 0) - { - foreach ($obj->getData() as $message) - { + if (count($obj->getData()) > 0) { + foreach ($obj->getData() as $message) { $this->assertNotNull($message->getId()); } }