Ejemplo n.º 1
0
        public void ConstructorTest()
        {
            ApiClient apiClient = new ApiClient();
            Assert.IsNotNull(apiClient);

            apiClient = new ApiClient("url", "user", "password");
            Assert.IsNotNull(apiClient);
        }
Ejemplo n.º 2
0
        public static void Execute()
        {
            Console.WriteLine("Alert Solutions API Client SimpleDemo\n");

            var attachments = new List<Attachment>();
            attachments.Add(Attachment.FromFile("Files\\Attachment.txt"));

            var proofs = new List<string>();
            proofs.Add("*****@*****.**");

            // create an email broadcast and give it the desired values
            var eb = new EmailBroadcast();
            eb.BillCode = "APIClient Demo";
            eb.ProjectCode = "APIClient Demo";
            eb.DisplayName = "AlertSolutions";
            eb.EmailSubject = "Alert Solutions API Client Demo";
            eb.EmailFrom = "*****@*****.**";
            eb.EmailReplyTo = "*****@*****.**";
            eb.TextBody = TextBody.FromFile("Files\\Email.txt");
            // be sure to modify the ContactList.csv file so the email goes to your intended destinations
            eb.List = ContactList.FromFile("Files\\ContactList.csv");
            eb.EmailHeader = "email";
            eb.Attachments = attachments;
            eb.Proofs = proofs;

            // change these values to your API login
            var user = "";
            var password = "";
            var url = "http://weblaunch.blifax.com/postapi";

            // create the client
            var client = new ApiClient(url, user, password);

            Console.WriteLine("\nPress any key to launch broadcast.");
            Console.ReadLine();

            // launch the broadcast
            var response = client.LaunchBroadcast(eb);

            // test the response status (in case it could not connect or something went wrong while submitting)
            Console.WriteLine("Response Status: " + response.RequestResult);
            if (response.RequestResult == RequestResultType.Error)
                Console.WriteLine("Error: " + response.RequestErrorMessage);
            else
                Console.WriteLine("OrderID: " + response.OrderID);

            Console.WriteLine("\nPress any key to retrieve report... (best to wait a few seconds)");
            Console.ReadLine();

            // get more information about the order by asking for a report
            var report = client.GetOrderReport(response, ReportReturnType.XML);

            Console.WriteLine("Report: " + report.ReportData);

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadLine();
        }
