├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── _config.yml ├── composer.json ├── config └── shoutout_message.php ├── src ├── Shoutout.php └── ShoutoutServiceProvider.php └── tests └── SampleTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | .idea 3 | composer.phar 4 | composer.lock 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## v2.0.3 - 2022-04-25 4 | 5 | ### Fixed 6 | 7 | - PHP version compatibility 8 | 9 | ## v2.0.2 - 2022-04-24 10 | 11 | ### Fixed 12 | 13 | - Guzzle latest version issue fixed by adding guzzle 7.4.2 library 14 | 15 | ## v1.0.1 - 2020-02-23 16 | 17 | ### Changed 18 | 19 | - Code Format -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Dasun Dissanayake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image3](https://user-images.githubusercontent.com/15827995/75132975-edd40b00-56fe-11ea-8811-7e6f3f13a450.jpg) 2 | 3 | # Laravel Shoutout Messaging 4 | Shoutout messaging library for Laravel 5 | 6 | [![Latest Stable Version](https://poser.pugx.org/dasun4u/laravel-shoutout-messaging/v/stable)](https://packagist.org/packages/dasun4u/laravel-shoutout-messaging) 7 | [![Total Downloads](https://poser.pugx.org/dasun4u/laravel-shoutout-messaging/downloads)](https://packagist.org/packages/dasun4u/laravel-shoutout-messaging) 8 | [![License](https://poser.pugx.org/dasun4u/laravel-shoutout-messaging/license)](https://packagist.org/packages/dasun4u/laravel-shoutout-messaging) 9 | [![StyleCI](https://github.styleci.io/repos/240946426/shield?branch=master)](https://github.styleci.io/repos/240946426) 10 | 11 | * [Laravel](https://laravel.com) PHP framework 12 | * [Shoutout](https://getshoutout.com) Messaging 13 | 14 | ## Requirements 15 | 16 | * PHP 8.0+ 17 | * Laravel 8.0+ 18 | ## Installation 19 | 20 | * Install the package by running this command in your terminal/cmd: 21 | ``` 22 | composer require dasun4u/laravel-shoutout-messaging 23 | ``` 24 | 25 | * Import config file by running this command in your terminal/cmd and change the configs accordingly 26 | ``` 27 | php artisan vendor:publish --provider="Dasun4u\LaravelShoutoutMessaging\ShoutoutServiceProvider" 28 | ``` 29 | 30 | * Change the imported config file (`config/shoutout_message.php`) accordingly 31 | ```php 32 | 'api_key' => 'XXXXXXXXX.XXXXXXXXX.XXXXXXXXX', 33 | 'sms_source' => 'ShoutDEMO', 34 | 'email_source' => 'ShoutDEMO ', 35 | ``` 36 | 37 | * Send SMS 38 | ```php 39 | use Dasun4u\LaravelShoutoutMessaging\Shoutout; 40 | 41 | $shoutout = new Shoutout(); 42 | $destinations = ["+94712345678"]; // Multiple numbers can add as array 43 | $content = "Test SMS"; 44 | $response = $shoutout->sendSMS($destinations, $content); 45 | ``` 46 | 47 | * Send Email 48 | ```php 49 | use Dasun4u\LaravelShoutoutMessaging\Shoutout; 50 | 51 | $shoutout = new Shoutout(); 52 | $destinations = ["test@test.com"]; // Multiple numbers can add as array 53 | $subject = "Test Subject"; 54 | $content = "

Test html content

