forked from lab123it/aws-sns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 63d3733
Showing
13 changed files
with
596 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.idea | ||
.buildpath | ||
.project | ||
.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
preset: laravel | ||
|
||
linting: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
All notable changes to `aws-sns` will be documented in this file | ||
|
||
## 1.0.0 - 201X-XX-XX | ||
|
||
- initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Contributing | ||
|
||
Contributions are **welcome** and will be fully **credited**. | ||
|
||
Please read and understand the contribution guide before creating an issue or pull request. | ||
|
||
## Etiquette | ||
|
||
This project is open source, and as such, the maintainers give their free time to build and maintain the source code | ||
held within. They make the code freely available in the hope that it will be of use to other developers. It would be | ||
extremely unfair for them to suffer abuse or anger for their hard work. | ||
|
||
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the | ||
world that developers are civilized and selfless people. | ||
|
||
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient | ||
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. | ||
|
||
## Viability | ||
|
||
When requesting or submitting new features, first consider whether it might be useful to others. Open | ||
source projects are used by many developers, who may have entirely different needs to your own. Think about | ||
whether or not your feature is likely to be used by other users of the project. | ||
|
||
## Procedure | ||
|
||
Before filing an issue: | ||
|
||
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. | ||
- Check to make sure your feature suggestion isn't already present within the project. | ||
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. | ||
- Check the pull requests tab to ensure that the feature isn't already in progress. | ||
|
||
Before submitting a pull request: | ||
|
||
- Check the codebase to ensure that your feature doesn't already exist. | ||
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. | ||
|
||
## Requirements | ||
|
||
If the project maintainer has any additional requirements, you will find them listed here. | ||
|
||
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). | ||
|
||
- **Add tests!** - Your patch won't be accepted if it doesn't have tests. | ||
|
||
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. | ||
|
||
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. | ||
|
||
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. | ||
|
||
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. | ||
|
||
**Happy coding**! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) Jean Pierre <jean.pierre@lab123.com.br> | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in | ||
> all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
> THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
# Amazon SNS Notifications Channel for Laravel 5.3 [WIP] | ||
|
||
[![Latest Version on Packagist](https://img.shields.io/packagist/v/lab123/aws-sns.svg?style=flat-square)](https://packagist.org/packages/lab123/aws-sns) | ||
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) | ||
[![Build Status](https://img.shields.io/travis/lab123/aws-sns/master.svg?style=flat-square)](https://travis-ci.org/lab123/aws-sns) | ||
[![StyleCI](https://styleci.io/repos/:style_ci_id/shield)](https://styleci.io/repos/:style_ci_id) | ||
[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/:sensio_labs_id.svg?style=flat-square)](https://insight.sensiolabs.com/projects/:sensio_labs_id) | ||
[![Quality Score](https://img.shields.io/scrutinizer/g/lab123/aws-sns.svg?style=flat-square)](https://scrutinizer-ci.com/g/lab123/aws-sns) | ||
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/lab123/aws-sns/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/lab123/aws-sns/?branch=master) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/lab123/aws-sns.svg?style=flat-square)](https://packagist.org/packages/lab123/aws-sns) | ||
|
||
This package makes it easy to send notifications using [Amazon SNS](https://aws.amazon.com/pt/sns/) with Laravel 5.3. | ||
|
||
## Contents | ||
|
||
- [Installation](#installation) | ||
- [Setting up the AwsSns service](#setting-up-the-AwsSns-service) | ||
- [Usage](#usage) | ||
- [Available Message methods](#available-message-methods) | ||
- [Changelog](#changelog) | ||
- [Testing](#testing) | ||
- [Security](#security) | ||
- [Contributing](#contributing) | ||
- [Credits](#credits) | ||
- [License](#license) | ||
|
||
|
||
## Installation | ||
|
||
Can to install with commands: | ||
|
||
composer require lab123/aws-sns | ||
|
||
Or editing the `composer.json` file: | ||
|
||
"require": { | ||
"lab123/aws-sns": "dev-master" | ||
} | ||
|
||
You must install the service provider in `config/app.php`: | ||
|
||
'providers' => [ | ||
... | ||
Lab123\AwsSns\AwsSnsServiceProvider::class, | ||
], | ||
|
||
### Setting up the AwsSns service | ||
|
||
Follow the Amazon Console generate the APIKEY and API SECRET, which is connecting both. | ||
|
||
Create a new sns section inside `config/services.php`: | ||
|
||
... | ||
'sns' => [ | ||
'key' => env('SNS_KEY'), | ||
'secret' => env('SNS_SECRET'), | ||
'region' => env('SNS_REGION', 'us-east-1') | ||
], | ||
... | ||
|
||
Next we need to add this keys to our Laravel environment. Edit file `.env` to config the keys: | ||
|
||
SNS_KEY=YOUR_KEY | ||
SNS_SECRET=YOUR_SECRET | ||
SNS_REGION=YOUR_REGION | ||
|
||
|
||
## Usage | ||
|
||
### SMS ### | ||
|
||
To send sms without the need to create a topic, leave the `function via` as follows: | ||
|
||
/** | ||
* Get the notification channels. | ||
* | ||
* @param mixed $notifiable | ||
* @return array|string | ||
*/ | ||
public function via($notifiable) | ||
{ | ||
return [ | ||
AwsSnsSmsChannel::class | ||
]; | ||
} | ||
|
||
Add function `toAwsSnsSms()` expected by class `AwsSnsSmsChannel` to send notification: | ||
|
||
/** | ||
* Get the AWS SNS SMS Message representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* @return \Lab123\AwsSns\Messages\AwsSnsMessage | ||
*/ | ||
public function toAwsSnsSms($notifiable) | ||
{ | ||
return (new AwsSnsMessage())->message('Message Here')->phoneNumber('+5511999999999'); | ||
} | ||
|
||
**Obs.: ** The expected number use the standards-based international [E.123](https://en.wikipedia.org/wiki/E.123) | ||
**eg.:** +5511999999999 | ||
|
||
### Topic ### | ||
|
||
To send notification to a topic, leave the `function via` as follows: | ||
|
||
/** | ||
* Get the notification channels. | ||
* | ||
* @param mixed $notifiable | ||
* @return array|string | ||
*/ | ||
public function via($notifiable) | ||
{ | ||
return [ | ||
AwsSnsTopicChannel::class | ||
]; | ||
} | ||
|
||
Add function `toAwsSnsTopic()` expected by class `AwsSnsTopicChannel` to send notification: | ||
|
||
/** | ||
* Get the AWS SNS Topic Message representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* @return \Lab123\AwsSns\Messages\AwsSnsMessage | ||
*/ | ||
public function toAwsSnsTopic($notifiable) | ||
{ | ||
return (new AwsSnsMessage())->message('Message Here')->topicArn('arn:aws:sns:us-east-1:000000000000:name-topic'); | ||
} | ||
|
||
### Available methods | ||
|
||
|
||
* `topicArn($topicArn)`: Your Topic Arn from Amazon SNS; | ||
* `phoneNumber($phoneNumber)`: Phone number to send notification; | ||
* `message($message)`: Message to be sent; | ||
|
||
## Changelog | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. | ||
|
||
## Testing | ||
|
||
``` bash | ||
$ composer test | ||
``` | ||
|
||
## Security | ||
|
||
If you discover any security related issues, please email jean.pierre@lab123.com.br instead of using the issue tracker. | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) for details. | ||
|
||
## Credits | ||
|
||
- [Jean Pierre](https://github.com/jeanpfs) | ||
- [Felipe Santos](https://github.com/felipeds2) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "lab123/aws-sns", | ||
"description": "Amazon SNS Notifications Channel for Laravel 5.3", | ||
"homepage": "https://github.com/lab123ti/aws-sns", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Jean Pierre", | ||
"email": "jean.pierre@lab123.com.br", | ||
"homepage": "https://lab123.com.br", | ||
"role": "Developer" | ||
}, | ||
{ | ||
"name": "Felipe Santos", | ||
"email": "felipe.santos@lab123.com.br", | ||
"homepage": "https://lab123.com.br", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.6.4", | ||
"illuminate/notifications": "^5.3", | ||
"illuminate/support": "^5.1|^5.2|^5.3", | ||
"aws/aws-sdk-php-laravel": "~3.0" | ||
}, | ||
"require-dev": { | ||
"mockery/mockery": "^0.9.5", | ||
"phpunit/phpunit": "4.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Lab123\\AwsSns\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Lab123\\AwsSns\\Test\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
namespace Lab123\AwsSns; | ||
|
||
use Lab123\AwsSns\Channels\AwsSnsTopicChannel; | ||
use Lab123\AwsSns\Channels\AwsSnsSmsChannel; | ||
use Illuminate\Support\ServiceProvider; | ||
use Aws\Sns\SnsClient; | ||
|
||
class AwsSnsServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Bootstrap the application services. | ||
*/ | ||
public function boot() | ||
{ | ||
$this->app->when(AwsSnsSmsChannel::class) | ||
->needs(SnsClient::class) | ||
->give(function () { | ||
return $this->giveSnsInstance(); | ||
}); | ||
|
||
$this->app->when(AwsSnsTopicChannel::class) | ||
->needs(SnsClient::class) | ||
->give(function () { | ||
return $this->giveSnsInstance(); | ||
}); | ||
} | ||
|
||
private function giveSnsInstance() | ||
{ | ||
$config = config('services.sns'); | ||
|
||
return SnsClient::factory([ | ||
'credentials' => [ | ||
'key' => $config['key'], | ||
'secret' => $config['secret'] | ||
], | ||
'version' => 'latest', | ||
'region' => $config['region'] | ||
]); | ||
} | ||
|
||
/** | ||
* Register the application services. | ||
*/ | ||
public function register() | ||
{} | ||
} |
Oops, something went wrong.