2017 © Pedro Peláez
 

library notification-library

A simple library to push events events to the queue to be handled by the Notification Service

image

fotografde/notification-library

A simple library to push events events to the queue to be handled by the Notification Service

  • Thursday, May 24, 2018
  • by beinbm
  • Repository
  • 2 Watchers
  • 0 Stars
  • 3,019 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 1044 % Grown

The README.md

Build Status, (*1)

Notification Library

A simple library to push data to be handled by the Notification Service, (*2)

Setup

  • add to your (project folder)/composer.json, (*3)

    "require": {
        ...
        "fotografde/notification-library": "*"
    }
    
  • run, (*4)

    (project folder)> composer update
    
  • modify the configuration file, if necessary, (*5)

    (project folder)> cp vendor/GetPhoto/notification-library/config/notification.php.default vendor/GetPhoto/notification-library/config/notification.php
    OR
    (project folder)> cp src/vendors/GetPhoto/notification-library/config/notification.php.default src/vendors/GetPhoto/notification-library/config/notification.php
    

    **OR (for local configuration) **, (*6)

    (project folder)> cp config/notification.php.default config/notification.php
    
  • and configure it, (*7)

    'events_table' => 'EventQueue',
    'region' => '...',
    'endpoint' => '...',
    'credential_key' => '...',
    'credential_secret' => '...',
    'notification_service_url' => '...',
    'method_add_trigger' => 'api/trigger',
    

Events

Usage

  • Import the Notification class, (*8)

    use GetPhoto\Notification;
    
  • Pass the data to the method to push events, (*9)

    (new Notification)->pushEvent($data);
    
  • Examples, (*10)

    • User Login, (*11)

      $data = [
          'eventTypeId' => 'User.Login',
          'dateTime' => '20170117 232900',
          'userId' => '1',
          'photographerId' => '1',
      ];
      (new Notification)->pushEvent($data);
      
    • New Contactsheet, (*12)

      $data = [
          'eventTypeId' => 'Contactsheet.Created',
          'dateTime' => '20170115 080005',
          'userId' => '5',
          'photographerId' => '2',
          'contactsheetId' => 'a0shfd0a9shf9',
      ];
      (new Notification)->pushEvent($data);
      

Triggers

Usage

  • Import the Trigger class, (*13)

    use GetPhoto\Trigger;
    
  • Instantiate a new object, add the options and save, (*14)

    //Trigger ID => Unique name for your trigger
    //Trigger type => EventBased, Scheduled, TimeBased or Manual
    //Trigger action => Action to be executed
    $trigger = new Trigger('trigger id', 'trigger description', 'trigger type', 'trigger action');
    
    //optional methods
    $trigger->addSubscriptionKey('value');
    $trigger->addDelay('value');
    $trigger->addWhen('value');
    
    //auxiliar methods
    $trigger->createActionParameterConstant('constant', 'value');
    $trigger->createActionParameterVariable('variable', 'value');
    $trigger->createActionParameterMethod('variable', 'method', ['arguments', ...]);
    
    //optional methods that can be used multiple times
    $trigger->addActionParameter($parameter);
    $trigger->addParameter(['data key' => 'data value', ...]);
    
    $trigger->save();
    

Samples

Manual Trigger

Triggers that are executed via api request, (*15)

  • Return a json with all login from an user, (*16)

    Problem: We need a trigger to feed the user's config page with all of his logins. The config page will make an api request whenever the user request the login data., (*17)

    Solution: We have the method returnEvents which filter events based on given arguments. In this case, we want to filter by EventTypeId and UserId. We can obtain the UserId from the subscription, so it is a variable. Since we already know the EventTypeId, we define a constant., (*18)

    $trigger = new Trigger('UserLogins.v1', 'Shows all logins from an user', 'Manual', 'method::returnJson');
    $trigger->addSubscriptionKey('UserId');
    
    $userId = $trigger->createVariable('userId', 'userId');
    $eventTypeId = $trigger->createConstant('eventTypeId', 'User.Login');
    $eventsMethod = $trigger->createMethod('returnJson', [$userId, $eventTypeId]);
    $events = $trigger->createVariable('events', $eventsMethod);
    
    $trigger->addActionParameter($events);
    $trigger->save();
    

    Result:, (*19)

    • Trigger ID: UserLogins.v1
    • Trigger Description: Shows all logins from an user
    • Type: Manual
    • Subscription Key: UserId
    • Action: method::returnJson
    • Action Parameters: events::{{returnEvents||userId::[[userId]]||eventTypeId::User.Login}}

    Usage:, (*20)

    http://notification-service-url/queryEvents/UserLogins.v1/subscriber-id, (*21)

The Versions

24/05 2018

dev-master

9999999-dev https://dev.getphoto.io/getphoto/NotificationLibrary

A simple library to push events events to the queue to be handled by the Notification Service

  Sources   Download

The Requires

 

The Development Requires

events notification service

24/05 2018

1.0.1

1.0.1.0 https://dev.getphoto.io/getphoto/NotificationLibrary

A simple library to push events events to the queue to be handled by the Notification Service

  Sources   Download

The Requires

 

The Development Requires

events notification service