Skip to content

Commit

Permalink
feat: add config for switching apis tld (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxlrbt authored May 21, 2020
1 parent 508c979 commit efda75b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ php artisan vendor:publish --provider="NotificationChannels\Smsapi\SmsapiService

### Setting up the Smsapi service

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

```php
Expand All @@ -53,6 +55,8 @@ Set your credentials and defaults in `config/smsapi.php`:
// 'username' => env('SMSAPI_AUTH_USERNAME'),
// 'password' => env('SMSAPI_AUTH_PASSWORD'), // Hashed by MD5
],
// Service of smsapi. Can be SmsapiClient::SERVICE_PL or SmsapiClient::SERVICE_COM.
'service' => SmsapiClient::SERVICE_PL,
],
'defaults' => [
'common' => [
Expand Down
14 changes: 14 additions & 0 deletions config/smsapi.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use NotificationChannels\Smsapi\SmsapiClient;

return [
'auth' => [
/*
Expand All @@ -18,6 +20,18 @@
// 'username' => env('SMSAPI_AUTH_USERNAME'),
// 'password' => env('SMSAPI_AUTH_PASSWORD'), // Hashed by MD5
],

/*
|----------------------------------------------------------------------
| SMSAPI service type
|----------------------------------------------------------------------
| SMSAPI runs a polish service on smsapi.pl and a international service
| on smsapi.com. This option will set which version will be used.
|
| Supported: "SmsapiClient::SERVICE_PL", "SmsapiClient::SERVICE_COM".
|
*/
'service' => SmsapiClient::SERVICE_PL,
],

/*
Expand Down
4 changes: 4 additions & 0 deletions src/SmsapiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class SmsapiClient
*/
protected $proxy;

public const SERVICE_PL = 'https://api.smsapi.pl';

public const SERVICE_COM = 'https://api.smsapi.com';

/**
* @param Client $client
* @param array $defaults
Expand Down
7 changes: 5 additions & 2 deletions src/SmsapiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use SMSApi\Client;
use SMSApi\Proxy\Http\Native;

class SmsapiServiceProvider extends ServiceProvider
{
Expand All @@ -17,7 +18,7 @@ public function boot()
->needs(SmsapiClient::class)
->give(function () {
$config = config('smsapi');
$auth = $config['auth'];
$auth = $config['auth'] + ['service' => SmsapiClient::SERVICE_PL];
if ($auth['method'] === 'token') {
$client = Client::createFromToken($auth['credentials']['token']);
} elseif ($auth['method'] === 'password') {
Expand Down Expand Up @@ -54,7 +55,9 @@ public function boot()
});
}, $defaults);

return new SmsapiClient($client, $defaults);
$proxy = new Native($auth['service']);

return new SmsapiClient($client, $defaults, $proxy);
});

if ($this->app->runningInConsole()) {
Expand Down

0 comments on commit efda75b

Please sign in to comment.