Skip to content

Commit

Permalink
Extra API parameters via config; return API response from send(); cs
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaoda committed Sep 26, 2019
1 parent cdeb3a3 commit dc01c06
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `smsc-ru` will be documented in this file

## 2.0.4 - 2019-09-26

- Extra API parameters via config
- Return API response from `send()`

## 2.0.3 - 2019-08-23

- Fix wrong parameters error in CouldNotSendNotification ([#33](https://github.com/laravel-notification-channels/smsc-ru/issues/33))
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/smsc-ru/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/smsc-ru/?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/smsc-ru.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/smsc-ru)

This package makes it easy to send notifications using [smsc.ru](//smsc.ru) (aka СМС–Центр) with Laravel 5.3+.
This package makes it easy to send notifications using [smsc.ru](https://smsc.ru) (aka СМС–Центр) with Laravel 5.3+.

## Contents

- [Installation](#installation)
- [Setting up the SmscRu service](#setting-up-the-SmscRu-service)
- [Usage](#usage)
- [Available Message methods](#available-message-methods)
- [Available Message methods](#available-methods)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
Expand Down Expand Up @@ -52,7 +52,11 @@ Add your SmscRu login, secret key (hashed password) and default sender name (or
'smscru' => [
'login' => env('SMSCRU_LOGIN'),
'secret' => env('SMSCRU_SECRET'),
'sender' => 'John_Doe'
'sender' => 'John_Doe',
'extra' => [
// any other API parameters
// 'tinyurl' => 1
],
],
...
```
Expand Down
7 changes: 6 additions & 1 deletion src/SmscRuApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ class SmscRuApi
/** @var string */
protected $sender;

/** @var array */
protected $extra;

public function __construct(array $config)
{
$this->login = Arr::get($config, 'login');
$this->secret = Arr::get($config, 'secret');
$this->sender = Arr::get($config, 'sender');
$this->endpoint = Arr::get($config, 'host', 'https://smsc.ru/').'sys/send.php';

$this->extra = Arr::get($config, 'extra', []);

$this->client = new HttpClient([
'timeout' => 5,
'connect_timeout' => 5,
Expand All @@ -48,7 +53,7 @@ public function send($params)
'fmt' => self::FORMAT_JSON,
];

$params = \array_merge($base, \array_filter($params));
$params = \array_merge($base, \array_filter($params), $this->extra);

try {
$response = $this->client->request('POST', $this->endpoint, ['form_params' => $params]);
Expand Down
12 changes: 7 additions & 5 deletions src/SmscRuChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public function __construct(SmscRuApi $smsc)
* @param mixed $notifiable
* @param Notification $notification
*
* @return void
* @throws CouldNotSendNotification
*
* @return array|null
*/
public function send($notifiable, Notification $notification)
{
if (! ($to = $this->getRecipients($notifiable, $notification))) {
return;
return null;
}

$message = $notification->{'toSmscRu'}($notifiable);
Expand All @@ -35,7 +37,7 @@ public function send($notifiable, Notification $notification)
$message = new SmscRuMessage($message);
}

$this->sendMessage($to, $message);
return $this->sendMessage($to, $message);
}

/**
Expand All @@ -50,7 +52,7 @@ protected function getRecipients($notifiable, Notification $notification)
{
$to = $notifiable->routeNotificationFor('smscru', $notification);

if ($to === null || $to === false || $to === '') {
if (empty($to)) {
return [];
}

Expand All @@ -73,6 +75,6 @@ protected function sendMessage($recipients, SmscRuMessage $message)
$params['time'] = '0'.$message->sendAt->getTimestamp();
}

$this->smsc->send($params);
return $this->smsc->send($params);
}
}

0 comments on commit dc01c06

Please sign in to comment.