"; // Html body 55 | $response = $shoutout->sendEmail($destinations, $subject, $content); 56 | ``` 57 | 58 | * Get Response Data 59 | ```php 60 | $response_body = $response->getBody(); // Get response 61 | $response_body = json_decode($response->getBody(), true); // Get response as associative array 62 | $response_status_code = $response->getStatusCode(); // Get status code 63 | ``` 64 | 65 | ## Author 66 | 67 | * [**Dasun Dissanayake**](https://github.com/dasun4u) 68 | 69 | ## License 70 | 71 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details 72 | 73 | ## Special Thanks to 74 | 75 | * [Laravel](https://laravel.com) Community 76 | * [Shoutout](https://getshoutout.com) 77 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dasun4u/laravel-shoutout-messaging", 3 | "description": "shoutout messaging library for laravel", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Dasun Dissanayake", 9 | "email": "dpdasun@gmail.com" 10 | } 11 | ], 12 | "minimum-stability": "stable", 13 | "require": { 14 | "php": ">=8.0", 15 | "guzzlehttp/guzzle": "7.8.0" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "Dasun4u\\LaravelShoutoutMessaging\\": "src/" 20 | } 21 | }, 22 | "require-dev": { 23 | "phpunit/phpunit": ">=7.0.0" 24 | }, 25 | "autoload-dev": { 26 | "psr-4": { 27 | "Dasun4u\\LaravelShoutoutMessaging\\Test\\": "tests" 28 | } 29 | }, 30 | "scripts": { 31 | "test": ".\\vendor\\bin\\phpunit .\\tests\\SampleTest.php" 32 | }, 33 | "extra": { 34 | "laravel": { 35 | "providers": [ 36 | "Dasun4u\\LaravelShoutoutMessaging\\ShoutoutServiceProvider" 37 | ] 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /config/shoutout_message.php: -------------------------------------------------------------------------------- 1 | 'XXXXXXXXX.XXXXXXXXX.XXXXXXXXX', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | SMS Source 23 | |-------------------------------------------------------------------------- 24 | | 25 | | SMS Source given by Shoutout 26 | | 27 | */ 28 | 'sms_source' => 'ShoutDEMO', 29 | 30 | /* 31 | |-------------------------------------------------------------------------- 32 | | Email Source 33 | |-------------------------------------------------------------------------- 34 | | 35 | | Email Source given by Shoutout 36 | | 37 | */ 38 | 'email_source' => 'ShoutDEMO ', 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Log Enable 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Log enable must be true or false. true is recommended for safety reasons 46 | | 47 | */ 48 | 'log_enable' => false, 49 | 50 | /* 51 | |-------------------------------------------------------------------------- 52 | | Log Path 53 | |-------------------------------------------------------------------------- 54 | | 55 | | If 'log_enable' is true then log files generated in this path 56 | | 57 | */ 58 | 'log_path' => storage_path('logs/shoutout'), 59 | 60 | /* 61 | |-------------------------------------------------------------------------- 62 | | Log File Name 63 | |-------------------------------------------------------------------------- 64 | | 65 | | If 'log_file_name' is null then write logs as daily log files else write logs on given log file (ex: shoutout.log) 66 | | 67 | */ 68 | 'log_file_name' => null, 69 | ]; 70 | -------------------------------------------------------------------------------- /src/Shoutout.php: -------------------------------------------------------------------------------- 1 | api_key = config('shoutout_message.api_key'); 58 | $this->sms_source = config('shoutout_message.sms_source'); 59 | $this->email_source = config('shoutout_message.email_source'); 60 | $this->api_url = 'https://api.getshoutout.com/coreservice/messages'; 61 | $this->log_enable = config('shoutout_message.log_enable'); 62 | $this->log_path = config('shoutout_message.log_path'); 63 | $this->log_file_name = config('shoutout_message.log_file_name'); 64 | } 65 | 66 | public function apiCall($request_body) 67 | { 68 | $url = $this->api_url; 69 | $method = 'POST'; 70 | $request = [ 71 | 'headers' => [ 72 | 'Content-Type' => 'application/json', 73 | 'Authorization' => 'apikey '.$this->api_key, 74 | ], 75 | 'json' => $request_body, 76 | ]; 77 | $client = new Client(['http_errors' => false]); 78 | $response = $client->request($method, $url, $request); 79 | $this->logService($url, $method, $request['json'], $response, $this->log_file_name); 80 | 81 | return $response; 82 | } 83 | 84 | public function sendSMS($destinations, $content) 85 | { 86 | $request_body = [ 87 | 'source' => $this->sms_source, 88 | 'destinations' => $destinations, 89 | 'content' => ['sms' => $content], 90 | 'transports' => ['SMS'], 91 | ]; 92 | 93 | return $this->apiCall($request_body); 94 | } 95 | 96 | public function sendEmail($destinations, $subject, $content) 97 | { 98 | $request_body = [ 99 | 'source' => $this->email_source, 100 | 'destinations' => $destinations, 101 | 'content' => ['email' => ['htmlType'=>true, 'subject'=>$subject, 'body'=>$content]], 102 | 'transports' => ['email'], 103 | ]; 104 | 105 | return $this->apiCall($request_body); 106 | } 107 | 108 | /** 109 | * @param null $url 110 | * @param null $method 111 | * @param null $request_body 112 | * @param null $response 113 | * @param null $file_name 114 | * 115 | * @throws \Exception 116 | */ 117 | public function logService($url = null, $method = null, $request_body = null, $response = null, $file_name = null) 118 | { 119 | try { 120 | if ($this->log_enable) { 121 | $content = [ 122 | 'Request URL' => $url, 123 | 'Request Method' => $method, 124 | 'Request Body' => $request_body, 125 | 'Status Code' => $response->getStatusCode(), 126 | 'Response Headers' => $response->getHeaders(), 127 | 'Response Body' => json_decode($response->getBody()) != null ? json_decode($response->getBody()) : $response->getBody(), 128 | ]; 129 | 130 | $log = new Logger('Shoutout'); 131 | $file_name = $file_name != null ? $file_name : date('Y_m_d').'.log'; 132 | $log->pushHandler(new StreamHandler($this->log_path.'/'.$file_name), Logger::INFO); 133 | $log->info('SERVICE LOG', $content); 134 | } 135 | } catch (\Exception $e) { 136 | report($e); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/ShoutoutServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 23 | $this->publishes([ 24 | __DIR__.'/../config/shoutout_message.php' => config_path('shoutout_message.php'), 25 | ], 'shoutout-message-config'); 26 | } 27 | } 28 | 29 | /** 30 | * Make config publishment optional by merge the config from the package. 31 | * 32 | * @return void 33 | */ 34 | public function register() 35 | { 36 | $this->mergeConfigFrom( 37 | __DIR__.'/../config/shoutout_message.php', 38 | 'shoutout_message' 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/SampleTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('SMS', 'SMS'); 21 | } 22 | 23 | public function testEmail() 24 | { 25 | // Testing need API token and more packages then ignore the testing 26 | $this->assertEquals('Email', 'Email'); 27 | } 28 | } 29 | --------------------------------------------------------------------------------