Ejemplo n.º 3
0
 public void CancelOrderTest()
 {
     var mockWebClientProxy = new Mock<IWebClientProxy>();
     mockWebClientProxy.Setup(x => x.UploadString(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
         .Returns(
             () => { return "some result"; });
     ApiClientResolver.Instance.Container.Register(mockWebClientProxy.Object);
     ApiClient apiClient = new ApiClient();
     apiClient.Initialize("blah", "user", "password");
     string retval = apiClient.CancelOrder(new OrderResponse{OrderID = 1, OrderType = OrderType.EmailBroadcast});
     Assert.AreEqual("some result", retval);
 }
Ejemplo n.º 4
0
 public void CallsFailWithoutInit01Test()
 {
     ApiClient apiClient = new ApiClient();
     try
     {
         apiClient.GetLists(ReportReturnType.CSV);
     }
     catch (ApplicationException ae)
     {
         Assert.AreEqual("APIClient.Initialized must be called prior to this method",ae.Message);
     }
 }
Ejemplo n.º 5
0
 public void CallsFailWithoutInit02Test()
 {
     ApiClient apiClient = new ApiClient();
     try
     {
         apiClient.GetOrderReport(1, OrderType.VoiceBroadcast, ReportReturnType.XML);
     }
     catch (ApplicationException ae)
     {
         Assert.AreEqual("APIClient.Initialized must be called prior to this method", ae.Message);
     }
 }
Ejemplo n.º 6
0
        public static void Execute()
        {
            // change these values to your API login
            var user = "******";
            var password = "******";
            var url = "http://weblaunch.blifax.com/postapi";

            var client = new ApiClient(url, user, password);
            var response = client.GetLists(ReportReturnType.XML);
            Console.WriteLine(response);

            response = client.GetLists(ReportReturnType.CSV);
            Console.WriteLine("\n\n"+ response);
        }
Ejemplo n.º 7
0
        public static void Execute()
        {
            Console.WriteLine("Alert Solutions API Client SimpleDemo\n");

            var attachments = new List<Attachment>();
            attachments.Add(Attachment.FromFile("Files\\Attachment.txt"));

            var proofs = new List<string>();
            proofs.Add("*****@*****.**");

            // create an email broadcast and give it the desired values
            var eb = new EmailBroadcast();
            eb.BillCode = "APIClient Demo";
            eb.ProjectCode = "APIClient Demo";
            eb.DisplayName = "AlertSolutions";
            eb.EmailSubject = "Alert Solutions API Client Demo";
            eb.EmailFrom = "*****@*****.**";
            eb.EmailReplyTo = "*****@*****.**";
            eb.TextBody = TextBody.FromFile("Files\\Email.txt");
            // be sure to modify the ContactList.csv file so the email goes to your intended destinations
            eb.List = ContactList.FromFile("Files\\ContactList.csv");
            eb.EmailHeader = "email";
            eb.Attachments = attachments;
            eb.Proofs = proofs;

            // change these values to your API login
            var user = "******";
            var password = "******";
            var url = "http://weblaunch.blifax.com/postapi";

            // create the client
            var client = new ApiClient(url, user, password);

            Console.WriteLine("\nPress any key to launch broadcast.");
            Console.ReadLine();

            // launch the broadcast
            var response = client.LaunchBroadcast(eb);
            Console.WriteLine("Response Status: " + response.RequestResult);
            if (response.RequestResult == RequestResultType.Error)
                Console.WriteLine("Error: " + response.RequestErrorMessage);
            else
                Console.WriteLine("OrderID: " + response.OrderID);

            Console.WriteLine("\nPress any key to cancel broadcast.");
            Console.ReadLine();

            var cancelResponse = client.CancelOrder(response);
            Console.WriteLine("\n\n"+ cancelResponse);
        }
Ejemplo n.º 8
0
        public static void Execute()
        {
            // change these values to your API login
            var user = "";
            var password = "";
            var url = "http://weblaunch.blifax.com/postapi";

            var client = new ApiClient(url, user, password);

            if (client.Authenticated())
            {
                Console.WriteLine("The credentials provided to the client have been authenticated!");
            }
            else
            {
                Console.WriteLine("The credentials provided to the client were not authenticated.");
            }
        }
Ejemplo n.º 9
0
        public static void Execute()
        {
            Console.WriteLine("Alert Solutions API Client TemplateDemo\n");

            Template template = Template.FromFile("Location\\Of\\Wav\\File.wav");

            // change these values to your API login
            // change your login details in the app config file
            var user = "";
            var password = "";
            var url = "http://weblaunch.blifax.com/postapi";

            var templateClient = new ApiClient(url, user, password);

            Console.WriteLine("\nPress any key to submit template.");
            Console.ReadLine();

            TemplateResponse response = templateClient.SendTemplates(template);

            var orderClient = new ApiClient(url, user, password);

            var vb = new VoiceBroadcast();
            vb.BillCode = "APIClient Demo";
            vb.ProjectCode = "APIClient Demo";
            vb.CallerID = "5555555555";
            vb.List = ContactList.FromFile("Files\\ContactList.csv");
            vb.VoiceHeader = "phone";
            vb.ThrottleType = VoiceBroadcast.VoiceThrottleType.MaximumCalls;
            vb.ThrottleNumber = 2;
            vb.Documents = new List<Document>()
            {
                //VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Live),
                VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Message),
            };

            OrderResponse broadcastResponse = orderClient.LaunchBroadcast(vb);

            Console.WriteLine(broadcastResponse.RequestErrorMessage);
        }
Ejemplo n.º 10
0
        public static void SendOrder(ApiClient client, IOrder order)
        {
            Console.WriteLine("Press any key to send " + order.TypeOfOrder + " order.");
            Console.WriteLine("[s] to skip...");
            var input = Console.ReadLine();
            if (input.ToUpper() == "S")
            {
                return;
            }

            Console.WriteLine("\nSending " + order.TypeOfOrder);
            var response = client.SendOrder(order);
            if (response.RequestResult == RequestResultType.Error)
            {
                Console.WriteLine(response.RequestErrorMessage);
            }
            else
            {
                Console.WriteLine("Return Status: " + response.RequestResult);
                Console.WriteLine("OrderID: " + response.OrderID);
                if (order is IMessage)
                {
                    Console.WriteLine("TransID: " + response.Unqid);
                }
            }

            Console.WriteLine("Press any key to fetch the report.");
            Console.ReadLine();

            var report = client.GetOrderReport(response, ReportReturnType.XML);

            if (report.RequestResult == RequestResultType.Error)
            {
                Console.WriteLine("Error: " + report.RequestErrorMessage);
            }
            else
            {
                Console.WriteLine("Report: " + report.ReportData);
            }
        }
Ejemplo n.º 11
0
        public static void Execute()
        {
            Console.WriteLine("Alert Solutions API Client Test\r\n\r\n");

            ApiClient client = new ApiClient("http://weblaunch.blifax.com/postapi", "*****@*****.**", "pentagon625");
            List<IOrder> orders = new List<IOrder>();

            orders.Add(CreateET());
            orders.Add(CreateEB());
            orders.Add(CreateMT());
            orders.Add(CreateML());
            orders.Add(CreateVT());
            orders.Add(CreateVL());
            orders.Add(CreateTL());
            orders.Add(CreateWL());

            foreach (var order in orders)
            {
                Console.WriteLine("About to generate a " + order.TypeOfOrder + " order.");
                Console.WriteLine("[Enter] to continue...");
                Console.WriteLine("[s] to skip...");
                var input = Console.ReadLine();
                if (input.ToUpper() != "S")
                {
                    Console.WriteLine(order.ToXml());
                    SendOrder(client, order);
                }
            }

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
Ejemplo n.º 12
0
        public static void Execute()
        {
            Console.WriteLine("Alert Solutions API Client FullDemo\n");

            // ===========================================
            //              BROADCASTS
            // ===========================================

            List<IBroadcast> broadcasts = new List<IBroadcast>();

            // EMAIL BROADCAST
            var eb = new EmailBroadcast();
            eb.BillCode = "APIClient Demo";
            eb.ProjectCode = "APIClient Demo";
            eb.DisplayName = "AlertSolutions";
            eb.EmailSubject = "Alert Solutions API Client Demo";
            eb.EmailFrom = "*****@*****.**";
            eb.EmailReplyTo = "*****@*****.**";
            eb.Attachments = new List<Attachment>() { Attachment.FromFile("Files\\Attachment.txt") };
            eb.List = ContactList.FromFile("Files\\ContactList.csv");
            eb.EmailHeader = "email";
            eb.Proofs = new List<string>() { "*****@*****.**" };
            // can use either Text or HTML
            eb.HtmlBody = HtmlBody.FromFile("Files\\Email.html");
            eb.TextBody = TextBody.FromFile("Files\\Email.txt");

            broadcasts.Add(eb);

            // SMS BROADCAST
            var sb = new SMSBroadcast();
            sb.BillCode = "APIClient Demo";
            sb.ProjectCode = "APIClient Demo";
            sb.ShortCode = "77811";
            sb.TextMessage = TextMessage.FromFile("Files\\TextMessage.txt");
            sb.List = ContactList.FromFile("Files\\ContactList.csv");
            sb.SMSHeader = "phone";
            sb.Proofs = new List<string>() { "5555555555" };

            broadcasts.Add(sb);

            // VOICE BROADCAST
            var vb = new VoiceBroadcast();
            vb.BillCode = "APIClient Demo";
            vb.ProjectCode = "APIClient Demo";
            vb.CallerID = "5555555555";
            vb.List = ContactList.FromFile("Files\\ContactList.csv");
            vb.VoiceHeader = "phone";
            vb.ThrottleType = VoiceBroadcast.VoiceThrottleType.MaximumCalls;
            vb.ThrottleNumber = 2;
            // can be told to load an xml file, or be given the xml as text
            //vt.CallScript = CallScript.FromString("");
            //vt.CallScript = CallScript.FromFile("");
            vb.Documents = new List<Document>()
            {
                //VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Live),
                VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Message),
            };

            broadcasts.Add(vb);

            // FAX BROADCAST
            var fb = new FaxBroadcast();
            fb.BillCode = "APIClient Demo";
            fb.ProjectCode = "APIClient Demo";
            fb.FaxFrom = "john doe";
            fb.List = ContactList.FromFile("Files\\FaxList.csv");
            fb.FaxHeader = "faxnumber";
            fb.Dedup = true;
            fb.DocumentStyle = "Letter";
            fb.Documents = new List<Document>()
            {
                Document.FromFile("Files\\FaxText.txt"),
            };

            broadcasts.Add(fb);

            // ===========================================
            //             MESSAGES
            // ===========================================

            List<IMessage> messages = new List<IMessage>();

            // EMAIL MESSAGE
            var em = new EmailMessage();
            em.EmailTo = "*****@*****.**";
            em.DisplayName = "AlertSolutions";
            em.EmailSubject = "Alert Solutions API Client Demo";
            em.EmailFrom = "*****@*****.**";
            em.EmailReplyTo = "*****@*****.**";
            em.Attachments = new List<Attachment>() { Attachment.FromFile("Files\\Attachment.txt") };
            // can use either Text or HTML
            em.TextBody = TextBody.FromFile("Files\\Email.txt");
            //em.EmailBody = HtmlBody.FromFile("Files\\Email.html");

            messages.Add(em);

            // SMS MESSAGE
            var sm = new SMSMessage();
            sm.Number = "5555555555";
            sm.ShortCode = "77811"; // shared Alert Solutions Shortcode
            sm.TextMessage = TextMessage.FromFile("Files\\TextMessage.txt");

            messages.Add(sm);

            // VOICE MESSAGE
            var vm = new VoiceMessage();
            //vt.CallScript = CallScript.FromString("");
            //vt.CallScript = CallScript.FromFile("");
            vm.Phone = "5555555555";
            vm.CallerID = "5555555555";
            vm.Documents = new List<Document>()
            {
                VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Live),
                VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Message),
            };

            messages.Add(vm);

            // FAX MESSAGE
            var fm = new FaxMessage();
            fm.FaxFrom = "john doe";
            fm.FaxNumber = "4014271405";
            fm.DocumentStyle = "Letter";
            fm.Documents = new List<Document>()
            {
                Document.FromFile("Files\\FaxText.txt"),
            };

            messages.Add(fm);

            // ===========================================
            //             LAUNCH
            // ===========================================

            // change these values to your API login
            var user = "******";
            var password = "******";
            var url = "http://weblaunch.blifax.com/postapi";

            // create the client
            var client = new ApiClient(url, user, password);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("There is a pause of about 10 seconds before getting a report.");
            Console.ForegroundColor = ConsoleColor.Gray;

            // launch the broadcasts
            foreach (var broadcast in broadcasts)
            {
                Console.Write("\n\nSending " + broadcast.TypeOfOrder + ": ");

                var response = client.LaunchBroadcast(broadcast);

                Console.Write("** " + response.RequestResult + " **");
                Console.Write(response.RequestResult != RequestResultType.Error ?
                    " OrderID: " + response.OrderID : "Error: " + response.RequestErrorMessage);

                // wait for broadcast before request report
                System.Threading.Thread.Sleep(12000);
                var report = client.GetOrderReport(response, ReportReturnType.XML);

                Console.Write("\nReport:\n" + report.ReportData);
            }

            // launch the messages
            foreach (var message in messages)
            {
                Console.Write("\n\nSending " + message.TypeOfOrder + ": ");

                var response = client.LaunchMessage(message);

                Console.Write("** " + response.RequestResult + " **");
                Console.Write(response.RequestResult != RequestResultType.Error ?
                    " OrderID: " + response.OrderID  + " TransID: " + response.Unqid : "Error: " + response.RequestErrorMessage);

                // wait for message before request report
                System.Threading.Thread.Sleep(10000);
                var report = client.GetOrderReport(response, ReportReturnType.XML);

                Console.Write("\nReport:\n" + report.ReportData);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
Ejemplo n.º 13
0
 public void GetListsTest()
 {
     var mockWebClientProxy = new Mock<IWebClientProxy>();
     mockWebClientProxy.Setup(x => x.DownloadString(It.IsAny<string>(), It.IsAny<string>())).Returns(() =>
     {
         return "downloaded string";
     });
     mockWebClientProxy.Setup(x => x.UploadString(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
         .Returns(
             () => { return "some result"; });
     ApiClientResolver.Instance.Container.Register(mockWebClientProxy.Object);
     ApiClient apiClient = new ApiClient();
     apiClient.Initialize("blah", "user", "password");
     string lists = apiClient.GetLists(ReportReturnType.XML);
     Assert.IsNotNull("downloaded string");
 }
Ejemplo n.º 14
0
        public void SendTemplateTest()
        {
            var mockWebClientProxy = new Mock<IWebClientProxy>();
            mockWebClientProxy.Setup(x => x.UploadString(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Returns(
                    () => { return "<Templates><TemplateID>123</TemplateID></Templates>"; });
            ApiClientResolver.Instance.Container.Register(mockWebClientProxy.Object);

            var mockMessage = new Mock<ITemplate>();
            mockMessage.Setup(x => x.ToXml()).Returns(XElement.Parse("<Templates><Template><FileName>template.html</FileName><FileBinary>fakefilebinary</FileBinary></Template></Templates>"));

            ApiClient apiClient = new ApiClient("url", "user", "password");
            TemplateResponse response = apiClient.SendTemplates(mockMessage.Object);
            Assert.AreEqual(RequestResultType.Success, response.Status);
            Assert.AreEqual(123, response.TemplateId);
        }
Ejemplo n.º 15
0
        public void LaunchMessageTest()
        {
            var mockWebClientProxy = new Mock<IWebClientProxy>();
            mockWebClientProxy.Setup(x => x.UploadString(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Returns(
                    () => { return "<PostAPIResponse><SaveTransactionalOrderResult><OrderID>12345</OrderID><transactionID>transactionId</transactionID></SaveTransactionalOrderResult></PostAPIResponse>"; });
            ApiClientResolver.Instance.Container.Register(mockWebClientProxy.Object);

            var mockMessage = new Mock<IMessage>();
            mockMessage.Setup(x => x.ToXml()).Returns("<Orders><Order Type='ET'></Order></Orders>");

            ApiClient apiClient = new ApiClient("url", "user", "password");
            OrderResponse response = apiClient.LaunchMessage(mockMessage.Object);
            Assert.AreEqual(RequestResultType.Success, response.RequestResult);
            Assert.AreEqual(OrderType.EmailMessage, response.OrderType);
            Assert.AreEqual(12345, response.OrderID);
            Assert.AreEqual("transactionId", response.Unqid);
        }
Ejemplo n.º 16
0
        public void GetTransactionReport()
        {
            var mockWebClientProxy = new Mock<IWebClientProxy>();
            mockWebClientProxy.Setup(x => x.UploadString(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Returns(
                    () => { return "<PostAPIResponse><SaveTransactionalOrderResult><status>status</status></SaveTransactionalOrderResult></PostAPIResponse>"; });
            ApiClientResolver.Instance.Container.Register(mockWebClientProxy.Object);

            ApiClient apiClient = new ApiClient("url", "user", "password");
            TransactionReport response = apiClient.GetTransactionReport("transactionid", OrderType.EmailMessage, ReportReturnType.XML);
            Assert.AreEqual(RequestResultType.Success, response.RequestResult);
            Assert.AreEqual(OrderType.EmailMessage, response.OrderType);
            Assert.AreEqual("transactionid", response.Unqid);
            Assert.AreEqual("status", response.OrderStatus);
            Assert.AreEqual("<PostAPIResponse><SaveTransactionalOrderResult><status>status</status></SaveTransactionalOrderResult></PostAPIResponse>", response.ReportData);
        }