RSS Push Notifications utilizando Parse
Lo sentimos, este post sólo está disponible en inglés.
Recently we have moved our apps to Parse and one thing we wanted to do is to send RSS Push Notifications. This way we can notify using Push Notifications every time we publish a post in our blog.
Searching on Google we have found that a lot of people asked for this, and there was no published solution. We have developed a solution for doing this using Cloud Code, and we want to share it with you.
Set up Cloud Code on your machine
To set up Cloud Code is very easy. Just run this line in your terminal and Cloud Code will be installed:
curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
If you are a Windows user you can follow Parse Documentation instructions:
The Parse command line tool for Windows is available here. After downloading the zip file and unzipping it, you can launch a parse-aware powershell session by double clicking ParseConsole.exe. After the first run of the ParseConsole, you can also start the powershell session by hitting Win + R and typing “parse”
Get Feed Item from RSS Feed with Parse Cloud Code
You will need two libraries on your Cloud Code in order to parse XML feed. This libraries are sax-js and xmlreader. You just simple download this js files to your Cloud folder, and change the following line on xmlreader.js: var sax = require(“sax”) to var sax = require(“cloud/sax”).
In your main.js file you can now use the parser using this variable xmlreader:
Use database to check if push was already sent
We create a function to save a Post on our database. This way the next time we run the job we can see if it’s already sent for a particular blog post.
Now, we try to find if the post is already sent and if not, we save it.
Send RSS Push Notifications to all installations
This example works for sending a push to everyone, buy you can customize it to send it to specific channels following the JS reference of Parse.
Make a job to perform this task every 15 minutes
Now you should encapsulate the code inside a job, and configure it to send it every 15 minutes on the parse dashboard website.
All code together
This is all the code to send push using a RSS Feed using Parse.