Introducing Push Plugins

Anyone pulling from the nightly repo may have noticed a cool new feature for the Swift Core that Ahmed wrote last month, our Push Plugin architecture.  This, as well as a number of other features will be released with the next release of Sweeper and the Swift PHP Core.


How Push Plugins Work

Push Plugins allow SwiftRiver applications to acquire content via push (versus pull) commands.  For instance, if a user needs an SMS gateway to submit to a Swift app, you no longer need to poll the server for that content, instead, the gateway can tell your app when there’s content by pushing to the application.  
 
This plugin architecture currently supports receiving data through the standard HTTP methods GET and POST.
 
In addition, this architecture can be extended through Push Plugins to support the injection of any kind of data into the system. For example, the uploading of content from files, or the use of bookmarklets such as the Quiver extension.

How To develop Push Plugins

Locate the Modules/SiSPS/PushParsers folder, this is where you’ll find push parsers. To develop a push parser you will need to do the following:

  1. Create a file named <parsername>PushParser.php (the class name needs to be the same as the file name).
  2. Needs to be in the namespace Swiftriver\Core\Modules\SiSPS\PushParsers;
  3. Implement the following methods:
  • PushAndParser($raw_content = null, $post_content = null, $get_content = null)
  • GetDescription() - This is what gets displayed in the Sweeper UI that describes how the parser works
  • ReturnType() - Returns the type that describes what the push parser is all about

The second and third methods are implemented for display purposes so that your parser can be displayed correctly in Swift applications.

The first method is where you need to write code to convert the content being received by your parser into the Swift object model, this function should also return the content back to the rest of the SwiftRiver Core once its finished.

Depending on the type of resource your parser is listening out for, it will receive the content in one of the three variables $raw_content, $post_content and $get_content.