Message to list model.
Inheritance: BaseSendMessageRequest
コード例 #1
0
ファイル: Program.cs プロジェクト: fastsmsuk/dotNet-sdk
        private static void CompileCommand(string[] args)
        {
            var client = new FastSmsClient("6Rx6-stiU-a8sY-vt9i");
            var commandArguments = args;
            if (!commandArguments.Any())
                return;
            var command = commandArguments[0];

            switch (command)
            {
                case "CheckCredits":
                    Console.WriteLine(client.CheckCredits());
                    break;
                case "CheckMessageStatus":
                    if (commandArguments.Length != 2)
                        Console.WriteLine(ArgumentError);
                    else
                        Console.WriteLine(client.CheckMessageStatus(commandArguments[1]));
                    break;
                case "UpdateCredits":
                    int i;
                    if (commandArguments.Length != 3 || !int.TryParse(commandArguments[2], out i))
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.UpdateCredits(commandArguments[1], i);
                        Console.WriteLine(Success);
                    }
                    break;
                case "DeleteAllContacts":
                    if (commandArguments.Length != 1)
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.DeleteAllContacts();
                        Console.WriteLine(Success);
                    }
                    break;
                case "DeleteAllGroups":
                    if (commandArguments.Length != 1)
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.DeleteAllGroups();
                        Console.WriteLine(Success);
                    }
                    break;
                case "EmptyGroup":
                    if (commandArguments.Length != 2)
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.EmptyGroup(commandArguments[1]);
                        Console.WriteLine(Success);
                    }
                    break;
                case "DeleteGroup":
                    if (commandArguments.Length != 2)
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.DeleteGroup(commandArguments[1]);
                        Console.WriteLine(Success);
                    }
                    break;
                case "CreateUser":
                    if (commandArguments.Length != 3)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var user = new CreateUserRequest(commandArguments[1], commandArguments[2])
                        {
                            LastName = "User Last name",
                            AccessLevel = "Normal",
                            ChildPassword = "******",
                            Email = @"*****@*****.**",
                            Credits = 100
                        };
                        client.CreateUser(user);
                        Console.WriteLine(Success);
                    }
                    break;
                case "SendMessageToUser":
                    if (commandArguments.Length != 3)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var message = new SendMessageToUserRequest()
                        {
                            Body = commandArguments[1],
                            DestinationAddress = commandArguments[2]
                        };
                        client.SendMessage(message);
                        Console.WriteLine(Success);
                    }
                    break;
                case "SendMessageToGroup":
                    if (commandArguments.Length != 3)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var message = new MessageToGroupRequest()
                        {
                            Body = commandArguments[1],
                            GroupName = commandArguments[2]
                        };
                        client.SendMessage(message);
                        Console.WriteLine(Success);
                    }
                    break;
                case "SendMessageToList":
                    if (commandArguments.Length != 3)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var message = new SendMessageToListRequest()
                        {
                            Body = commandArguments[1],
                            ListName = commandArguments[2]
                        };
                        client.SendMessage(message);
                        Console.WriteLine(Success);
                    }
                    break;
                case "GetReports":
                    if (commandArguments.Length != 4)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var reportType = ReportType.Messages;
                        switch (commandArguments[1])
                        {
                            case "InboundMessages":
                                reportType = ReportType.InboundMessages;
                                break;
                            case "Messages":
                                reportType = ReportType.Messages;
                                break;
                            case "Outbox":
                                reportType = ReportType.Outbox;
                                break;
                            case "Usage":
                                reportType = ReportType.Usage;
                                break;
                        }
                        var reports = client.GetReports(reportType, commandArguments[2], commandArguments[3]);
                        foreach (var report in reports)
                        {
                            Console.WriteLine(ReportToString(report));
                        }
                    }
                    break;
                case "Help":
                    Help();
                    break;
                default:
                    break;
            }
        }
コード例 #2
0
ファイル: FastSmsClient.cs プロジェクト: fastsmsuk/dotNet-sdk
        /// <summary>
        ///    Sends message to list.
        /// </summary>
        /// <param name="messageToList">Message model for list</param>
        public void SendMessage(SendMessageToListRequest messageToList)
        {
            var validityPeriod = 86400;
            if (messageToList.ValidityPeriod != null && messageToList.ValidityPeriod > 0 && messageToList.ValidityPeriod <= 86400)
                validityPeriod = (int)messageToList.ValidityPeriod;

            var requestUrl = string.Format("{0}{1}&Action=Send&DestinationAddress=List&ListName={2}&SourceAddress={3}&Body={4}&ScheduleDate={5}&SourceTON={6}&ValidityPeriod={7}" +
                                            "&GetAllMessageIDs={8}&GetBGSendID={9}",
                ApiUrl, _token, messageToList.ListName, messageToList.SourceAddress, messageToList.Body,
                messageToList.ScheduleDate, messageToList.SourceTon, validityPeriod, messageToList.GetAllMessageIDs,
                messageToList.GetBgSendId);

            var result = _httpClient.GetResponse(requestUrl);

            if (result.AsIntSafe() < 1)
            {
                throw new FastSmsException(result);
            }
        }