示例#1
0
        /// <summary>
        /// Get a YouMailContact from an ID
        /// </summary>
        /// <param name="id">The id of the contact</param>
        /// <returns>The YouMailContact</returns>
        public async Task <YouMailContact> GetContactAsync(long id, int imageSize = 100)
        {
            YouMailContact contact = null;

            try
            {
                AddPendingOp();
                YouMailContactQuery query = new YouMailContactQuery(QueryType.GetContact)
                {
                    ImageSize = imageSize,
                };
                query.AddItemId(id);

                var results = await ExecuteContactQueryAsync(query);

                if (results != null && results.Data != null && results.Data.Length > 0)
                {
                    contact = results.Data[0];
                }
            }
            finally
            {
                RemovePendingOp();
            }
            return(contact);
        }
示例#2
0
 /// <summary>
 /// Update and existing contact
 /// </summary>
 /// <param name="contact">The new contact to update</param>
 /// <param name="id">The id of the contact to update</param>
 public async Task UpdateContactAsync(YouMailContact contact, long id)
 {
     try
     {
         AddPendingOp();
         if (await LoginWaitAsync())
         {
             string ser = SerializeObject(contact, YMST.c_contact);
             using (await YouMailApiAsync(string.Format(YMST.c_updateContact, id), SerializeObjectToHttpContent(contact, YMST.c_contact), HttpMethod.Put))
             {
             }
         }
     }
     finally
     {
         RemovePendingOp();
     }
 }
示例#3
0
        /// <summary>
        /// Get or create a contact if one doesn't exist.
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        public async Task <YouMailContact> GetOrCreateContactAsync(string number, YouMailContact contact)
        {
            try
            {
                AddPendingOp();
                if (await LoginWaitAsync())
                {
                    using (var response = await YouMailApiAsync(string.Format(YMST.c_getOrCreateContact, number), SerializeObjectToHttpContent(contact), HttpMethod.Post))
                    {
                        return(DeserializeObject <YouMailContact>(response.GetResponseStream()));
                    }
                }
            }
            finally
            {
                RemovePendingOp();
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// Create a new contact
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        public async Task <long> CreateContactAsync(YouMailContact contact)
        {
            long id = 0;

            try
            {
                AddPendingOp();
                if (await LoginWaitAsync())
                {
                    using (var response = await YouMailApiAsync(YMST.c_createContact, SerializeObjectToHttpContent(contact, YMST.c_contact), HttpMethod.Post))
                    {
                        var ymResponse = DeserializeObject <YouMailResponse>(response.GetResponseStream());
                        id = long.Parse(ymResponse.Properties[YMST.c_contactId]);
                    }
                }
            }
            finally
            {
                RemovePendingOp();
            }
            return(id);
        }