Exemplo n.º 1
0
        /// <summary>
        /// Create a new device
        /// </summary>
        /// <param name="userAccessToken">User Access Token</param>
        /// <param name="deviceEntityToCreate">DeviceService Entity</param>
        /// <returns></returns>
        public string Create(string userAccessToken, DeviceEntityCreate deviceEntityToCreate)
        {
            ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;

            var url     = _baseUrl + "users/devices?key=" + userAccessToken;
            var client  = new RestClient(url);
            var request = new RestRequest(Method.POST);

            if (string.IsNullOrEmpty(deviceEntityToCreate.NativeId))
            {
                throw new ApplicationException("Device NativeId is Required");
            }

            request.AddHeader("content-type", "application/json");
            request.AddParameter("application/json",
                                 JsonConvert.SerializeObject(deviceEntityToCreate),
                                 ParameterType.RequestBody);

            // execute the request
            IRestResponse response       = client.Execute(request);
            var           responseObject = (dynamic)JsonConvert.DeserializeObject(response.Content);

            if (responseObject != null && responseObject.result != null)
            {
                return(responseObject.result.device_id);
            }

            return(string.Empty);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var saraImageString    = ReadImage("sara-arjun.jpg");
            var jsonObjectDumpper  = new JsonObjectDumper();
            var deviceService      = new DeviceService();
            var accountService     = new AccountService();
            var accountAccessToken = accountService.GetAccountAccessToken();

            var userAccessTokenService = new UserAccessTokenService();
            var userAccessToken        = userAccessTokenService.GetUserAccessToken("user2");

            var deviceId    = "abc2fa752c3c4edf97de8b0a12f622f0";
            var textMessage = new MessageToSendRoot
            {
                MessageToSend = new MessageToSend
                {
                    Message = new Message
                    {
                        MimeType = "text/plain",
                        Text     = "let's meet tonight"
                    },
                    UUID        = deviceId,
                    ContentType = "text",
                    Destination = "*****@*****.**"
                }
            };

            // Example to send message to device
            SendMessageToDevice(userAccessToken, deviceId, textMessage);

            // Send Image as Message
            var imageMessage = new MessageToSendRoot
            {
                MessageToSend = new MessageToSend
                {
                    Message = new Message
                    {
                        MimeType = "image/jpeg",
                        Text     = saraImageString
                    },
                    UUID        = deviceId,
                    ContentType = "image",
                    Destination = "*****@*****.**"
                }
            };

            SendImageToDevice(userAccessToken, deviceId, imageMessage);

            // Fetch Device Addressbook Contacts
            var deviceAddressBookContacts = deviceService.GetDeviceAddressBookContacts(userAccessToken,
                                                                                       deviceId);

            // Delete Handled Messages
            //deviceService.DeleteHandledMessages(userAccessToken,
            //    deviceId, new List<string> {
            //        "A149EBB9A69D4E66B62D26FBDEF440C5"});

            // Create a new user device
            var deviceEntity = new DeviceEntityCreate
            {
                NativeId = "353897050095214",
                Family   = "Windows",
                Name     = "Windows Phone 8",
                ClientSoftwareVersion  = "0102001",
                OperatingSystemVersion = "8.0.10328.78"
            };

            // Fetch and Create new device
            var devices = deviceService.GetDevices(userAccessToken);

            Console.WriteLine(jsonObjectDumpper.WriteToString(devices));
            var newDeviceId = deviceService.Create(userAccessToken, deviceEntity);

            var domains   = accountService.GetDomains(accountAccessToken);
            var newDomain = accountService.CreateDomain(accountAccessToken, "TestDomain", "Test");

            var domainService     = new DomainService();
            var domainAccessToken = domainService.GetDomainAccessToken();

            // Fetch and create user contacts
            var userAddressBookService = new UserAddressBookService(userAccessToken);
            var contacts = userAddressBookService.GetContacts();

            Console.WriteLine(jsonObjectDumpper.WriteToString(contacts.ContactResultEntity.Contacts));

            var contactId = userAddressBookService.AddContact(new ContactEntity
            {
                FirstName    = "Test",
                LastName     = "Test 123",
                Email        = "*****@*****.**",
                Nickname     = "Testing",
                Name         = "Test",
                MobileNumber = "12244199894"
            });

            Console.WriteLine("Contact Id: {0}", contactId);

            // Group related
            string groupId      = "6f6db62a2d0c4900b7c8b70661442194";
            var    groupService = new GroupService(userAccessToken);
            var    groupInfo    = groupService.FindGroupById(groupId);
            var    allGroups    = groupService.GetAllGroups();

            Console.WriteLine(jsonObjectDumpper.WriteToString(allGroups));

            // Add Group Members
            var groupMemeberCreationStatus =
                groupService.AddGroupMembers(userAccessToken, groupId,
                                             new List <string>
            {
                "*****@*****.**",
                "*****@*****.**",
            });

            var createdGroupId = groupService.CreateGroup(new GroupEntity
            {
                GroupName  = "Test Group",
                GroupImage = string.Empty
            });

            Console.WriteLine("Newly Created Group Id: {0}", createdGroupId);

            // Send GroupMessage
            var groupMessage = new GroupMessageToSendRoot
            {
                MessageToSend = new GroupMessageToSend
                {
                    GroupId = "6f6db62a2d0c4900b7c8b70661442194",
                    Message = new Message
                    {
                        MimeType = "text/plain",
                        Text     = "Sending test message to group"
                    },
                    UUID        = deviceId,
                    ContentType = "text",
                    Destination = "*****@*****.**"
                }
            };

            groupService.SendGroupMessage(userAccessToken,
                                          JsonConvert.SerializeObject(groupMessage));

            Console.ReadLine();
        }