示例#1
0
        public Message ViewMessage(string id)
        {
            ParameterValidator.IsNotNullOrWhiteSpace(id, "id");

            var messageToView = new Messages(new Message(id));
            var result = restClient.Retrieve(messageToView);

            return result.Object as Message;
        }
        public void DeserializeRecipientsAsMsisdnsArray()
        {
            var recipients = new Recipients();
            recipients.AddRecipient(31612345678);

            var message = new Message("MsgBirdSms", "Welcome to MessageBird", recipients);
            var messages = new Messages(message);

            string serializedMessage = messages.Serialize();

            messages.Deserialize(serializedMessage);
        }
        public Message SendMessage(string originator, string body, long[] msisdns, MessageOptionalArguments optionalArguments = null)
        {
            ParameterValidator.IsNotNullOrWhiteSpace(originator, "originator");
            ParameterValidator.IsNotNullOrWhiteSpace(body, "body");
            ParameterValidator.ContainsAtLeast(msisdns, 1, "msisdns");

            var recipients = new Recipients(msisdns);
            var message = new Message(originator, body, recipients, optionalArguments);

            var messages = new Messages(message);
            var result = restClient.Create(messages);

            return result.Object as Message;
        }
        public void DeserializeAndSerialize()
        {
            const string CreateMessageResponseTemplate = @"{
              'id':'e7028180453e8a69d318686b17179500',
              'href':'https:\/\/rest.messagebird.com\/messages\/e7028180453e8a69d318686b17179500',
              'direction':'mt',
              'type':'sms',
              'originator':'$ORIGINATOR',
              'body':'Welcome to MessageBird',
              'reference':null,
              'validity':null,
              'gateway':56,
              'typeDetails':{

              },
              'datacoding':'plain',
              'mclass':1,
              'scheduledDatetime':null,
              'createdDatetime':'2014-08-11T11:18:53+00:00',
              'recipients':{
            'totalCount':1,
            'totalSentCount':1,
            'totalDeliveredCount':0,
            'totalDeliveryFailedCount':0,
            'items':[
              {
            'recipient':31612345678,
            'status':'sent',
            'statusDatetime':'2014-08-11T11:18:53+00:00'
              }
            ]
              }
            }";
            Recipients recipients = new Recipients();
            Message message = new Message("", "", recipients);
            Messages messages = new Messages(message);

            messages.Deserialize(CreateMessageResponseTemplate.Replace("$ORIGINATOR", "Messagebird"));
            JsonConvert.DeserializeObject<Message>(messages.Object.ToString());

            messages.Deserialize(CreateMessageResponseTemplate.Replace("$ORIGINATOR", "3112345678"));
            JsonConvert.DeserializeObject<Message>(messages.Object.ToString());

            messages.Deserialize(CreateMessageResponseTemplate.Replace("$ORIGINATOR", "+3112345678"));
            JsonConvert.DeserializeObject<Message>(messages.Object.ToString());
        }