當前位置: 首頁>>代碼示例>>C#>>正文


C# API.Send方法代碼示例

本文整理匯總了C#中API.Send方法的典型用法代碼示例。如果您正苦於以下問題:C# API.Send方法的具體用法?C# API.Send怎麽用?C# API.Send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在API的用法示例。


在下文中一共展示了API.Send方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ReceiveSms

        private async Task<dynamic> ReceiveSms()
        {
            var smsMessage = this.Bind<SmsMessage>();

            var result = _smsRepository.FindByMessageId(smsMessage.Msg_ID);
            if (result != null) return HttpStatusCode.OK;

            _smsRepository.Add(smsMessage);

            var response = await HandleSms(smsMessage);

            var clockworkApi = new API("508ed11cab000a796881e015fc5e022daf1bb6d3");
            if (!string.IsNullOrWhiteSpace(response))
            {
                clockworkApi.Send(new SMS { To = smsMessage.From, Message = response });
            }
            else
            {
                clockworkApi.Send(new SMS { To = smsMessage.From, Message = "Thanks for playing. You will stop receiving messages." });
            }
                        
            return HttpStatusCode.OK;
        }
開發者ID:ritasker,項目名稱:ZorkSms,代碼行數:23,代碼來源:ApiModule.cs

示例2: SendMessage

        public ActionResult SendMessage(MessageToSend msg)
        {
            try
              {
              if (msg.to != null && msg.body != null)
              {
            Clockwork.API api = new API(apiKey);
            SMSResult result = api.Send(new Clockwork.SMS { To = msg.to, Message = "Hello World" });

            if (result.Success){
            ViewBag.result = result;
            return View();
            //Console.WriteLine("SMS Sent to {0}, Clockwork ID: {1}", result.SMS.To, result.ID);
            }
            else
            Console.WriteLine("SMS to {0} failed, Clockwork Error: {1} {2}", result.SMS.To, result.ErrorCode, result.ErrorMessage);
              }

              }
              catch (APIException ex)
              {
              // You'll get an API exception for errors
              // such as wrong username or password
              Console.WriteLine("API Exception: " + ex.Message);
              }
              catch (WebException ex)
              {
              // Web exceptions mean you couldn't reach the Clockwork server
              Console.WriteLine("Web Exception: " + ex.Message);
              }
              catch (ArgumentException ex)
              {
              // Argument exceptions are thrown for missing parameters,
              // such as forgetting to set the username
              Console.WriteLine("Argument Exception: " + ex.Message);
              }
              catch (Exception ex)
              {
              // Something else went wrong, the error message should help
              Console.WriteLine("Unknown Exception: " + ex.Message);
              }
              return View("/");
        }
開發者ID:mariobot,項目名稱:twilio,代碼行數:43,代碼來源:ClockWorkSMSController.cs

示例3: sendMessage_Click

        private void sendMessage_Click(object sender, EventArgs e)
        {
            try
            {
                API api = new API(key.Text);

                SMS sms = new SMS
                {
                    To = to.Text,
                    Message = message.Text
                };

                SMSResult result = api.Send(sms);

                if (result.Success)
                    MessageBox.Show("Sent\nID: " + result.ID);
                else
                    MessageBox.Show("Error: " + result.ErrorMessage);
            }
            catch (APIException ex)
            {
                // You'll get an API exception for errors
                // such as wrong key
                MessageBox.Show("API Exception: " + ex.Message);
            }
            catch (WebException ex)
            {
                // Web exceptions mean you couldn't reach the mediaburst server
                MessageBox.Show("Web Exception: " + ex.Message);
            }
            catch (ArgumentException ex)
            {
                // Argument exceptions are thrown for missing parameters,
                // such as forgetting to set the username
                MessageBox.Show("Argument Exception: " + ex.Message);
            }
            catch (Exception ex)
            {
                // Something else went wrong, the error message should help
                MessageBox.Show("Unknown Exception: " + ex.Message);
            }
        }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:42,代碼來源:Form1.cs

示例4: Send

        public void Send(string number, string body)
        {
            try
            {
                Clockwork.API api = new API("e26d24050e1147c7f8a57bdeeb574581dd5ca5f1");
                SMSResult result = api.Send(
                    new SMS
                    {
                        To = number,
                        Message = body
                    });

                if (!result.Success)
                {
                    throw new Exception(result.ErrorMessage);
                }
            }
            catch (APIException ex)
            {
                // You’ll get an API exception for errors
                // such as wrong username or password
                Console.WriteLine("API Exception: " + ex.Message);
            }
            catch (WebException ex)
            {
                // Web exceptions mean you couldn’t reach the Clockwork server
                Console.WriteLine("Web Exception: " + ex.Message);
            }
            catch (ArgumentException ex)
            {
                // Argument exceptions are thrown for missing parameters,
                // such as forgetting to set the username
                Console.WriteLine("Argument Exception: " + ex.Message);
            }
            catch (Exception ex)
            {
                // Something else went wrong, the error message should help
                Console.WriteLine("Unknown Exception: " + ex.Message);
            }
        }
開發者ID:mistakenot,項目名稱:mcrhack,代碼行數:40,代碼來源:SmsService.cs

