1. Introduction

    Pushetta is made to make it simple send broadcast communications to groups of subscribers. It works in a really simple way: as publisher You create a thematic group, every user that subscribes this group will receive a notification every time You push a message.
    It can be compared with SMS with many advantages:

    1. It's free of charge
    2. No needs of phone numbers or other personal data
    3. Sender gets accurate statistics about subscribers and delivered messages
    4. Can be extended to support devices other than phones (ie. Smart TV, web browsers, ...)

    Integrating Pushetta in Your Application it's really simple. Pushetta exposes his functionality with a REST API can be used in a wide range of cases, from enterprise web application to Arduino sketch.

  2. How it works

    Push notification are powerful tools but today this power is unexpressed, Pushetta is thought to make them available for everyone.
    Main field for which is thought (although not limited to) is IoT. Take a simple scenario: an Arduino based house automation system where it is necessary to notify the user against some events . Today this scenario can be solved with:

    1. Email: this is the standard approach and the most hated from users (mailboxes are filled of spam)
    2. SMS: this give many problems, obtain phone numbers, costs per send
    3. Custom App: developer can make a custom App with push notification support. Costs and time can be prohibitive

    Here is where Pushetta comes in help. Our Arduino's developer registers to Pushetta web site and creates a Channel named "House Alarms". He takes his API key from Dashboard and this is all he need to integrate Pushetta's function to his sketch. Integration it's made using simple API calls usable from many environments and languages.
    Most is done! Downloading one of Pushetta's companion Apps and subscribing the channel created it's all He need to start to receive push notification on event triggered by custom house automation system.
    It's also possible to send notification from channel details page which may be useful in testing but also for custom application which require manual notifications.

  3. Creating Channels

    First step to begin with Pushetta is to make a Channel. A Channel represents a topic it will be subscribed by users interested in receiving informations about this topic. It can be better explained with a simple use case: a weather forecast company creates a Channel named "Meteo Torino", every day the company sends a notification with day forecast. A user that live in Torino can subscribes to this Channel using one of Apps and every day a notification will inform him about forecast in Torino.
    Making a Channel isn't sufficient, You need to broadcast informations You need to advertise existence of Your Channel, in Advertising Channels is explained how to.

  4. Advertising Channels

    Pushetta handles advertising of Channels as well. While time flows the number of channels grows and it can be really difficult to users find what they search for. To solve this problem when a Channel is made it's automatically generated an advertise URL. This URL is smart: opened by a user on a smartphone it opens Pushetta App, if installed, and automatically subscribes to the channel, also it give information about subscribing channel in other ways (browser, desktop, ...). It also handles the case where user opening URL doesn't own Pushetta App, the device is detected and, if available, a link where download the App is displayed.

  5. Authentication

    Pushetta authentication is token based, a User registered on Pushetta get a token he/she have to use with API calls. You can get Your token from API itself of reading it in Dashboard. You can also send notifications from web using Channel detail page on this site.

  6. Pushing messages

    Pushing a message with API it's made with a single call. It can be made from command line of a Linux, Mac or any OS with installed curl as well

                    curl -H "Authorization: Token {API KEY}" -H "Content-Type: application/json" -X POST \
                     -d "{ \"body\" : \"Hello World\", \"message_type\" : \"text/plain\" }"\
                     http://api.pushetta.com/api/pushes/{Channel Name}/
                    
    And in case there is no curl on Your system You can use netcat (thanks to Valerio Morgante)
    
                   BODY="{ \"body\" : \"Hello World\", \"message_type\" : \"text/plain\" }"
                   
                   echo -ne "POST http://api.pushetta.com/api/pushes/{Channel Name}/ HTTP/1.0\r\nHost: api.pushetta.com\r\nContent-Type: application/json\r\nContent-Length: ${#BODY}\r\nAuthorization: Token {API KEY}\r\n\r\n${BODY}" | nc -i 3 api.pushetta.com 80 
                    

    Naturally it can be made from all populars languages and platforms, following are some samples:

    • Arduino LogoArduino Yún
      To use Pushetta with Arduino Yún need the custom library from here
      
                      #include <Bridge.h>
                      #include <Pushetta.h>
      
                      Pushetta pushetta("API KEY");
      
                      void setup() {
                        Bridge.begin();
                      }
      
                      void loop() {
                        pushetta.pushMessage("MyChannel", "Hello World"); // Send a message to "MyChannel" subscribers
                        delay(1000);  // waits for a second
                      }
      
                      

      Arduino LogoArduino with Ethernet Shield
      
                     #include <SPI.h>
                     #include <Ethernet.h>
                      
                     // Be sure this address is unique in your network
                     byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x19 };        
                     char APIKEY[] = "ffaabb444f1177772222f7243534badaanaa1100"; // Put here your API key
                     char CHANNEL[] = "my channel";                              // and here your channel name
       
                     char serverName[] = "api.pushetta.com";
                     boolean lastConnected = false; 
                     EthernetClient client;
                      
                     void setup() {
                       Serial.begin(9600);
      
                       if (Ethernet.begin(mac) == 0) {
                         while(true);                          // no point in carrying on, so do nothing forever
                       }
                     
                       delay(1000);                          // give the Ethernet shield a second to initialize
                     }
                      
                     void loop()
                     {
                           sendToPushetta(CHANNEL, "Hello world!");
                           delay(60000); 
                     }
                      
                      
                     //Function for sending the request to Pushetta
                     void sendToPushetta(char channel[], String text){
                       client.stop();
                      
                       if (client.connect(serverName, 80)) 
                       {                   
                         client.print("POST /api/pushes/");
                         client.print(channel);
                         client.println("/ HTTP/1.1");
                         client.print("Host: ");
                         client.println(serverName);
                         client.print("Authorization: Token ");
                         client.println(APIKEY);
                         client.println("Content-Type: application/json");
                         client.print("Content-Length: ");
                         client.println(text.length()+46);
                         client.println();
                         client.print("{ \"body\" : \"");
                         client.print(text);
                         client.println("\", \"message_type\" : \"text/plain\" }");
                         client.println(); 
                       } 
                     }
      
                      
    • Python LogoPython
      To use Pushetta with Python You need to install pushetta lib, using following command
                      pip install pushetta
                      
      When the lib is installed using it is as simple as the following sample
                      from pushetta import Pushetta
                        
                      API_KEY="00112233445566778899aabbccddeeff00112233"
                      CHANNEL_NAME="MyChannel"
                      p=Pushetta(API_KEY)
                      p.pushMessage(CHANNEL_NAME, "Hello World")
                      
    • Microsot .Net LogoMicrosoft .Net
                      var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://api.pushetta.com/api/pushes/MyChannel/");
                      httpWebRequest.ContentType = "application/json";
                      httpWebRequest.Headers.Add("Authorization", "Token {API KEY}");
      
                      httpWebRequest.Method = "POST";
      
                      using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                      {
      
                          string json = "{ \"body\" : \"Hello World from .Net\", \"message_type\" : \"text/plain\", \"expire\" : \"2015-01-01\"  }";
      
                          streamWriter.Write(json);
                          streamWriter.Flush();
                          streamWriter.Close();
      
                          var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                          using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                          {
                              var result = streamReader.ReadToEnd();
                          }
                      }
      
                      
    • PowerShellPowerShell (thanks to George Rolston)
                      # script requires Powershell 3.0 or later
      
                      # set your Pushetta API Key
                      $ApiKey = 'abcdefghijklmnopqrstuvwxyz123456789'
                      # the name of the specific channel your are posting message to
                      $ChannelName = 'YOURCHANNELNAME'
                      # create the uri to post your message
                      $Uri ='http://api.pushetta.com/api/pushes/' + $ChannelName + '/'
                      # specify the content type of the http request
                      $ContentType = "application/json"
                      # set the method of the http request
                      $Method = "POST"
                      # create a json message for the body of the http request
                      $JsonMsg = @{
                                      body = "Hello World from my $env:COMPUTERNAME";
                                      message_type ="text/plain";
                                      expire ="2015-01-01"
                                      } | ConvertTo-JSON
                      # create the header of the request to store authentication info
                      $Header = @{}
                      # add your key to the header
                      $Header.Add("AUTHORIZATION", " Token $ApiKey");
                      # call http request
                      Invoke-RestMethod -Method $Method -Uri $Uri -Header $Header -Body $JsonMsg -ContentType $ContentType
                      
    • PHP PHP (thanks to David Pounds)
      $channel = 'YOUR_CHANNEL_NAME';
      $apikey = 'YOUR_API_TOKEN';
      $expire = 'EXPIRY_DATE'; // In YYYY-MM-DD format
      
      $data = array(
      'body' => $message,
      'message_type' => 'text/plain',
      'expire' => $expire
      );
      
      $ch = curl_init("http://api.pushetta.com/api/pushes/$channel/");
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', "Authorization: Token $apikey"));
      
      $response = json_decode(curl_exec($ch));
                      
    • PHP Java (thanks to Valerio Morgante)
      //usage
      //
      //edit settings and compile: javac sendPush.java
      //
      //java sendPush your-message
      //
      
      import java.io.BufferedReader;
      import java.io.DataOutputStream;
      import java.io.InputStreamReader;
      import java.net.HttpURLConnection;
      import java.net.URL;
      
      public class sendPush {
      	
      	//settings
      	public static String channel = "your-channel";
      	public static String token = "Token your token";
      
      	public static void main(String[] args) throws Exception {
       
      		System.out.println("\nSending PUSH notification to " + channel + " channel");
      		sendPost(args[0]);
       
      	}
      
      	public static void sendPost(String message) throws Exception {
       
      		String url = "http://api.pushetta.com/api/pushes/" + channel + "/";
      		URL obj = new URL(url);
      		HttpURLConnection con = (HttpURLConnection) obj.openConnection();
       
      		//set reuqest header
      		con.setRequestMethod("POST");
      		con.setRequestProperty("Host", "api.pushetta.com");
      		con.setRequestProperty("User-Agent", "Mozilla/5.0");
      		con.setRequestProperty("Authorization",token);
      		con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
      		con.setRequestProperty("Content-Type","application/json");
      		
      		//API parameters
      		String urlParameters = "{ \"body\" : \"" + message + "\", \"message_type\" : \"text/plain\"  }";
       
      		// Send post request
      		con.setDoOutput(true);
      		DataOutputStream wr = new DataOutputStream(con.getOutputStream());
      		wr.writeBytes(urlParameters);
      		wr.flush();
      		wr.close();
       
      		int responseCode = con.getResponseCode();
      		String responseMessage = con.getResponseMessage();
      		System.out.println("\nSending 'POST' request to URL : " + url);
      		
      		//response information
      		System.out.println("Post parameters : " + urlParameters);
      		System.out.println("Response Code : " + responseCode);
      		System.out.println("Response Message : " + responseMessage);
      		
      		//read response
      		BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
      		StringBuffer response = new StringBuffer();
      		String inputLine;
      		while ((inputLine = in.readLine()) != null) {
      			response.append(inputLine);
      		}
      		in.close();
      		
      		//complete html page response if you wanna print it
      		String res = response.toString();
      		
      		//extract result
      		int aux = res.indexOf("success");
      		int auxx = res.indexOf(",", aux);
      		System.out.println(res.substring(aux, aux+7) + " : " + res.substring(aux+15, auxx));
      		
      	}
       
      }
                                      

Using pushetta

Something Legal