Skip to content

Commit

Permalink
fix: white space issue in pattern parameters name and value (#1247)
Browse files Browse the repository at this point in the history
* fix: white space issue in pattern parameters name and value

* fix: pint

---------

Co-authored-by: rel4xdev <arelaxdev@gmail.com>
  • Loading branch information
moosti and rel4xdev authored Feb 5, 2024
1 parent 3abc0ab commit 0711ee6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
'username' => 'Your SMSApi Username',
'password' => 'Your SMSApi Password',
'from' => 'Your Default From Number',
'cc' => 'Your Default Country Code'
'cc' => 'Your Default Country Code',
],
],

Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Farazsmspattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function payload($recipient): array
continue;
}
$key_value = explode('=', $datum);
$input_data[trim($key_value[0])] = $key_value[1];
$input_data[trim($key_value[0])] = trim($key_value[1]);
}

return [
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Melipayamakpattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function send()
continue;
}
$key_value = explode('=', $datum);
$input_data[] = $key_value[1];
$input_data[] = trim($key_value[1]);
}
foreach ($this->recipients as $recipient) {
$response->put($recipient, $this->client->sms('soap')->sendByBaseNumber(
Expand Down
16 changes: 7 additions & 9 deletions src/Drivers/SmsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SmsApi extends Driver
protected Client $client;

private array $options = [];

protected function boot(): void
{
$this->client = new Client();
Expand All @@ -19,17 +19,14 @@ protected function boot(): void

/**
* Provides a way to pass additional valid parameters or override existing ones
*
* @param array $options
* @return self
*/
public function with(array $options): self
{
if (!empty(array_diff(array_keys($options), ['from', 'sname', 'cc', 'sid', 'ur', 'dr', 'stime', 'unicode', 'mms', 'mmstype', 'mmsurl']))) {
throw new \Exception(__METHOD__ . " contains invalid options");
if (! empty(array_diff(array_keys($options), ['from', 'sname', 'cc', 'sid', 'ur', 'dr', 'stime', 'unicode', 'mms', 'mmstype', 'mmsurl']))) {
throw new \Exception(__METHOD__.' contains invalid options');
}

foreach($options as $option => $value) {
foreach ($options as $option => $value) {
$this->options[$option] = $value;
}

Expand All @@ -47,11 +44,12 @@ public function send()
data_get($this->settings, 'url'),
[
'form_params' => $this->payload($recipient),
'verify' => false
'verify' => false,
]
)
);
}

return (count($this->recipients) == 1) ? $response->first() : $response;
}

Expand All @@ -66,6 +64,6 @@ public function payload($recipient): array
'm' => $this->body,
];

return array_merge($payload, $this->options);
return array_merge($payload, $this->options);
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/SmsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Tzsk\Sms\Tests\Drivers;

use Tzsk\Sms\Facades\Sms;
use Tzsk\Sms\Tests\TestCase;
use Tzsk\Sms\Tests\Mocks\Drivers\MockSmsApi;
use Tzsk\Sms\Tests\TestCase;

class SmsApiTest extends TestCase
{
Expand All @@ -19,7 +19,7 @@ public function test_it_wont_accept_invalid_parameters()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Tzsk\Sms\Drivers\SmsApi::with contains invalid options');
Sms::via('smsapi')->send("this message", function ($sms) {
Sms::via('smsapi')->send('this message', function ($sms) {
$sms->to(['Number 1', 'Number 2'])->with(['invalid_parameter' => 'value', 'sid' => 1, 'sname' => 'Sender Name']);
});
}
Expand Down

0 comments on commit 0711ee6

Please sign in to comment.