Message to group model.
Inheritance: BaseSendMessageRequest
Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///    Sends message to group.
        /// </summary>
        /// <param name="messageToGroup">Message model for group</param>
        public void SendMessage(MessageToGroupRequest messageToGroup)
        {
            var validityPeriod = 86400;
            if (messageToGroup.ValidityPeriod != null && messageToGroup.ValidityPeriod > 0 && messageToGroup.ValidityPeriod <= 86400)
                validityPeriod = (int)messageToGroup.ValidityPeriod;

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

            var result = _httpClient.GetResponse(requestUrl);

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