Giter Site home page Giter Site logo

andreshg112 / pusher-api-notifications Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 1.0 28 KB

Send Pusher API Notifications with Laravel notifications system.

Home Page: https://pusher.com/docs/javascript_quick_start

License: MIT License

PHP 100.00%
laravel laravel-notification-channels pusher pusher-api php

pusher-api-notifications's Introduction

Pusher API Notifications

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

This package makes it easy to send notifications using Pusher API Messages (like shown below) with Laravel 5.3 or greater.

Contents

Installation

Require the package:

$ composer require andreshg112/pusher-api-notifications

Setting up the Pusher API Notifications service

This package requires pusher/pusher-http-laravel ^4.2, so after installing this, you have to configure it.

If your using Laravel ^5.5, don't worry about adding the service provider to your config/app.php file because this package uses Laravel Package Discovery. If don't, you have to add it:

'providers' => [
    // ...,
    Andreshg112\PusherApiNotifications\PusherApiServiceProvider::class,
],

Usage

This is a third-party Laravel Notification Package, so you should know how to use Notifications in Laravel before using this. Docs can be found here: https://laravel.com/docs/master/notifications.

In your notification, add the PusherApiChannel to the via() function:

use Andreshg112\PusherApiNotifications\PusherApiChannel;

public function via($notifiable)
{
    return [PusherApiChannel::class];
}

Then, create a method called toApiNotification() in your notification:

use Andreshg112\PusherApiNotifications\PusherApiMessage;

public function toApiNotification($notifiable)
{
    return (new PusherApiMessage)
        ->channels($channelName)
        ->event($eventName)
        ->data($data)
        ->socketId($socketId)
        ->debug($debug)
        ->alreadyEncoded($alreadyEncoded);

    // or

    return new PusherApiMessage($channelName, $eventName, $data, $socketId, $debug, $alreadyEncoded);
}

Available Message methods

  • channels($channelName): array or string of channel name(s).
  • event($eventName): the name of the event for the Pusher message.
  • data($data): array, string or something that can be corverted to JSON. It's the body of the Pusher message.
  • socketId($socketId): [optional] socketId of Pusher.
  • debug($debug): [optional] boolean that tells Pusher if you're debugging.
  • alreadyEncoded($alreadyEncoded): [optional] If the data is already encoded and you don't want Pusher to convert it, set this to true.

These parameters are the same received by Pusher::trigger() method.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

pusher-api-notifications's People

Contributors

andreshg112 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

appstarbd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.