-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolved issue #12 #18
Changes from 5 commits
60625ea
505dd5a
038737a
588d2c2
52aeb24
5dba2ab
39b3816
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,15 @@ Add your SmscRu login, secret key (hashed password) and default sender name (or | |
... | ||
``` | ||
|
||
> If smsc.ru is not responding, you can set custom host WITH trailing slash | ||
``` | ||
'smscru' => [ | ||
... | ||
'host' => 'http://www1.smsc.kz/', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Надо вынести в |
||
... | ||
], | ||
``` | ||
|
||
## Usage | ||
|
||
You can use the channel in your `via()` method inside the notification: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,12 @@ class SmscRuApi | |
{ | ||
const FORMAT_JSON = 3; | ||
|
||
/** @var string */ | ||
protected $apiUrl = 'https://smsc.ru/sys/send.php'; | ||
|
||
/** @var HttpClient */ | ||
protected $httpClient; | ||
|
||
/** @var string */ | ||
protected $url; | ||
|
||
/** @var string */ | ||
protected $login; | ||
|
||
|
@@ -25,11 +25,12 @@ class SmscRuApi | |
/** @var string */ | ||
protected $sender; | ||
|
||
public function __construct($login, $secret, $sender) | ||
public function __construct($config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
$this->login = $login; | ||
$this->secret = $secret; | ||
$this->sender = $sender; | ||
$this->url = array_get($config, 'host', 'https://smsc.ru/').'sys/send.php'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$this->login = array_get($config, 'login'); | ||
$this->secret = array_get($config, 'secret'); | ||
$this->sender = array_get($config, 'sender'); | ||
|
||
$this->httpClient = new HttpClient([ | ||
'timeout' => 5, | ||
|
@@ -57,7 +58,7 @@ public function send($params) | |
$params = array_merge($params, $base); | ||
|
||
try { | ||
$response = $this->httpClient->post($this->apiUrl, ['form_params' => $params]); | ||
$response = $this->httpClient->post($this->url, ['form_params' => $params]); | ||
|
||
$response = json_decode((string) $response->getBody(), true); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace NotificationChannel\SmscRu\Tests; | ||
|
||
use NotificationChannels\SmscRu\SmscRuApi; | ||
|
||
class SmscRuApiTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var SmscRuApi | ||
*/ | ||
private $smsc; | ||
|
||
public function tearDown() | ||
{ | ||
$this->smsc = null; | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** @test */ | ||
public function it_has_default_url() | ||
{ | ||
$this->smsc = new SmscRuApi([]); | ||
$this->assertAttributeEquals('https://smsc.ru/sys/send.php', 'url', $this->smsc); | ||
$this->assertAttributeEquals(null, 'login', $this->smsc); | ||
$this->assertAttributeEquals(null, 'secret', $this->smsc); | ||
$this->assertAttributeEquals(null, 'sender', $this->smsc); | ||
} | ||
|
||
/** @test */ | ||
public function it_has_custom_config() | ||
{ | ||
$host = 'https://smsc.kz/'; | ||
$login = 'login'; | ||
$secret = 'secret'; | ||
$sender = 'sender'; | ||
|
||
$this->smsc = new SmscRuApi([ | ||
'host' => $host, | ||
'login' => $login, | ||
'secret' => $secret, | ||
'sender' => $sender, | ||
]); | ||
|
||
$this->assertAttributeEquals('https://smsc.kz/sys/send.php', 'url', $this->smsc); | ||
$this->assertAttributeEquals($login, 'login', $this->smsc); | ||
$this->assertAttributeEquals($secret, 'secret', $this->smsc); | ||
$this->assertAttributeEquals($sender, 'sender', $this->smsc); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не очень понятно, можно подумать, что пакет автоматом переключится на этот хост, если основной не отвечает.