Пример #1
0
        /// <summary>
        /// Pushes the address.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="ignoreEmptyFields">if set to <c>true</c> [ignore empty fields].</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">address request</exception>
        /// <exception cref="System.Exception">
        /// </exception>
        public PushResponse PushAddress(PushAddressRequest request, bool ignoreEmptyFields = false)
        {
            try
            {
                #region pre-processing

                if (request == null)
                {
                    throw new ArgumentNullException("address request");
                }

                if (string.IsNullOrWhiteSpace(request.DeviceIden) && string.IsNullOrWhiteSpace(request.Email))
                {
                    throw new Exception(PushbulletConstants.PushRequestErrorMessages.EmptyEmailProperty);
                }

                if (string.IsNullOrWhiteSpace(request.Type))
                {
                    throw new Exception(PushbulletConstants.PushRequestErrorMessages.EmptyTypeProperty);
                }

                if (!ignoreEmptyFields)
                {
                    if (string.IsNullOrWhiteSpace(request.Name))
                    {
                        throw new Exception(PushbulletConstants.PushAddressErrorMessages.EmptyNameProperty);
                    }

                    if (string.IsNullOrWhiteSpace(request.Address))
                    {
                        throw new Exception(PushbulletConstants.PushAddressErrorMessages.EmptyAddressProperty);
                    }
                }

                #endregion pre-processing


                #region processing

                return(PostPushRequest <PushAddressRequest>(request));

                #endregion processing
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public void PushbulletPushAddressTest()
        {
            try
            {
                var devices = Client.CurrentUsersDevices();
                Assert.IsNotNull(devices);

                var device = devices.Devices.Where(o => o.manufacturer == "Apple").FirstOrDefault();
                Assert.IsNotNull(device, "Could not find the device specified.");

                PushAddressRequest reqeust = new PushAddressRequest()
                {
                    device_iden = device.iden,
                    name        = "Apple Incorporated",
                    address     = "1 Infinite Loop, Cupertino, CA 95014"
                };

                var response = Client.PushAddress(reqeust);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }