Skip to content

Commit efda75b

Browse files
authored
feat: add config for switching apis tld (#13)
1 parent 508c979 commit efda75b

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

README.md

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ php artisan vendor:publish --provider="NotificationChannels\Smsapi\SmsapiService
4141

4242
### Setting up the Smsapi service
4343

44-
Log in to your [Smsapi dashboard](https://ssl.smsapi.pl/) and configure your preferred authentication method.
44+
Log in to your Smsapi dashboard and configure your preferred authentication method. There is a
45+
[polish version](https://ssl.smsapi.pl/) and an [international version](https://ssl.smsapi.com/)
46+
which have separated accounts.
4547
Set your credentials and defaults in `config/smsapi.php`:
4648

4749
```php
@@ -53,6 +55,8 @@ Set your credentials and defaults in `config/smsapi.php`:
5355
// 'username' => env('SMSAPI_AUTH_USERNAME'),
5456
// 'password' => env('SMSAPI_AUTH_PASSWORD'), // Hashed by MD5
5557
],
58+
// Service of smsapi. Can be SmsapiClient::SERVICE_PL or SmsapiClient::SERVICE_COM.
59+
'service' => SmsapiClient::SERVICE_PL,
5660
],
5761
'defaults' => [
5862
'common' => [

config/smsapi.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use NotificationChannels\Smsapi\SmsapiClient;
4+
35
return [
46
'auth' => [
57
/*
@@ -18,6 +20,18 @@
1820
// 'username' => env('SMSAPI_AUTH_USERNAME'),
1921
// 'password' => env('SMSAPI_AUTH_PASSWORD'), // Hashed by MD5
2022
],
23+
24+
/*
25+
|----------------------------------------------------------------------
26+
| SMSAPI service type
27+
|----------------------------------------------------------------------
28+
| SMSAPI runs a polish service on smsapi.pl and a international service
29+
| on smsapi.com. This option will set which version will be used.
30+
|
31+
| Supported: "SmsapiClient::SERVICE_PL", "SmsapiClient::SERVICE_COM".
32+
|
33+
*/
34+
'service' => SmsapiClient::SERVICE_PL,
2135
],
2236

2337
/*

src/SmsapiClient.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class SmsapiClient
2626
*/
2727
protected $proxy;
2828

29+
public const SERVICE_PL = 'https://api.smsapi.pl';
30+
31+
public const SERVICE_COM = 'https://api.smsapi.com';
32+
2933
/**
3034
* @param Client $client
3135
* @param array $defaults

src/SmsapiServiceProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Arr;
66
use Illuminate\Support\ServiceProvider;
77
use SMSApi\Client;
8+
use SMSApi\Proxy\Http\Native;
89

910
class SmsapiServiceProvider extends ServiceProvider
1011
{
@@ -17,7 +18,7 @@ public function boot()
1718
->needs(SmsapiClient::class)
1819
->give(function () {
1920
$config = config('smsapi');
20-
$auth = $config['auth'];
21+
$auth = $config['auth'] + ['service' => SmsapiClient::SERVICE_PL];
2122
if ($auth['method'] === 'token') {
2223
$client = Client::createFromToken($auth['credentials']['token']);
2324
} elseif ($auth['method'] === 'password') {
@@ -54,7 +55,9 @@ public function boot()
5455
});
5556
}, $defaults);
5657

57-
return new SmsapiClient($client, $defaults);
58+
$proxy = new Native($auth['service']);
59+
60+
return new SmsapiClient($client, $defaults, $proxy);
5861
});
5962

6063
if ($this->app->runningInConsole()) {

0 commit comments

Comments
 (0)