Skip to content

Commit

Permalink
Merge pull request #1 from Norris1z/master
Browse files Browse the repository at this point in the history
Updating my fork with changes
  • Loading branch information
hinimajesty authored Dec 11, 2020
2 parents 48f5a1c + 67310bd commit 61a45e4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 33 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Hubtel notification channel for Laravel 5.3+

[![Latest Stable Version](https://poser.pugx.org/norris1z/hubtel-laravel-sms-channel/v/stable)](https://packagist.org/packages/norris1z/hubtel-laravel-sms-channel)
[![Total Downloads](https://poser.pugx.org/norris1z/hubtel-laravel-sms-channel/downloads)](https://packagist.org/packages/norris1z/hubtel-laravel-sms-channel)
[![License](https://poser.pugx.org/norris1z/hubtel-laravel-sms-channel/license)](https://packagist.org/packages/norris1z/hubtel-laravel-sms-channel)

This package makes it easy to send notifications using [Hubtel](https://hubtel.com) with Laravel 5.3+.
Expand All @@ -21,7 +22,7 @@ This package makes it easy to send notifications using [Hubtel](https://hubtel.c

## Installation

To get the latest version of Pushbullet Notification channel for Laravel 5.3+, simply require the project using [Composer](https://getcomposer.org):
To get the latest version of Hubtel Notification channel for Laravel 5.3+, simply require the project using [Composer](https://getcomposer.org):

```bash
$ composer require norris1z/hubtel-laravel-sms-channel
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
}
],
"require": {
"php": ">=5.6.4",
"guzzlehttp/guzzle": "^6.3",
"illuminate/notifications": "5.3.*|5.4.*|5.5.*|5.6.*",
"illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*"
"php": ">=7.2",
"guzzlehttp/guzzle": "^7.2",
"illuminate/notifications": "5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*",
"illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*"
},
"require-dev": {
"mockery/mockery": "^0.9.5",
"phpunit/phpunit": "4.*"
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public static function apiSecretNotSet()
{
return new static ('Hubtel API secret not set');
}
}
}
6 changes: 3 additions & 3 deletions src/HubtelChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace NotificationChannels\Hubtel;

use Illuminate\Notifications\Notification;
use NotificationChannels\Hubtel\SMSClients\HubtelSMSClient;
use NotificationChannels\Hubtel\Exceptions\CouldNotSendNotification;
use NotificationChannels\Hubtel\SMSClients\HubtelSMSClient;

class HubtelChannel
{
Expand Down Expand Up @@ -42,10 +42,10 @@ public function send($notifiable, Notification $notification)
throw CouldNotSendNotification::contentNotSetError();
}

if (is_null($message->to) && !is_null($notifiable->routeNotificationFor('SMS'))) {
if (is_null($message->to) && ! is_null($notifiable->routeNotificationFor('SMS'))) {
$message->to = $notifiable->routeNotificationFor('SMS');
}

return $this->client->send($message);
}
}
14 changes: 11 additions & 3 deletions src/HubtelMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HubtelMessage
public $registeredDelivery;

/**
*The Reference Number provided by the Client
*The Reference Number provided by the Client
*prior to sending the message.
*@var int
*/
Expand All @@ -43,7 +43,7 @@ class HubtelMessage

/**
*The User Data Header of the SMS Message being sent.
*@var string
*@var string
*/
public $udh;

Expand All @@ -59,7 +59,6 @@ class HubtelMessage
*/
public $flashMessage;


public function __construct($from = null, $to = null, $content = null)
{
$this->from = $from;
Expand All @@ -75,6 +74,7 @@ public function __construct($from = null, $to = null, $content = null)
public function from($from)
{
$this->from = $from;

return $this;
}

Expand All @@ -86,6 +86,7 @@ public function from($from)
public function to($to)
{
$this->to = $to;

return $this;
}

Expand All @@ -97,6 +98,7 @@ public function to($to)
public function content($content)
{
$this->content = $content;

return $this;
}

Expand All @@ -107,6 +109,7 @@ public function content($content)
public function registeredDelivery()
{
$this->registeredDelivery = 'true';

return $this;
}

Expand All @@ -118,6 +121,7 @@ public function registeredDelivery()
public function clientReference($reference)
{
$this->clientReference = $reference;

return $this;
}

Expand All @@ -129,6 +133,7 @@ public function clientReference($reference)
public function type($type)
{
$this->type = $type;

return $this;
}

Expand All @@ -140,6 +145,7 @@ public function type($type)
public function udh($udh)
{
$this->udh = $udh;

return $this;
}

Expand All @@ -151,6 +157,7 @@ public function udh($udh)
public function time($time)
{
$this->time = $time;

return $this;
}

Expand All @@ -161,6 +168,7 @@ public function time($time)
public function flashMessage()
{
$this->flashMessage = 'true';

return $this;
}
}
22 changes: 11 additions & 11 deletions src/SMSClients/HubtelSMSClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
namespace NotificationChannels\Hubtel\SMSClients;

use GuzzleHttp\Client;
use NotificationChannels\Hubtel\HubtelMessage;
use NotificationChannels\Hubtel\Exceptions\InvalidConfiguration;
use NotificationChannels\Hubtel\HubtelMessage;

class HubtelSMSClient
{

public $client;

public $apiKey;

public $apiSecret;

public function __construct($apiKey, $apiSecret, Client $client)
{
$this->apiKey = $apiKey;
Expand All @@ -35,27 +34,28 @@ public function getApiURL()
public function buildMessage(HubtelMessage $message, $apiKey, $apiSecret)
{
$this->validateConfig($apiKey, $apiSecret);

$params = array('ClientId'=>$apiKey,'ClientSecret' => $apiSecret);

foreach(get_object_vars($message) as $property => $value) {
if(!is_null($value)) {
$params = ['ClientId'=>$apiKey, 'ClientSecret' => $apiSecret];

foreach (get_object_vars($message) as $property => $value) {
if (! is_null($value)) {
$params[ucfirst($property)] = $value;
}
}

return http_build_query($params);
}

public function validateConfig($apiKey, $apiSecret)
{
if(is_null($apiKey)) {
if (is_null($apiKey)) {
throw InvalidConfiguration::apiKeyNotSet();
}

if(is_null($apiSecret)) {
if (is_null($apiSecret)) {
throw InvalidConfiguration::apiSecretNotSet();
}

return $this;
}
}
}
8 changes: 4 additions & 4 deletions src/config/hubtel.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* This file holds the configuration keys.
*/
* This file holds the configuration keys.
*/

return [
'account' => [
'key' => env('HUBTEL_API_KEY'),
'secret' => env('HUBTEL_API_SECRET'),
],
];

];
8 changes: 4 additions & 4 deletions tests/HubtelMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace NotificationChannels\Hubtel\Test;

use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;
use NotificationChannels\Hubtel\HubtelMessage;

class HubtelMessageTest extends PHPUnit_Framework_TestCase
class HubtelMessageTest extends TestCase
{
public $message;

public function setUp()
public function setUp():void
{
parent::setUp();
$this->message = new HubtelMessage();
Expand Down Expand Up @@ -86,4 +86,4 @@ public function it_can_send_the_message_as_a_flash_message()
$this->message->flashMessage();
$this->assertEquals($this->message->flashMessage, 'true');
}
}
}

0 comments on commit 61a45e4

Please sign in to comment.