From fedb687397dd42b034f89c1fd1e4ebeff7cea5cc Mon Sep 17 00:00:00 2001 From: John Reese Date: Tue, 25 Oct 2011 15:40:45 -0400 Subject: [PATCH] Experimental support for subscribe command Issue #228 --- push.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/push.cpp b/push.cpp index b6c3ffd..9712b85 100644 --- a/push.cpp +++ b/push.cpp @@ -1175,6 +1175,46 @@ class CPushMod : public CModule PutModule(table); } + // SUBSCRIBE command + else if (action == "subscribe") + { + // Set up the connection profile + CString service = options["service"]; + bool use_post = true; + int use_port = 443; + bool use_ssl = true; + CString service_host; + CString service_url; + CString service_auth; + MCString params; + + if (service == "boxcar") + { + if (options["username"] == "") + { + PutModule("Error: username not set"); + return; + } + + CString boxcar_api_key = "puSd2qp2gCDZO7nWkvb9"; + + service_host = "boxcar.io"; + service_url = "/devices/providers/" + boxcar_api_key + "/notifications/subscribe"; + + params["email"] = options["username"]; + } + else + { + PutModule("Error: service does not support subscribe command"); + return; + } + + // Create the socket connection, write to it, and add it to the queue + CPushSocket *sock = new CPushSocket(this); + sock->Connect(service_host, use_port, use_ssl); + sock->Request(use_post, service_host, service_url, params, service_auth); + AddSocket(sock); + } // SEND command else if (action == "send") {