示例5: SendSmsToVolunteer

        public static void SendSmsToVolunteer(int volunteerId)
        {
            var volunteer = VolunteerRepository.Get(volunteerId);

            if (volunteer != null)
            {
                var mobile = volunteer.Mobile.Replace(" ", "");
                var api = new API(ClockworkSmsKey);
                var result = api.Send(
                    new SMS
                    {
                        To = mobile,
                        Message = "Go help Granny Smith!"
                    });
                if (!result.Success)
                {
                    Debug.WriteLine($"Failed to send SMS to {mobile}");
                    Debug.WriteLine($"Clockwork SMS ErrorCode: {result.ErrorCode}");
                    Debug.WriteLine($"Clockwork SMS ErrorMessage: {result.ErrorMessage}");
                }
            }
        }
開發者ID:dutchmvp,項目名稱:GPS,代碼行數:22,代碼來源:SmsProvider.cs

示例6: SendOneSMS_UseProxy

        public void SendOneSMS_UseProxy()
        {
            string proxyHost = "";
            int proxyPort = 0;

            proxyHost = System.Configuration.ConfigurationManager.AppSettings["ProxyHost"];
            if (String.IsNullOrWhiteSpace(proxyHost))
                Assert.Inconclusive("Proxy host not configured - Skipping test");

            string proxyPortTemp = System.Configuration.ConfigurationManager.AppSettings["ProxyPort"];
            if (String.IsNullOrWhiteSpace(proxyPortTemp))
                Assert.Inconclusive("Proxy port not configured - Skipping test");

            if(!int.TryParse(proxyPortTemp, out proxyPort))
                Assert.Inconclusive("Proxy port could not be parsed - Skipping test");

            Clockwork.API api = new API(key);

            api.Proxy = new System.Net.WebProxy(proxyHost, proxyPort);

            SMSResult result = api.Send(new SMS { To = "44123457890", Message = "Hello World" });

            Assert.IsTrue(result.Success);
        }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:24,代碼來源:APITest.cs

示例7: SendOneSMS_Single

 public void SendOneSMS_Single()
 {
     Clockwork.API api = new API(key);
     SMSResult result = api.Send(new SMS { To = "441234567890", Message = "Hello World" });
     Assert.IsTrue(result.Success);
 }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:6,代碼來源:APITest.cs

示例8: SendOneSMS_Response_Matches_Send

        public void SendOneSMS_Response_Matches_Send()
        {
            Clockwork.API api = new API(key);

            List<SMS> smsList = new List<SMS>();
            SMS sms = new SMS { To = "441234567891", Message = "Hello World" };
            smsList.Add(sms);

            List<SMSResult> result = api.Send(smsList);
            Assert.AreSame(sms, result[0].SMS);
        }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:11,代碼來源:APITest.cs

示例9: SendOneSMS_List

        public void SendOneSMS_List()
        {
            Clockwork.API api = new API(key);

            List<SMS> sms = new List<SMS>();
            sms.Add(new SMS { To = "441234567891", Message = "Hello World" });

            List<SMSResult> result = api.Send(sms);
            Assert.IsTrue(result[0].Success);
        }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:10,代碼來源:APITest.cs

示例10: SendOneSMS_InvalidNumber

        public void SendOneSMS_InvalidNumber()
        {
            Clockwork.API api = new API(key);
            SMSResult result = api.Send(new SMS { To = "not_a_number", Message = "Hello World" });

            Assert.IsNotNull(result);
            Assert.IsFalse(result.Success);
            Assert.AreEqual(10, result.ErrorCode);
        }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:9,代碼來源:APITest.cs

示例11: SendNullSMS_Single

 public void SendNullSMS_Single()
 {
     Clockwork.API api = new API(key);
     SMS sms = null;
     SMSResult result = api.Send(sms);
 }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:6,代碼來源:APITest.cs

示例12: SendNullSMS_List

 public void SendNullSMS_List()
 {
     Clockwork.API api = new API(key);
     List<SMS> smsList = null;
     List<SMSResult> result = api.Send(smsList);
 }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:6,代碼來源:APITest.cs

示例13: SendMultiSMS_Success

        public void SendMultiSMS_Success()
        {
            Clockwork.API api = new API(key);

            List<SMS> smsList = new List<SMS>();
            smsList.Add(new SMS { To = "441234567891", Message = "Hello World" });
            smsList.Add(new SMS { To = "441234567892", Message = "Hello World" });

            List<SMSResult> result = api.Send(smsList);
            Assert.IsTrue(result[0].Success && result[1].Success);
        }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:11,代碼來源:APITest.cs

示例14: SendMultiSMS_BothNoMessage

        public void SendMultiSMS_BothNoMessage()
        {
            Clockwork.API api = new API(key);

            List<SMS> smsList = new List<SMS>();
            smsList.Add(new SMS { To = "441234567891" });
            smsList.Add(new SMS { To = "441234567892" });

            List<SMSResult> result = api.Send(smsList);
            Assert.IsFalse(result[0].Success || result[1].Success);
        }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:11,代碼來源:APITest.cs

示例15: SendEmptySMS_List

 public void SendEmptySMS_List()
 {
     List<SMS> sms = new List<SMS>();
     Clockwork.API api = new API(key);
     List<SMSResult> result = api.Send(sms);
 }
開發者ID:techip,項目名稱:clockwork-dotnet,代碼行數:6,代碼來源:APITest.cs


注:本文中的API.Send方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。